I have to parse the following XML into an internal table, I get the short dump, after running the program. Please see the program and simple transformation in the following. An exception occurred in simple transformation that is explained in detail below.
The exception, which is assigned to class 'CX_ST_MATCH_ELEMENT', was not caught and therefore caused a runtime error.
The reason for the exception is:
XML matching error Expected was element-end: "Total" [ ] Read was element-start: "Weighing"
My XML:
CONCATENATE '<Automatic>'
' <Weighing Tolerance="5" Deviation="1.60" >'
' <Substance ExtId="3" Speed="1" />'
' <Substance ExtId="22" Speed="5" />'
' </Weighing>'
' <Weighing Tolerance="5" Deviation="-16" >'
' <Substance ExtId="22" Speed="5" />'
' </Weighing>'
' <Weighing Tolerance="5" >'
' <Substance ExtId="22" Speed="5" />'
' </Weighing>'
' <Total State="0" Result="Ok" />'
' </Automatic>'
INTO DATA(xml).
Program:
* Substance *
TYPES: BEGIN OF ty_data,
ExtId TYPE CHAR20,
Speed TYPE CHAR20,
END OF ty_data.
DATA: wa_ty_data TYPE ty_data,
lt_data TYPE TABLE OF ty_data.
* Total *
TYPES: BEGIN OF ty_data3,
State TYPE CHAR20,
Result TYPE CHAR20,
END OF ty_data3.
DATA: wa_ty_data3 TYPE ty_data3,
lt_data3 TYPE TABLE OF ty_data3.
* Weighing *
TYPES: BEGIN OF ty_data2,
Tolerance TYPE CHAR20,
Deviation TYPE CHAR20,
t_data TYPE TABLE OF ty_data WITH DEFAULT KEY,
t_data3 TYPE TABLE OF ty_data3 WITH DEFAULT KEY,
END OF ty_data2.
DATA: wa_ty_data2 TYPE ty_data2,
lt_data2 TYPE TABLE OF ty_data2.
CALL TRANSFORMATION zpp_tt_exampletest_st
SOURCE XML xml
RESULT xml_tab = lt_data2.
ZPP_TT_EXAMPLETEST_ST transformation:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="XML_TAB"/>
<tt:template>
<Automatic>
<tt:loop name="b" ref=".XML_TAB">
<Weighing>
<tt:cond check="not-initial($b.TOLERANCE)">
<tt:attribute name="Tolerance" value-ref="$b.TOLERANCE"/>
</tt:cond>
<tt:cond check="not-initial($b.DEVIATION)">
<tt:attribute name="Deviation" value-ref="$b.DEVIATION"/>
</tt:cond>
<tt:loop name="a" ref="$b.T_DATA">
<Substance>
<tt:cond check="not-initial($a.EXTID)">
<tt:attribute name="ExtId" value-ref="$a.EXTID"/>
</tt:cond>
<tt:cond check="not-initial($a.SPEED)">
<tt:attribute name="Speed" value-ref="$a.SPEED"/>
</tt:cond>
</Substance>
</tt:loop>
<Total>
<tt:cond check="not-initial($b.STATE)">
<tt:attribute name="State" value-ref="$b.STATE"/>
</tt:cond>
<tt:cond check="not-initial($b.RESULT)">
<tt:attribute name="Result" value-ref="$b.RESULT"/>
</tt:cond>
</Total>
</Weighing>
</tt:loop>
</Automatic>
</tt:template>
</tt:transform>
Many thanks in advance.