将字段值分配给 ABAP ST 转换中的属性?
Assign field value to attribute in ABAP ST transformation?
我正在使用 SAP 简单转换,我想从在我的结构中定义的 ABAP 字段设置 unitCode
属性的值。假设它是 UNITCODE
字段。
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCode="C62" unitCodeListID="UNECRec20"/>
现在 unitCode
被硬编码为值 C62
但我希望此属性从 ABAP UNITCODE
字段中获取值(与 INVOICEDQUANTITY
具有相同的结构)。我怎样才能做到这一点?
提前致谢!
而不是:
unitCode="C62"
您可以使用:
unitCode="{UnitCode}"
或更准确地说:
unitCode="{path/to/UnitCode}"
其中 path/to/UnitCode
是从当前节点的上下文到 UnitCode
元素的路径。
您可以使用 tt:attribute
:
从 ABAP 变量初始化属性
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCodeListID="UNECRec20">
<tt:attribute name="unitCode" value-ref="UNITCODE"/>
</cbc:InvoicedQuantity>
下面是一个最小的可重现示例:
- ABAP :
DATA : BEGIN OF ls_data,
invoicedquantity TYPE decfloat34,
unitcode TYPE string,
END OF ls_data.
ls_data = VALUE #( invoicedquantity = 1000 unitcode = 'C62' ).
CALL TRANSFORMATION ztransfo
SOURCE abaproot = ls_data
RESULT XML DATA(xml).
- 简单转换
ZTRANSFO
:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
xmlns:ddic="http://www.sap.com/abapxml/types/dictionary">
<tt:root name="ABAPROOT"/>
<tt:template>
<ROOT xmlns:cbc="http://xxx" tt:ref="ABAPROOT">
<cbc:InvoicedQuantity unitCodeListID="UNECRec20">
<tt:attribute name="unitCode" value-ref="UNITCODE"/>
<tt:value ref="INVOICEDQUANTITY"/>
</cbc:InvoicedQuantity>
</ROOT>
</tt:template>
</tt:transform>
- 预期XML结果:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:cbc="http://xxx">
<cbc:InvoicedQuantity unitCodeListID="UNECRec20" unitCode="C62">
1000
</cbc:InvoicedQuantity>
</ROOT>
我正在使用 SAP 简单转换,我想从在我的结构中定义的 ABAP 字段设置 unitCode
属性的值。假设它是 UNITCODE
字段。
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCode="C62" unitCodeListID="UNECRec20"/>
现在 unitCode
被硬编码为值 C62
但我希望此属性从 ABAP UNITCODE
字段中获取值(与 INVOICEDQUANTITY
具有相同的结构)。我怎样才能做到这一点?
提前致谢!
而不是:
unitCode="C62"
您可以使用:
unitCode="{UnitCode}"
或更准确地说:
unitCode="{path/to/UnitCode}"
其中 path/to/UnitCode
是从当前节点的上下文到 UnitCode
元素的路径。
您可以使用 tt:attribute
:
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCodeListID="UNECRec20">
<tt:attribute name="unitCode" value-ref="UNITCODE"/>
</cbc:InvoicedQuantity>
下面是一个最小的可重现示例:
- ABAP :
DATA : BEGIN OF ls_data, invoicedquantity TYPE decfloat34, unitcode TYPE string, END OF ls_data. ls_data = VALUE #( invoicedquantity = 1000 unitcode = 'C62' ). CALL TRANSFORMATION ztransfo SOURCE abaproot = ls_data RESULT XML DATA(xml).
- 简单转换
ZTRANSFO
:<?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"> <tt:root name="ABAPROOT"/> <tt:template> <ROOT xmlns:cbc="http://xxx" tt:ref="ABAPROOT"> <cbc:InvoicedQuantity unitCodeListID="UNECRec20"> <tt:attribute name="unitCode" value-ref="UNITCODE"/> <tt:value ref="INVOICEDQUANTITY"/> </cbc:InvoicedQuantity> </ROOT> </tt:template> </tt:transform>
- 预期XML结果:
<?xml version="1.0" encoding="UTF-8"?> <ROOT xmlns:cbc="http://xxx"> <cbc:InvoicedQuantity unitCodeListID="UNECRec20" unitCode="C62"> 1000 </cbc:InvoicedQuantity> </ROOT>