I'm using SAP Simple Transformation and I want to set value of unitCode
attribute from ABAP field which is defined inside my structure. Let's say it's UNITCODE
field.
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCode="C62" unitCodeListID="UNECRec20"/>
Right now unitCode
is hardcoded as value C62
but I want that this attribute takes value from ABAP UNITCODE
field (in same structure as INVOICEDQUANTITY
). How can I make this happen?
Thanks in advance!
You may initialize an attribute from an ABAP variable using tt:attribute
:
<cbc:InvoicedQuantity tt:value-ref="INVOICEDQUANTITY" unitCodeListID="UNECRec20">
<tt:attribute name="unitCode" value-ref="UNITCODE"/>
</cbc:InvoicedQuantity>
Below is a Minimal Reproducible Example:
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 version="1.0" encoding="UTF-8"?>
<ROOT xmlns:cbc="http://xxx">
<cbc:InvoicedQuantity unitCodeListID="UNECRec20" unitCode="C62">
1000
</cbc:InvoicedQuantity>
</ROOT>