Application Development and Automation 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: 
Read only

Problem Converting xml to ABAP

Former Member
0 Likes
1,327

Dear all,

We are uploading a PDF file and converting to XML (into string variable).

This XML has three elements:

     - Structure        (OK)

     - Internal Table (OK)

     - Variable          (Not OK)

When calling transformation to pass these data from XLM into respective elements, we have the structure and internal table filling very well, but i REALLY don't know why the variable I caught  the exception CX_ST_MATCH_ELEMENT.

I tried to find something, but nothing useful.

Below my code:

CALL TRANSFORMATION ztransf

       SOURCE XML lv_xml_data_string

       RESULT root    = s1

                       root1  = t1

                       root2  = v1.

lv_xml_data_string contains (I pasted only the final):

<NETWR_WAERS/></DATA></LISTA_ITENS></DADOS_COTACAO><V1>ggggggggggggg</V1>

The <V1>ggggggggggggg</V1> is important here, I just need to pass "ggggggggggggg" to a simple variable.

Now, my transformation code:

<?sap.transform simple?>

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

   <tt:root name="ROOT" type="?"/>

   <tt:root name="ROOT1" type="?"/>

   <tt:root name="ROOT2" type="?"/>

   <tt:template>

     <DADOS_COTACAO tt:ref="ROOT">

       <BUKRS>

         <tt:value ref="BUKRS"/>

       </BUKRS>

       <LIFNR>

         <tt:value ref="LIFNR"/>

       </LIFNR>

       <NAME1>

         <tt:value ref="NAME1"/>

       </NAME1>

       <STRAS>

         <tt:value ref="STRAS"/>

       </STRAS>

       <LISTA_ITENS>

         <tt:loop name="data" ref=".ROOT1">

           <DATA xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">

             <EBELP>

               <tt:value ref="$data.ebelp"/>

             </EBELP>

             <EBELN>

               <tt:value ref="$data.ebeln"/>

             </EBELN>

             <MATNR>

               <tt:value ref="$data.matnr"/>

             </MATNR>

             <MAKTX>

               <tt:value ref="$data.maktx"/>

             </MAKTX>

             <LABST>

               <tt:value ref="$data.labst"/>

             </LABST>

             <LABST_MEINS>

               <tt:value ref="$data.labst_meins"/>

             </LABST_MEINS>

             <NETWR>

               <tt:value ref="$data.netwr"/>

             </NETWR>

             <NETWR_WAERS>

               <tt:value ref="$data.netwr_waers"/>

             </NETWR_WAERS>

           </DATA>

         </tt:loop>

       </LISTA_ITENS>

     </DADOS_COTACAO>

    

     <V1>                                             """""Here is the part that isn't working

       <tt:value ref="ROOT2"/>

     </V1>

   </tt:template>

</tt:transform>

Please, i really appreciate any help!

Best Regrads

Thanks In advanced

Vinicius Ostan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,180

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. BEGIN OF ty_input,
  3.   col1 TYPE d ,
  4.   col2 TYPE t ,
  5. END OF ty_input.
  6. ***
  7. DATA: input      TYPE ty_input,
  8.       ls_input2  TYPE ty_input,
  9.       input2     TYPE TABLE OF ty_input,
  10.       input3     TYPE string VALUE 'asdf',
  11.       xml_string TYPE string,
  12.       result     LIKE input,
  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>

/.

8 REPLIES 8
Read only

Former Member
0 Likes
1,180

This message was moderated.

Read only

Former Member
0 Likes
1,181

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. BEGIN OF ty_input,
  3.   col1 TYPE d ,
  4.   col2 TYPE t ,
  5. END OF ty_input.
  6. ***
  7. DATA: input      TYPE ty_input,
  8.       ls_input2  TYPE ty_input,
  9.       input2     TYPE TABLE OF ty_input,
  10.       input3     TYPE string VALUE 'asdf',
  11.       xml_string TYPE string,
  12.       result     LIKE input,
  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>

/.

Read only

0 Likes
1,180

Thanks Kumar.

This good example is working well.

I analyze this example against my code, and it supposedly should run fine. But I dont know why I'm getting error.

I get XLM when uploading PDF file, so I can't manipulate its code.

Please, could you see if there is any synthetically difference in XML, because I dont see.

Bellow my complete XML (when uploading PDF).

<DADOS_COTACAO> " "Structure with 2 fields - OK

     <BUKRS>1000</BUKRS>

     <LIFNR>0098000000</LIFNR>

          <LISTA_ITENS> "Table with 3 fields and 1 row - OK

          <DATA xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">

          <EBELP>00010</EBELP>

          <EBELN>0100000000</EBELN>

          <MATNR>R10001</MATNR>

</DADOS_COTACAO> "end structure TAG

<V1>teste</V1> "Variable that's getting error


Thank you so much.

Read only

0 Likes
1,180

I don't see the DATA tag getting closed here. With one line content it is not clear whether DATA tag is repeating or something else. Try posting complete xml, xslt and abap code as attachment (use advanced editor to see attachment option). I can then have a look.

Read only

0 Likes
1,180

Kumar,

Please, see attachments.

Again, thank you so much.

Read only

0 Likes
1,180

I found the error, as you said, was missing the DATA tag in XML.

I've inserted it in transformation code e now it's OK.

Kumar, I really appreciate your help.

Thanks a lot.

Best Regards..

Read only

0 Likes
1,180

It looks like proper xml can have only one root element. Your xml has DADOS_COTACAO as well as V1 at top level of hierarchy.

I enclosed the xml content in another tag that became new root.

New xml became something this.

<XMLROOT>

<DADOS_COTACAO>....</DADOS_COTACAO>

<V1>...</V1>

</XMLROOT>

You can do something similar by concatenating <XMLROOT>, xml_string, </XMLROOT> into single string.

After having single root, following simple transformation worked.


<?sap.transform simple?>

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

  <tt:root name="ROOT"/>

  <tt:root name="ROOT1"/>

  <tt:root name="ROOT2"/>

  <tt:template>

    <XMLROOT>

      <DADOS_COTACAO>

        <BUKRS>

          <tt:value ref="ROOT.BUKRS"/>

        </BUKRS>

        <LIFNR>

          <tt:value ref="ROOT.LIFNR"/>

        </LIFNR>

        <LISTA_ITENS>

          <tt:loop name="data" ref="ROOT1">

            <DATA xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">

              <EBELP>

                <tt:value ref="$data.EBELP"/>

              </EBELP>

              <EBELN>

                <tt:value ref="$data.EBELN"/>

              </EBELN>

              <MATNR>

                <tt:value ref="$data.MATNR"/>

              </MATNR>

            </DATA>

          </tt:loop>

        </LISTA_ITENS>

      </DADOS_COTACAO>

      <V1>

        <tt:value ref="ROOT2"/>

      </V1>

    </XMLROOT>

  </tt:template>

</tt:transform>

/.

Read only

0 Likes
1,180

You are completely right.

I was clearing the first TAG DATA. For this I was getting error.

Thank you so much.