Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAP Simple Transformation with arbitrary XML tags

I have XML of unknown structure and I want to apply ST (Simple Transformation) on it to get "somehow" that content out of XML into ABAP structures.

For now I have following test report:

report  ztbu_st_with_copy.

data: lf_xml type string.
concatenate '<tab><obj>'
              '<id>A1</id>'
              '<first>Erste</first>'
              '<second>Zweite</second>'
            '</obj><obj>'
              '<id>B2</id>'
              '<item>'
                '<here>Tady</here>'
                '<there>Tam</there>'
              '</item>'
            '</obj>'
            '</tab>'
       into lf_xml.

types: begin of ys_obj,
         id type string,
         rest type string,
       end of ys_obj,
       yt_obj type standard table of ys_obj.

data: lt_obj type yt_obj.

call transformation ztbu_st_copy_test
  source xml lf_xml
  result root = lt_obj.

uline.

data: ls_obj like line of lt_obj.
loop at lt_obj into ls_obj.
  write: / sy-tabix, ls_obj-id.
endloop.

uline.

and I have following ST transformation ZTBU_ST_COPY_TEST (the one called above):

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

<tt:root name="ROOT"/>

<tt:template>
  <tab>
  <tt:loop ref=".ROOT" name="obj">
      <obj>
        <id>
          <tt:value ref="$obj.ID" />
        </id>
        <tt:skip />
      </obj>
  </tt:loop>
  </tab>
</tt:template>

</tt:transform>

Now it works fine and it will bring IDs into the fields of table LT_OBJ. However the rest is ignored due to use of <TT:SKIP>. My goal would be to get the rest of XML document (these FIRST, SECOND, HERE and THERE or any arbitrary XML) into field REST in "some" format - probably as rough XML stored in STRING variable.

I understand I need to replace <TT:SKIP> with something smarter, but I can't figure it out what that should be... Any idea?

Side note: yes, I know, it would be better to use XSLT or something else, instead of ST, but I have no choice and I need to make it using ST.

like image 363
Tom Burger Avatar asked May 08 '13 15:05

Tom Burger


1 Answers

ST are constraint since the can be used both ways (abap <-> xml). They are great because they are fast. But they map ABAP values to XML nodes and there's not much options there. I beleive you can't do this with ST. SXML would be best for your senario.

like image 132
jerome Avatar answered Oct 03 '22 11:10

jerome