Thursday, November 16, 2017

Simple Transformation to Serialize ABAP Deep Internal Table

Today I worked on an ABAP program to export batch classes, classifications and values to a cXML format file required by Ariba.

Serialization is ABAP to XML. Deserialization is the opposite.

Although I prefer XSLT over ST (both transformations are possible in SAP), I ended up using ST as I don't know XSLT properly yet.

A single internal table with deep structure was prepared which had all the data returned by relevant BAPIs.

The internal table was structured like this:

ROOT (itab)

  line

    class name

    class description

    characteristics (itab)

      line

        characteristic name

        characteristic description

    characteristic values (itab)

      line

        characteristic name

        characteristic value

        characteristic value description



Logic to traverse the internal table was written inside the transformation using tt:value tt:loop tt:cond+check tt:attribute commands.

To achieve proper node nesting, I needed an equivalent of LOOP WHERE in ST. This was possible by using tt:loop+name and tt:cond+check command.

Command tt:cond+check also allowed me to do something like "if var1 eq 'E'" and "if var2 eq var3".

DOCTYPE node could not be added using ST. So it was added by string manipulating the xml in ABAP code post transformation.



So, use of tt:cond and tt:loop+name qualifies this activity has something new (never done before) for me.

No comments: