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

XML TO ABAP

Former Member
0 Likes
874

Hello All,

We have been durind the last week to map an XML file to an ABAP interal table, with out any success. We have read wiki samples, blogs and several post about it, but we have not been able to read completely the XML.

We are doing it with CALL TRANSFORMATION stm,

The XML structure is:


<BEAN>
   <MSGID>22</MSGID>
   <SUPPLIER>11</SUPPLIER>
   <EVENTS>
        <EVENT>
              <ID_PROGRAM> RRRRARR</ID_PROGRAM>
              <CALLS>
                      <CALL>
                             <ID_CALL>222</ID_CALL>
                             <CAN>333</CAN>
                      </CALL>
              </CALLS>
        </EVENT>
   </EVENTS>
</BEAN>

The XSL we are using is:


        <BEAN>
          <BEAN>
            <MSGID>
              <xsl:value-of select="bean/msgid"/>
            </MSGID>
            <SUPPLIER>
              <xsl:value-of select="bean/supplier"/>
            </SUPPLIER>
            <EVENTS>
              <EVENT>
                <EVENT>
                  <IDPROGRAM>
                       <xsl:value-of select="idprogram"/>
                  </IDPROGRAM>                  
                  <CALLS>
                         <xsl:for-each select="//call">
                         <CALL>
                            <ID_CALL>
                                <xsl:value-of select="call"/>
                            </ID_CALL>
                            <CAN>
	         <xsl:value-of select="can"/>
                           </CAN>
                      </CALL>
                    </xsl:for-each>
                  </CALLS>
                </EVENT>
              </EVENT>
            </EVENTS>
          </BEAN>
        </BEAN>

But we are unable to map values of the node <CALLS>, we have no more ideas or clue on how to achive it,

PLEASE HELP US!!

Gabriel P.-

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
813

Hello

Any more ideas??

10nks

Gabriel.

5 REPLIES 5
Read only

Former Member
0 Likes
813

Sorry, I fogot the types definded for this are:




 TYPES: BEGIN OF ty_call,
       id_call TYPE string,
      can      TYPE string,
END OF ty_call.

 TYPES: BEGIN OF ty_calls ,
          call    TYPE  ty_call,
END OF   ty_calls .

 TYPES: BEGIN OF ty_event,
          idprogram TYPE string,
          calls TYPE ty_calls,
END OF ty_event.

 TYPES: BEGIN OF ty_events,
          event   TYPE ty_event, " string,
END OF   ty_events.

 TYPES: ty_tabevent TYPE  ty_events OCCURS 0 .

 TYPES: BEGIN OF ty_bean,
           msgid    TYPE string,
           supplier TYPE string,
           events   TYPE ty_events,
 END OF   ty_bean.

Thanks again!!

Read only

Former Member
0 Likes
813

Hi,

Please use following Link,

/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach

It really worked for me.

Thanks & Regards,

ShreeMohan

Edited by: ShreeMohan Pugalia on Jul 31, 2009 3:36 PM

Read only

Former Member
0 Likes
814

Hello

Any more ideas??

10nks

Gabriel.

Read only

0 Likes
813

What a mess in your XSL ! Here I give you something more correct than yours but I didn't test it. When you fixed it, please post the final solution for people who would be interested.

Before working on BIG problems, I advise you to practice on LITTLE problems first, to understand how XSL works. (this is valid for all kinds of problems)

Well now...

You made an error in the ABAP type : I guess EVENTS and CALLS should be table types ! My answer assumes you have corrected that.

Moreover, I guess you don't know the "item" node that you must put in the XSL, it is REQUIRED for table types.

If the XSD (used to define how your XML will always look like) corresponds to your ABAP type, then the XSL should be as follows.

GOOD LUCK !


       <BEAN>
          <BEAN>
            <MSGID>
              <xsl:value-of select="bean/msgid"/>
            </MSGID>
            <SUPPLIER>
              <xsl:value-of select="bean/supplier"/>
            </SUPPLIER>
            <EVENTS>
              <xsl:for-each select="bean/events/event">
              <item>
                  <IDPROGRAM>
                       <xsl:value-of select="idprogram"/>
                  </IDPROGRAM>                  
                  <CALLS>
                     <xsl:for-each select="calls/call">
                     <item>
                         <CALL>
                            <ID_CALL>
                                <xsl:value-of select="id_call"/>
                            </ID_CALL>
                            <CAN>
                                <xsl:value-of select="can"/>
                           </CAN>
                        </CALL>
                      </item>
                    </xsl:for-each>
                  </CALLS>
              </item>
              </xsl:for-each>
            </EVENTS>
          </BEAN>
        </BEAN>

Read only

0 Likes
813

Thanks Sandra...

Sorry if I had mistakes...for confidenciality reasons I had to change XML and XSL files, so I might had some mistakes during translation. I´ve been working on this transformation for a week, with out noticing simple stuff.

About your sample code...you are correct, I did not know that that item node was required. I´ll try and let you know Thanks again

Gabriel P.-