运行程序后,我必须将以下 XML 解析为内部表,得到简短的转储。请看下面的程序和简单的转换。简单转换中发生异常,下面将详细说明。
分配给类“CX_ST_MATCH_ELEMENT”的异常未被捕获,因此导致运行时错误。
异常的原因是:
XML 匹配错误预期为元素结束:“总计”[] 读取为元素开始:“称重”
我的 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).
程序:
* 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 转换:
<?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>
提前谢谢了。