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

Help on XML transformation

Former Member
0 Likes
880

Hi all,

I discover the XML in SAP.

The goal is to integrate an xml file in SAP using an ABAP program.

File:

<A>
      <B>
             <C>Val 1</C>
             <D>Val 2 </D> 
             <E>Val 3 </E>
      </B>
      <B>
             <C>Val 4</C>
             <D>Val 5</D> 
             <E>Val 6</E>
      </B>
</A>

I create a table type include a structure with the following fields: C, D, E (all in char100).

A is the root and B a node.

When i try the test mode using a file, i have the following error (No Valide XSLT supplied program)...

When i try the transformation in an ABAP program, i have a dump...

Can someone help on this topic?

I looked on the web but i do not find some beginer's guide on the transaction XSLT_TOOL....

Thanks,

David

Edited by: David31 on Sep 23, 2010 3:45 PM

1 ACCEPTED SOLUTION
Read only

anesh_kumar
Active Participant
0 Likes
779

Hi

try this...

1. Write XSLT program. T.code XSLT . e.g. XSLT name "ZTRANS".

2. Write ABAP program

Which includes declaration of internal tables

that you need "IT_DATA".

Upload XML data to an internal table "IT_XML "

use below statement to convert XML to internal table.

Call transformation ZTRANS

source XML IT_XML

result IT_DATA.

check this [Link|http://sapblog.rmtiwari.com/2009/04/generate-simple-transformation-for-xml.html] as well

Regards

4 REPLIES 4
Read only

anesh_kumar
Active Participant
0 Likes
780

Hi

try this...

1. Write XSLT program. T.code XSLT . e.g. XSLT name "ZTRANS".

2. Write ABAP program

Which includes declaration of internal tables

that you need "IT_DATA".

Upload XML data to an internal table "IT_XML "

use below statement to convert XML to internal table.

Call transformation ZTRANS

source XML IT_XML

result IT_DATA.

check this [Link|http://sapblog.rmtiwari.com/2009/04/generate-simple-transformation-for-xml.html] as well

Regards

Read only

0 Likes
779

Hi,

I progress a few.

Now using the transformation in my program. I have an error on <tt:loop ref="A">.

Transformation:

1 <?sap.transform simple?>                                                                     
    2 <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www. 
    3   <tt:root name="A" type="ddic:TABLE_TYPE"/>                             
    4   <tt:template>                                                                                
5     <A>                                                                      
    6     <tt:loop ref="A">     <<<<<<<                                                 
    7         <B>                                                                   
    8           <target tt:value-ref="C"/>                                                    
    9           <atributename tt:value-ref="D"/>                                        
   10           <value tt:value-ref="E"/>                                                      
   11         </B>                                                                  
   12       </tt:loop>                                                                                
13     </A>                                                                     
   14   </tt:template>                                                                                
15 </tt:transform>

When i read the previous post (link) i do not see where is the mistake....

Thanks,

David

Read only

0 Likes
779

Hi

I don't think the issue is at the loop, it could be inside the loop

i mean the way you declare your elements and attributes

check you structure and if possible try to replicate the same example on the link that gives you an idea on how to drive with the XSLT TOOL

If you can send the ST structure i can have a look

There is one more way of converting itab to xml format, check the below code as well

CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'

EXPORTING

I_XML_DOC_NAME = 'xmldocument'

IMPORTING

PE_BIN_FILESIZE = BIN_SIZE

TABLES

I_TAB_SAP_DATA = T_EXTRACT " your table name

CHANGING

I_TAB_CONVERTED_DATA = XMLTAB

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

IF SY-SUBRC 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD CL_RSZ_WWW_DB_INTERFACE=>CONVERT_RAW_TO_CHAR

EXPORTING

I_T_IN = XMLTAB

IMPORTING

E_T_OUT = GT_ITAB[].

Regards

Read only

0 Likes
779

If 'A' is your root, then your ST program should look like the below code. This will render your internal table in your program. There are some help files on ST syntax but they aren't very good...


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="A"/>
  <tt:template>
    <A>
      <tt:loop name="line" ref=".A">
        <B>
          <C>
            <tt:value ref="$line.C"/>
          </C>
          <D>
            <tt:value ref="$line.D"/>
          </D>
          <E>
            <tt:value ref="$line.E"/>
          </E>
        </B>
      </tt:loop>
    </A>
  </tt:template>
</tt:transform>