Skip to Content
author's profile photo Former Member
Former Member

Reading XML Data from ABAP Program?

Hi,

How do I read XML Data from an ABAP Program? For example if I have the below basic XML Code-

<xml>

<Name> Thiru </Name>

<Age> 24 </Age>

<City> chennai </Chennai>

</xml>

How do i read the data within the Name,Age, and City tags into variables in the ABAP Program?

Regards,

Thiru

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 09:51 AM

    if you decide to do in XSLT, I have a sample list here:

    XML file like this:
    <?xml version="1.0" encoding="UTF-16"?>
    <F>
    <P1>
    <t_1>value1</t_1>
    <t_2>testvalue</t_2>
    </P1>
    <P2>
    </P2>
    </F>
    
    XSLT file like this:
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sapxsl="http://www.sap.com/sapxsl" version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:template match="F">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
    <<b>DOCUMENT</b>>
    <xsl:apply-templates/>
    </<b>DOCUMENT</b>>
    </asx:values>
    </asx:abap>
    </xsl:template>
    <xsl:template match="P1">
    <ENTRY>
    <<b>T_1</b>><xsl:value-of select="t_1"/></T_1>
    <<b>T_2</b>><xsl:value-of select="t_2"/></T_2>
    </ENTRY>
    </xsl:template>
    </xsl:transform>
    
    ABAP program like this:
    DATA: BEGIN OF wa_upload,
    text(255) TYPE c,
    END OF wa_upload,
    itab_upload LIKE TABLE OF wa_upload,
    BEGIN OF wa_document,
    t_1 TYPE string,
    t_2 TYPE string,
    END OF wa_document,
    itab_document LIKE TABLE OF wa_document.
    
    
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = 'XXXXX'
    filetype = 'ASC'
    TABLES
    data_tab = itab_upload.
    
    CALL TRANSFORMATION zrappel_xml_test
    SOURCE XML itab_upload
    RESULT <b>document</b> = itab_document.
    

    You should pay attention to the bold words.

    hope it will be helpful

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 06:49 AM

    Hi,

    Check this link,

    http://www.sap-img.com/abap/xml-file-to-word-document-through-sap.htm>

    Hope it helps u.

    Thanks&Regards,

    Ruthra.R

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 03, 2005 at 07:08 AM

    You need to write a XSLT program to convert this XML into a variable/itab.

    and then use the XSLT program along with

    CALL TRANSFORMATION to do the actual conversion.

    CALL TRANSFORMATION (`<z_myxslt_program`)

    SOURCE XML <source xml>

    RESULT itab = itab[].

    search ABAP forum with key word CALL TRANSFORMATION and you will see quiet a few examples with code.

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 07:11 AM

    hi, there is two way for you choose, DOM or XSLT.

    for DOM , you can read this link for reference:

    http://help.sap.com/saphelp_nw04/helpdata/en/86/8280ba12d511d5991b00508b6b8b11/frameset.htm

    for XSLT, it only supported on 4.7 or above, here is a topic on how to read XML into ABAP with XSLT:

    xml---abap

    hope it will be helpful

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 08:49 AM

    Hi durai,

    I am able to read the code into an internal table but how do i specify the tag and get the data within the specific tag?

    I suppose call transformation is used for seriazliation right? How do i deserialize?

    Regards,

    Thiru

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 09:29 AM

    Take a look at the cl_xml_document this has a method called GET_DATA which fills a datastructure out of your XML file.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 09:58 AM

    'but how do i specify the tag and get the data within the specific tag'

    You should do it in the XSLT file.

    XSLT has <if ...> and you can define variable in XSLT.

    you can search some material of XSLT, if you only need to specify a tag, and get the value of this tag, do like this:

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

    XXX is a path of XSLT, hope you are familiar with XPATH.

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.