I am writing a serialization through ST and it should put several vars/nodes into one XML tag.
Input ABAP itab that should be serialized:
ROW_ID ROW
VAL INDEX
1 val55 X
val32 Y
val46 X
2 val8 X
val16
val789
3 val78 Y
val53 Y
val98 Y
where each ROW
value is an itab which consists of VAL
and INDEX
fields
Expected output sample for first row:
<rows>
<row r="1">
<c r="1_xcell1">
<v>val55</v>
</c>
<c r="1_ycell2">
<v>val32</v>
</c>
<c r="1_xcell3">
<v>val46</v>
</c>
<row>
</rows>
Here
1 in <row r="1">
corresponds to row number from ROW_ID
1_xcell1 in <c r="1_xcell1">
is a concatenation of ROW_ID
from the current line of root table, INDEX
field of current ROW
line, literal cell
and loop counter of ROW
table
The transformation I ended up with is:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="main">
<tt:root name="root"/>
<tt:variable name="range" val="11"/>
<tt:template name="main">
<rows>
<tt:loop name="row" ref="root">
<row>
<tt:attribute name="r" value-ref="row_id"/>
<tt:assign to-var="range" ref="row_id"/>
<tt:loop name="cells" ref="$row.ROW">
<tt:serialize>
<c>
<tt:attribute name="r"><tt:write var="range" map="val(I(1)) = xml('1_xcell1'), val(I(2)) = xml('2_xcell2'), val(I(3)) = xml('3_xcell3)"/></tt:attribute>
<v><tt:value ref="value"/></v>
</c>
</tt:serialize>
</tt:loop>
</row>
</tt:loop>
</rows>
</tt:template>
</tt:transform>
where I put the ROW_ID
into var for using in mapping on the lower lever in <c>
tag.
As you can see, this approach will not work because I have no idea how to put loop counter and how to concatenate it with other values.
I found a couple of old threads on answers.sap.com (1, 2, 3), but they are left unanswered.
Is there a concatenation in ST like in XSLT:
`<xsl:element name="{concat($segment2, '_', $tail2)}">`?
Is there a built-in variable for loops like SY-TABIX
in ABAP?
This should work (if $row.row_id
equals 1
, it will generate ...<c r="1_xcell1">...
):
...
<c>
<tt:attribute name="r">
<tt:value ref="$row.row_id"/>_xcell<tt:value ref="$row.row_id"/>
</tt:attribute>
...
Concerning the loop counter, I think it can't be done within Simple Transformations, your solution to pass the row number explicitly inside the internal table is the best.