cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Transformation - ABAP to XML - Dynamic attribute name

0 Kudos
218

Let's start with the question: Is it possible to have dynamic attribute names with simple transformations?

And for a bit of context: From our S/4HANA Public Cloud Edition we need to export data in XML format. The easiest way to convert an internal table to XML is by using a simple transformation. To keep this as flexible as possible, I have added property attributes as a name/value table.

ARTICLE-VALUE = 'BL22070'
ARTICLE-PROPERTIES = ( ( name = 'group'   value = 'BK' )
                       ( name = 'chgdate' value = '20240807' ) ).

 In the simple transformation, this is processed in a loop:

<tt:loop ref = "article.properties">
  <tt:attribute name="$ref.name" value-ref="$ref.value"/>
</tt:loop>

Everything else (of course there is more data) works as expected, the XML looks great... except for the attribute name here. The "$ref.name" is copied literally.

<article $ref.name="BK" $ref.name="20240807">

Fair enough, the documentation of the tt:attribute tag does not mention any dynamic way of defining the name... as I found out after this did not work.

Is there a different method to get this to work? Should I start over and switch to XSLT? Or just accept that I will have to define all attribute names statically in the simple transformation and check whether to include them based on the corresponding ref-value?

Thanks in advance for your help and insights!

Sandra_Rossi
Active Contributor
0 Kudos
I'd say that using XML transformations in ABAP systems (whatever it's Cloud or not Cloud) is the most appropriate way of working with XML. Simple transformations used to be 10 times faster than XSLT (tests done years ago, but not on Cloud), especially because ST is a lightweight language compared to XSLT. ST also permits to call ABAP methods to work around missing features.
0 Kudos
Bottom line is... you cannot dynamically assign both the attribute name and value. One of my colleagues suggested the simply build the XML manually using ABAP Cloud, which can still be done using class cl_sxml_string_writer. You can then add tags, attributes and values, creating the XML exactly as you would want it. And as long as you provide the data in a generic way, that XML coding does not have to be very complex.

Accepted Solutions (0)

Answers (0)