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: 

Dynamic XML to Internal Table

Former Member
0 Kudos

Hi,

I can successfully transfer XML data to internal table using CALL TRANSFORMATION, if all XML tag repeats all the time in XML file, but if all XML tag doesn't repeat then how to transfer data in internal table using CALL TRANSFORMATION.

1 ACCEPTED SOLUTION

christian_jianelli
Contributor
0 Kudos

Hi Sunny,

You can use a XSLT transformation instead of ST. With XSLT you don't need to have all tags nor a specific order.

http://wiki.sdn.sap.com/wiki/display/ABAP/XML+XSLT+with+ABAP

Regards,

Christian

4 REPLIES 4

christian_jianelli
Contributor
0 Kudos

Hi Sunny,

You can use a XSLT transformation instead of ST. With XSLT you don't need to have all tags nor a specific order.

http://wiki.sdn.sap.com/wiki/display/ABAP/XML+XSLT+with+ABAP

Regards,

Christian

0 Kudos

Thanks Christian for your reply..

but i couldn't understand much from this..

Here is XML file.

<?xml version="1.0" encoding="UTF-8"?>

<CPS_FRS_INTERFACE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cpsFrsInterface.xsd">

  <FACILITY>

    <TRANSACTION_TYPE>01</TRANSACTION_TYPE>

    <FACILITY_KEY>1</FACILITY_KEY>

    <FACILITY_CODE>00005</FACILITY_CODE>

    <NAME>ST. BONIFACE GENERAL HOSPITAL</NAME>

    <ADDR_UNIT_DESIG_ID>UNIT A</ADDR_UNIT_DESIG_ID>

    <STREET>409 TACHE AVENUE</STREET>

    <CITY>wINNIPEG</CITY>

    <POSTAL_ZIP_CODE>R2H2A6</POSTAL_ZIP_CODE>

    <EFFECTIVE_FROM_DATE>19700101</EFFECTIVE_FROM_DATE>

    <EFFECTIVE_TO_DATE>99991231</EFFECTIVE_TO_DATE>

    <FACILITY_GROUP>H</FACILITY_GROUP>

    <FACILITY_TEACHING_HOSPITAL>H</FACILITY_TEACHING_HOSPITAL>

  </FACILITY>

  <FACILITY>

    <TRANSACTION_TYPE>01</TRANSACTION_TYPE>

    <FACILITY_KEY>1</FACILITY_KEY>

    <FACILITY_CODE>00005</FACILITY_CODE>

    <NAME>ST. BONIFACE GENERAL HOSPITAL</NAME>

    <ADDR_UNIT_DESIG_ID>UNIT A</ADDR_UNIT_DESIG_ID>

    <STREET>409 TACHE AVENUE</STREET>

    <CITY>wINNIPEG</CITY>

    <POSTAL_ZIP_CODE>R2H2A6</POSTAL_ZIP_CODE>

    <EFFECTIVE_FROM_DATE>19700101</EFFECTIVE_FROM_DATE>

    <EFFECTIVE_TO_DATE>99991231</EFFECTIVE_TO_DATE>

    <FACILITY_GROUP>H</FACILITY_GROUP>

  </FACILITY>

</CPS_FRS_INTERFACE>

In last record <FACILITY_TEACHING_HOSPITAL> Tag is missing and Simple transformation can't handle this.

can anyone provide the XSLT transformation for this.

Thanks.

0 Kudos

Hi Sunny,

Here is a sample XSLT for your XML (you just have to inform the other tags).

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

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

  <xsl:template match="CPS_FRS_INTERFACE">

    <asx:abap version="1.0">

      <asx:values>

        <CPS_FRS_INTERFACE>

          <xsl:for-each select="FACILITY">

            <FACILITY>

              <TRANSACTION_TYPE>

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

              </TRANSACTION_TYPE>

              <NAME>

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

              </NAME>

            </FACILITY>

          </xsl:for-each>

        </CPS_FRS_INTERFACE>

      </asx:values>

    </asx:abap>

  </xsl:template>

</xsl:transform>

Regards,

Christian

jeroen_verbrugge2
Active Participant
0 Kudos

Hi,

For optional elements in ST, you can make use of

<tt:cond frq="?"> or

<tt:cond check="not-initial(...)">.

Both will work to parse XML, the difference is with the creation of XML.

The first option will generate an empty element, the second option will not generate the element.

Check out the example program attached.

Kind Regards,

Jeroen