2015 Aug 05 5:12 PM
I have a requirement to populate an XML file from ABAP using
CALL TRANSFORMATION zpa_cpr_to_xml
SOURCE root = lt_cpr_xml
RESULT XML lw_xml.
where lt_cpr_xml is an ABAP deep structure (nested internal tables)
and lw_xml is the XML string returned by the transformation.
I believe most of it is working properly by I still need to set the ID=... attribute on one of the resulting XML tags.
The sample file provided for my requirement includes the following section of XML, including the attribute ID="123456" on the CPR:name node:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
...
<CPR:payrollInfo>
...
<CPR:employees>
<CPR:employee>
<CPR:name id="123456">John Smith</CPR:name>
...
Currently, my corresponding XML simple transformation looks like this...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<tt:loop name="cprdata" ref=".ROOT">
...
<CPR:payrollInfo>
...
<CPR:employees>
<tt:loop name="employee" ref="$cprdata.payinfo.payemps">
<CPR:employee>
<CPR:name id="123456">
<tt:value ref="$employee.empname"/>
</CPR:name>
...
I need to set the ID="123456" attribute on the CPR:name tag, replacing the "123456" constant with the value associated with the $employee.empid variable as it loops through my $cprdata.payinfo.payemps source root deep structure that was passed into the transformation.
What tt:instruction do I use to set attributes of particular XML nodes to values from the ABAP source data?
I have had a tough time finding any documentation or examples regarding this requirement, so any assistance would be greatly appreciated.
Thanks,
Bryan
2015 Aug 06 9:20 PM
Solution:
After changing my root node to explicitly reference my underlying ABAP table type, it was able to see the new EmpID field I had added to the structure...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT" type="ddic:ZPA_CPR_XML_TAB"/>
<tt:template name="ZPA_CPR_XML">
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<tt:loop name="cprdata" ref=".ROOT">
...
<CPR:payrollInfo>
...
...and I was then able to use the tt:attribute command
...
<CPR:employees>
<tt:loop name="employee" ref="$cprdata.payinfo.payemps">
<CPR:employee>
<CPR:name>
<tt:attribute name="id" value-ref="$employee.empid"/>
<tt:value ref="$employee.empname"/>
</CPR:name>
...
...which produced the resulting XML
<CPR:employees>
<CPR:employee>
<CPR:name id="EmpID">EmpName</CPR:name>
...
I hope that helps whoever else is trying to do this.
Thanks for your interest.
Bryan
I have a requirement to populate an XML file from ABAP using
CALL TRANSFORMATION zpa_cpr_to_xml
SOURCE root = lt_cpr_xml
RESULT XML lw_xml.
where lt_cpr_xml is an ABAP deep structure (nested internal tables)
and lw_xml is the XML string returned by the transformation.
I believe most of it is working properly by I still need to set the ID=... attribute on one of the resulting XML tags.
The sample file provided for my requirement includes the following section of XML, including the attribute ID="123456" on the CPR:name node:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
...
<CPR:payrollInfo>
...
<CPR:employees>
<CPR:employee>
<CPR:name id="123456">John Smith</CPR:name>
...
Currently, my corresponding XML simple transformation looks like this...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<tt:loop name="cprdata" ref=".ROOT">
...
<CPR:payrollInfo>
...
<CPR:employees>
<tt:loop name="employee" ref="$cprdata.payinfo.payemps">
<CPR:employee>
<CPR:name id="123456">
<tt:value ref="$employee.empname"/>
</CPR:name>
...
I need to set the ID="123456" attribute on the CPR:name tag, replacing the "123456" constant with the value associated with the $employee.empid variable as it loops through my $cprdata.payinfo.payemps source root deep structure that was passed into the transformation.
What tt:instruction do I use to set attributes of particular XML nodes to values from the ABAP source data?
I have had a tough time finding any documentation or examples regarding this requirement, so any assistance would be greatly appreciated.
Thanks,
Bryan
2015 Aug 06 9:20 PM
Solution:
After changing my root node to explicitly reference my underlying ABAP table type, it was able to see the new EmpID field I had added to the structure...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT" type="ddic:ZPA_CPR_XML_TAB"/>
<tt:template name="ZPA_CPR_XML">
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<tt:loop name="cprdata" ref=".ROOT">
...
<CPR:payrollInfo>
...
...and I was then able to use the tt:attribute command
...
<CPR:employees>
<tt:loop name="employee" ref="$cprdata.payinfo.payemps">
<CPR:employee>
<CPR:name>
<tt:attribute name="id" value-ref="$employee.empid"/>
<tt:value ref="$employee.empname"/>
</CPR:name>
...
...which produced the resulting XML
<CPR:employees>
<CPR:employee>
<CPR:name id="EmpID">EmpName</CPR:name>
...
I hope that helps whoever else is trying to do this.
Thanks for your interest.
Bryan
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |