Application Development 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: 

XSLT content into ABAP Table

Former Member
0 Kudos
653

Hi all,

I'm receiving a XML from a Server and transform it via xslt-Transformation into an integer, because it is only one number.

Now I want to transform the data from a XML into a table. I checked some tutorials and there are many topics to solve this, but there, the structure is most for example: <id>1549347</id> <vorname>Albert</vorname> and so on.

But my file has the following structure:

<member><name>id</name><value><string>1549347</string></value></member>

  <member><name>vorname</name><value><string>Albert</string></value></member>

  <member><name>nachname</name><value><string>Hofman</string></value></member>

  <member><name>email</name><value><string>albert.hofman@kunde.at</string></value></member>

  <member><name>status</name><value><string>aktiv</string></value></member>

  <member><name>istatus</name><value><int>1</int></value></member>

(This structure for each customer)

I tried, but I don't know how to solve this. How do I get this into a structure?

I don't need the value from <name>, I only need the value itself (into a table layout).

Do you have any idea?

Thanks in advance,

regards,

Florian

7 REPLIES 7

Former Member
0 Kudos
191

Hi,

what I know is xslt[transformation language] is used in sap xi/pi to convert the message structure.

I didn't get for which requirement you are using the xslt.

provide us more details...

br,

avinash

Former Member
0 Kudos
191

You can first use this type of transformation to convert xml to better format, and then use another transformation to populate structures.

XSLT


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">

    <member>

      <xsl:apply-templates select="member" />

    </member>

  </xsl:template>

  <xsl:template match="member">

    <xsl:element name="{name}">

      <xsl:value-of select="string" />

    </xsl:element>

  </xsl:template>

</xsl:transform>

ABAP

  1.   CONCATENATE lv_xml '<?xml version="1.0" encoding="UTF-8"?>' INTO lv_xml.
  2.   CONCATENATE lv_xml '<members>' INTO lv_xml.
  3.   CONCATENATE lv_xml '    <member>' INTO lv_xml.
  4.   CONCATENATE lv_xml '        <name>AAA</name>' INTO lv_xml.
  5.   CONCATENATE lv_xml '        <string>Value1</string>' INTO lv_xml.
  6.   CONCATENATE lv_xml '    </member>' INTO lv_xml.
  7.   CONCATENATE lv_xml '    <member>' INTO lv_xml.
  8.   CONCATENATE lv_xml '        <name>BBB</name>' INTO lv_xml.
  9.   CONCATENATE lv_xml '        <string>Value2</string>' INTO lv_xml.
  10.   CONCATENATE lv_xml '    </member>' INTO lv_xml.
  11.   CONCATENATE lv_xml '</members>' INTO lv_xml.
  12.   TRY.
  13.       CALL TRANSFORMATION zmtest
  14.       SOURCE XML lv_xml
  15.       RESULT XML lv_xml.
  16.      
  17.     CATCH cx_root.
  18.   ENDTRY.

//

0 Kudos
191

Continuing previous reply, this xml:


<members>

<member><name>id</name><value><string>1549347</string></value></member>

<member><name>vorname</name><value><string>Albert</string></value></member>

<member><name>nachname</name><value><string>Hofman</string></value></member>

<member><name>email</name><value><string>albert.hofman@kunde.at</string></value></member>

<member><name>status</name><value><string>aktiv</string></value></member>

<member><name>istatus</name><value>1</value></member>

</members>

Gets converted to this:


<member>

<id>1549347</id>

<vorname>Albert</vorname>

<nachname>Hofman</nachname>

<email>albert.hofman@kunde.at</email>

<status>aktiv</status>

<istatus></istatus>

</member>

Using XSLT transformation code:


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">

    <member>

      <xsl:apply-templates select="member" />

    </member>

  </xsl:template>

  <xsl:template match="member">

    <xsl:element name="{name}">

      <xsl:value-of select="value/string" />

    </xsl:element>

  </xsl:template>

</xsl:transform>

//

Former Member
0 Kudos
191

Hi,

we are using SAP-CRM and an external E-Mail broadcasting tool based on web.

You can only communicate via RPC. So I'm preparing a XML and send it to the Server and get back a XML in the above structure (in abap). I want to change this structure and get the values into an abap table.

@Manish Kumar: Do I have to call this Transformation from an abap report, or can I call a transformation in a transformation. When I implement your solution, I get an raise exception at line 04. "Falsches Element element bei XML-ABAP Transformation." --> False element "element" in XML abap transformation.


0 Kudos
191

Hi Florian,

I had run the logic from a report program which demonstrates how during a transformation, key-value node pair can be converted a single node whose name is key and value is value.

You are able to convert <amount>1234</data> to an ABAP structure or variable using existing internet tutorials, using say transformation2.

Before calling this transformation, you can call another transformation, say transformation1 that will change <name>amount</name><value>1234</value> to <amount>1234</amount>.

It is possible to do it using single transformation, but i do not have sufficient expertise in this area.

0 Kudos
191

Hi Manish,

I have a problem that data is not populated to my internal table. Could you please check and help me ?

-----------------------------------------------------------------------------

My ABAP code is below:

-----------------------------------------------------------------------------

GET REFERENCE OF gt_goodsmovement INTO gs_result_xml-value.
gs_result_xml-name = 'IDOC_POSDW'.
APPEND gs_result_xml TO gt_result_xml.


CALL TRANSFORMATION zxslt_goodsmovement
     SOURCE XML gt_itab
     RESULT (gt_result_xml).

-----------------------------------------------------------------------------

My transformation is below:

-----------------------------------------------------------------------------

<xsl:transform version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:sap="http://www.sap.com/sapxsl"
>

<xsl:strip-space elements="*"/>

<xsl:template match="/">

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
       <asx:values>
         <IDOC_POSDW>
           <xsl:apply-templates select="//POSDW"/>
         </IDOC_POSDW>
       </asx:values>
     </asx:abap>

</xsl:template>

<xsl:template match="/POSDW">
   <item>
       <POSDW>
       <xsl:for-each select="TRANSACTION">
       <TRANSACTION>
        <RETAILSTOREID>
           <xsl:value-of select="TRANSACTION/RETAILSTOREID"/>
        </RETAILSTOREID>
        <BUSINESSDAYDATE>
           <xsl:value-of select="TRANSACTION/BUSINESSDAYDATE"/>
        </BUSINESSDAYDATE>
        <TRANSACTIONTYPECODE>
           <xsl:value-of select="TRANSACTION/TRANSACTIONTYPECODE"/>
        </TRANSACTIONTYPECODE>
        <WORKSTATIONID>
           <xsl:value-of select="TRANSACTION/WORKSTATIONID"/>
        </WORKSTATIONID>
        <TRANSACTIONSEQUENCENUMBER>
           <xsl:value-of select="TRANSACTION/TRANSACTIONSEQUENCENUMBER"/>
        </TRANSACTIONSEQUENCENUMBER>
    
        <xsl:for-each select="GOODSMOVEMENT">
        <GOODSMOVEMENT>
       
         <GOODSMOVEMENTSEQUENCENUMBER>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTSEQUENCENUMBER"/>
         </GOODSMOVEMENTSEQUENCENUMBER>
         <GOODSMOVEMENTTYPECODE>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTTYPECODE"/>
         </GOODSMOVEMENTTYPECODE>
         <GOODSMOVEMENTREASONCODE>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTREASONCODE"/>
         </GOODSMOVEMENTREASONCODE>
         <ITEMIDQUALIFIER>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/ITEMIDQUALIFIER"/>
         </ITEMIDQUALIFIER>
         <ITEMID>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/ITEMID"/>
         </ITEMID>
         <UNITCOUNT>
            <xsl:value-of select="TRANSACTION/GOODSMOVEMENT/UNITCOUNT"/>
         </UNITCOUNT>

         </GOODSMOVEMENT>
         </xsl:for-each>
       </TRANSACTION>
     </xsl:for-each>

       </POSDW>
     </item>
   </xsl:template>

</xsl:transform>

-----------------------------------------------------------------------------

Thanks and Regards,

May