我在使用简单转换时遇到一个问题,我无法弄清楚。
CX_ST_REF_ACCESS
运行代码在转换行上给我以下错误消息(异常类) <tt:loop name="PurchaseOrder" ref="PurchaseOrder">
:
访问引用节点“PURCHASEORDER”时出错。引用节点未定义或没有必要的类型
当我使用时出现错误CALL Transformation
。
我尝试使用简单转换从 XML 中读取数据。
这是我的简单转变:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="PurchaseOrder"/>
<!-- Root element: PurchaseOrder -->
<tt:template>
<tt:loop name="PurchaseOrder" ref="PurchaseOrder">
<PurchaseOrder>
<!-- Address Elements -->
<Address>
<tt:loop name="Adress" ref="PurchaseOrder.Address">
<Name>
<tt:value ref="Name"/>
</Name>
<Street>
<tt:value ref="Street"/>
</Street>
<City>
<tt:value ref="City"/>
</City>
<State>
<tt:value ref="State"/>
</State>
<Zip>
<tt:value ref="Zip"/>
</Zip>
<Country>
<tt:value ref="Country"/>
</Country>
</tt:loop>
</Address>
<!-- DeliveryNotes Element -->
<DeliveryNotes>
<tt:value ref="PurchaseOrder"/>
</DeliveryNotes>
<!-- Items Section -->
<Items>
<tt:loop ref="PurchaseOrder">
<Item>
<ProductName>
<tt:value ref="ProductName"/>
</ProductName>
<Quantity>
<tt:value ref="Quantity"/>
</Quantity>
<USPrice>
<tt:value ref="USPrice"/>
</USPrice>
<tt:cond>
<Comment>
<tt:value ref="Comment"/>
</Comment>
</tt:cond>
<tt:cond>
<ShipDate>
<tt:value ref="ShipDate"/>
</ShipDate>
</tt:cond>
</Item>
</tt:loop>
</Items>
</PurchaseOrder>
</tt:loop>
</tt:template>
</tt:transform>
我的 ABAP 代码(精简到相关部分):
TYPES: BEGIN OF ty_address,
name TYPE string,
street TYPE string,
city TYPE string,
state TYPE string,
zip TYPE string,
country TYPE string,
END OF ty_address.
TYPES: BEGIN OF ty_item,
productname TYPE string,
quantity TYPE i,
usprice TYPE p DECIMALS 2,
comment TYPE string, " Optionales Feld für Kommentar
shipdate TYPE d, " Optionales Feld für ShipDate
END OF ty_item.
DATA: BEGIN OF ty_purchase_order,
addresses TYPE TABLE OF ty_address, " Mehrere Address-Einträge
deliverynotes TYPE string,
items TYPE TABLE OF ty_item, " Tabelle mit Items
END OF ty_purchase_order.
DATA: gv_file TYPE string, " Datei für den Upload
lt_xml_table TYPE TABLE OF string, " Tabelle für XML-Zeilen
gv_xml_string TYPE string. " Für das gesamte XML als String
gv_file = p_file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gv_file
* codepage = '1252'
CHANGING
data_tab = lt_xml_table
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
LOOP AT lt_xml_table INTO DATA(lv_line).
CONCATENATE gv_xml_string lv_line INTO gv_xml_string.
ENDLOOP.
CALL TRANSFORMATION ZJB_TRAN0
SOURCE XML gv_xml_string
RESULT PurchaseOrder = ty_purchase_order.
最后我想要处理的 XML 文件是:
<PurchaseOrder>
<Address>
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>USA</Country>
</Address>
<Address>
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
<Items>
<Item>
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item>
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<ShipDate>1999-05-21</ShipDate>
</Item>
</Items>
</PurchaseOrder>