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
912

Hi Experts,

I am having trouble in processing the below XML to ABAP internal table.I just need the value from tag <FORMATTED_VALUE> into internal table.If COLUMN = 0,first column in internal table,if COLUMN = 1, second column in internal table.

Can anyone pls help.

<DATA_CELLS>
- <DATA_CELL column="0" row="0" type="NORMAL">
  <VALUE type="CALENDAR_DAY">20101029</VALUE> 
  <DISPLAY_VALUE type="CALENDAR_DAY">20101029</DISPLAY_VALUE> 
  <FORMATTED_VALUE>29.10.2010</FORMATTED_VALUE> 
  </DATA_CELL>
- <DATA_CELL column="1" row="0" type="NORMAL">
  <VALUE type="CALENDAR_DAY">20101101</VALUE> 
  <DISPLAY_VALUE type="CALENDAR_DAY">20101101</DISPLAY_VALUE> 
  <FORMATTED_VALUE>01.11.2010</FORMATTED_VALUE> 
  </DATA_CELL>
- <DATA_CELL column="2" row="0" type="NORMAL">
  <VALUE type="CALENDAR_DAY">20101029</VALUE> 
  <DISPLAY_VALUE type="CALENDAR_DAY">20101029</DISPLAY_VALUE> 
  <FORMATTED_VALUE>29.10.2010</FORMATTED_VALUE> 
  </DATA_CELL>
- <DATA_CELL column="3" row="0" type="NORMAL">
  <VALUE type="CALENDAR_DAY">20101101</VALUE> 
  <DISPLAY_VALUE type="CALENDAR_DAY">20101101</DISPLAY_VALUE> 
  <FORMATTED_VALUE>01.11.2010</FORMATTED_VALUE> 
  </DATA_CELL>
  </DATA_CELLS>

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
870

Check function module SMUM_XML_PARSE.

Check function module SMUM_XML_PARSE.

6 REPLIES 6
Read only

Former Member
0 Likes
871

Check function module SMUM_XML_PARSE.

Read only

0 Likes
870

sry.. this doesnt work as expected..

Read only

0 Likes
870

Hi,

Try with the below 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="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<RESULT_SET>
<xsl:apply-templates select="//DATA_CELLS"/>
</RESULT_SET>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="DATA_CELLS">
<DISP1>
<xsl:for-each select="DATA_CELL">
<xsl:choose>
<xsl:when test="@column = 0">
<COL_0>
<xsl:value-of select="FORMATTED_VALUE"/>
</COL_0>
</xsl:when>
<xsl:when test="@column = 1">
<COL_1>
<xsl:value-of select="FORMATTED_VALUE"/>
</COL_1>
</xsl:when>
<xsl:when test="@column = 2">
<COL_2>
<xsl:value-of select="FORMATTED_VALUE"/>
</COL_2>
</xsl:when>
<xsl:when test="@column = 3">
<COL_3>
<xsl:value-of select="FORMATTED_VALUE"/>
</COL_3>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</DISP1>
</xsl:template>
</xsl:transform>

Also the definition of the corresponding type in ABAP needs to be like below,


TYPES: BEGIN OF t_data,
         col_0 TYPE char20,
         col_1 TYPE char20,
         col_2 TYPE char20,
         col_3 TYPE char20,
       END OF t_data.

Regards,

Chen

Read only

0 Likes
870

Thanks Chen.that solved my problem.

Read only

Former Member
0 Likes
870

Have a look at the use of the if_ixml* classes along with the cl_xml_document.

Once you get the XML data represented in the class if_ixml_document, you can easily navigate/iterate through the elements using the document object model (if_ixml_node_collection, if_ixml_node_iterator).

Read only

former_member213275
Contributor
0 Likes
870

Hi,

Check this link.

[http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=195726698]

[http://www.sap-press.de/download/dateien/1112/076_leseprobe.pdf]

Srikanth.