The serialization and deserialization of structures results directly from the addressing rules, because the structures can be mapped directly to the tree structures that start from the data roots. When the current node is bound to an elementary component of an ABAP structure, the structure can be processed with tt:valuejust like an elementary data object.
The three ST programs in the sections Current Node, Addressing the Current Node, and Addressing Subnodes of the Current Node can transform a nested ABAP structure symmetrically. The following program can call these three ST programs:
DATA: BEGIN OF
struc1,
col1(10) TYPE c VALUE
'ABCDEFGHIJ',
col2
TYPE i VALUE 111,
BEGIN OF struc2,
col1 TYPE d VALUE
'20040126',
col2 TYPE t VALUE
'084000',
END OF struc2,
END OF struc1.
DATA: xml_string TYPE
string,
result LIKE struc1.
TRY.
CALL
TRANSFORMATION ...
SOURCE
root = struc1
RESULT XML xml_string.
CALL
TRANSFORMATION ...
SOURCE
XML xml_string
RESULT root = result.
IF
struc1 <> result.
MESSAGE 'Deserialization <>
Serialization' TYPE 'I'.
ENDIF.
CATCH cx_st_error.
...
ENDTRY.
The result of the serialization is the same XML document for all three simple transformations:
<X>
<X1>ABCDEFGHIJ</X1>
<X2>111</X2>
<X3>
<X1>2004-01-26</X1>
<X2>08:40:00</X2>
</X3>
</X>