Skip to Content

Simple Transformation: Variable XML node names

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?


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Oct 29, 2019 at 08:15 PM

    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 ".")
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.