Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to deal with complex data types (mixed elements) in ABAP simple transformations

fpeter
Discoverer
0 Kudos
392

Hi there,

I am working on an xml simple transformation logic, and I came across the following XML structure:

<PARENT>

<CHILD_1> some text start <CHILD_2> content </CHILD_2> some text continued </CHILD_1>

</PARENT>

Is it possible to deal with this situation in simple transformations in ABAP, and if yes, how? I would like to avoid XSLT usage...

Cheers,

Ferenc

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos
343

You are asking a solution where you "would like to avoid XSLT usage", what do you mean and why do you want to avoid it? What kind of solution are you currently using?

I guess you mean you are using Simple Transformation, and you want an answer about Simple Transformation only. No need to think about other technologies like the ABAP XML Libraries, XSLT, etc.

Sandra_Rossi
Active Contributor
0 Kudos
343

I guess that Simple Transformation doesn't handle XML text nodes natively, you need to use workarounds.

For instance, with my test program below (only the important part is posted), I get the whole CHILD_1 content, exactly as it is = '<CHILD_1> some text start <CHILD_2> content </CHILD_2> some text continued </CHILD_1>', in XSTRING / UTF-8 encoding.

After that, you may parse the contents of CHILD_1 with the ABAP XML Library you want, e.g. SXML.

The use of the type XSDANY is a key part of the XML Libraries to work directly with XML content (you can find explanations in the official ABAP documentation):

    TYPES:
      BEGIN OF ty_transfo_result,
          child_1 TYPE xsdany,
      END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                               ` )
              ( `<tt:transform                                          ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates">` )
              ( `  <tt:root name="PARENT"/>                             ` )
              ( `                                                       ` )
              ( `  <tt:template>                                        ` )
              ( `    <PARENT>                                           ` )
              ( `      <CHILD_1 tt:value-ref="PARENT.CHILD_1"/>         ` )
              ( `    </PARENT>                                          ` )
              ( `  </tt:template>                                       ` )
              ( `                                                       ` )
              ( `</tt:transform>                                        ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<PARENT>'
            && '<CHILD_1> some text start <CHILD_2> content </CHILD_2> some text continued </CHILD_1>'
            && '</PARENT>'.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT parent = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
                child_1 = cl_abap_codepage=>convert_to(
                    `<CHILD_1> some text start <CHILD_2> content </CHILD_2> some text continued </CHILD_1>` ) ) ).