Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8902

Re: Problem Converting xml to ABAP

$
0
0

Have a look at below snippets. I have modified standard example so that it looks similar to your case, root structure, root internal table and root variable. Run it in debug to see that ABAP to XML and XML to ABAP transformations are happening successfully.

 

ABAP code

  1. TYPES:
  2. BEGINOF ty_input,
  3.   col1 TYPE d ,
  4.   col2 TYPE t ,
  5. ENDOF ty_input.
  6. ***
  7. DATA: input      TYPE ty_input,
  8.       ls_input2  TYPE ty_input,
  9.       input2     TYPETABLEOF ty_input,
  10.       input3     TYPE string VALUE'asdf',
  11.       xml_string TYPE string,
  12.       result     LIKEinput,
  13.       result2    LIKE input2,
  14.       result3    LIKE input3.
  15. ***
  16. input-col1 = 'ABCDEFGHIJ'.
  17. input-col2 = 111.
  18. ***
  19. ls_input2-col1 = '20040126'.
  20. ls_input2-col2 = '084000'.
  21. APPEND ls_input2 TO input2.
  22. ls_input2-col1 = '20050126'.
  23. ls_input2-col2 = '085000'.
  24. APPEND ls_input2 TO input2.
  25. ls_input2-col1 = '20060126'.
  26. ls_input2-col2 = '086000'.
  27. APPEND ls_input2 TO input2.
  28. TRY.
  29.     CALL TRANSFORMATION zm1
  30.       SOURCE root  = input
  31.              root2 = input2
  32.              root3 = input3
  33.       RESULT XML xml_string.
  34. ***
  35.     CALL TRANSFORMATION zm1
  36.       SOURCE XML xml_string
  37.       RESULT root  = result
  38.              root2 = result2
  39.              root3 = result3.
  40.     WRITE'pass'.
  41.   CATCH cx_st_error.
  42.     WRITE'fail'.
  43. ENDTRY.

 

Simple transformation code

<?sap.transform simple?><tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp" version="0.1">  <tt:root name="ROOT"/>  <tt:root name="ROOT2"/>  <tt:root name="ROOT3"/>  <tt:template name="temp">    <X>      <X1>        <tt:value ref="ROOT.COL1"/>      </X1>      <X2>        <tt:value ref="ROOT.COL2"/>      </X2>      <X3>        <tt:loop name="line" ref="ROOT2">          <ITEM>            <X1>              <tt:value ref="$line.COL1"/>            </X1>            <X2>              <tt:value ref="$line.COL2"/>            </X2>          </ITEM>        </tt:loop>      </X3>      <X4>        <tt:value ref="ROOT3"/>      </X4>    </X>  </tt:template></tt:transform>

 

/.


Viewing all articles
Browse latest Browse all 8902

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>