Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

XML to ABAP

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>

Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question