Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Simple Transformation: Variable XML node names

patricksteffens
Participant
0 Likes
2,475

Can I serialize ABAP tables containing nodes with variable names into XML using simple transformations?

The Output XML should look as follows:

<?XML Version="1.0" Encoding=UTF-16"?><Root>
  <Table>
    <abc> 1 </abc>
    <def> 2 </def>
  </Table>
</Root>

The ABAP content:

TYPES: BEGIN OF ly_table,
         param TYPE string,
         value TYPE string,
       END OF ly_table.

DATA lt_table TYPE TABLE OF ly_table.
lt_table = VALUE #( ( param = 'abc' value = '1' )
                    ( param = 'def' value = '2' ) ).
I.e. the identifiers and number of nodes in <Table> are not known at design time.

How would I realize that in ST? Is it even possible?


2 REPLIES 2
Read only

Sandra_Rossi
Active Contributor
1,314

With a Simple Transformation, which can only transform an ABAP data object to XML or vice versa, the Simple Transformation must define the XML element tags statically. Example - the root ABAP data object "ABAP_TABLE" is an internal table whose lines have components ZABC and ZDEF, the XML can only be defined statically :

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ss="cc">
  <tt:root name="ABAP_TABLE"/>
  <tt:template>
    <Table>
      <tt:loop ref=".ABAP_TABLE" name="line">
      <Line>
        <abc tt:value-ref="$line.ZABC"/>
        <def tt:value-ref="$line.ZDEF"/>
      </Line>
    </Table>
  </tt:template>
</tt:transform>f

So that to replace dynamically the tags of elements <abc ... and <def , the only workaround I can imagine is to create and fill an intermediate internal table dynamically (RTTS) with components ABC, DEF, and then use tt:copy .... A table of two lines would create a weird XML like "<_T00006S0000000><ABC>1</ABC><DEF>2</DEF></_T00006S0000000><_T00006S0000000><ABC>3</ABC><DEF>4</DEF></_T00006S0000000>". The element name for each line is weird (because it's a type generated by RTTS), the element names are in upper case, and you cannot customize anything inside the serialized internal table.

Or you build the XML from scratch in ABAP by using sXML classes.

Or you build the XML by concatenating strings. By the way, you may use escape to convert special characters to their character entity references:

xmlvalue = escape( val = value format = cl_abap_format=>e_xml_text ). " Expl: & -> &.amp; (no ".")
Read only

DoanManhQuynh
Active Contributor
0 Likes
1,314

If you call transformation id, you can see that xml node will take its name from table column. so what you want just like transpose the internal table row to column then transform to xml. You could search the transpose solution first.