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 and ABAP Transformation Deep Structure

Former Member
0 Kudos
467

Hello Everyone,

While I've read the forums and the links of a number of folks doing the same thing. I am stuck in that I cannot figure out how to populate a deep structure via XSLT. Not sure what is going wrong, but I suspect it is obvious. The simple problem is that my structure is not getting populated. It is blank. The transformation works in testing STRANS (and in Stylus Studio).

I cannot figure out what is wrong that makes the t_pexr2002 table blank. Thanks for any insight.

Greg

The simple program is:

TYPES: BEGIN OF ty_head,
          sndprn TYPE string,
          bgmref TYPE string,
          moabetrh TYPE string,
          create_date TYPE string,
          settlement_date TYPE string,
          no_lines TYPE string,
       END OF ty_head.

TYPES: BEGIN OF ty_pricing,
        moabetr TYPE string,
       END OF ty_pricing.

TYPES: BEGIN OF ty_item,
          docname TYPE string,
          docnummr TYPE string,
          pricing TYPE ty_pricing,
        END OF ty_item.

TYPES: BEGIN OF ty_summary,
          status_message TYPE string,
       END OF ty_summary.

TYPES: BEGIN OF ty_mn,
        header_data  TYPE ty_head,
        item_data    TYPE ty_item,
        summary_data TYPE ty_summary,
       END OF ty_mn.

DATA: t_pexr2002 TYPE STANDARD TABLE OF ty_mn.

DATA: xml_doc TYPE REF TO cl_xml_document, xml TYPE string.

CREATE OBJECT xml_doc.

CALL METHOD xml_doc->import_from_file
  EXPORTING
    filename = 'C:\temp\2640273.xml'.

CALL METHOD xml_doc->render_2_string
  EXPORTING
    pretty_print = 'X'
  IMPORTING
    stream       = xml.

CALL TRANSFORMATION zusl_pexr2002_v1
SOURCE XML xml
RESULT output = t_pexr2002.

Edited by: Thomas Zloch on Jun 9, 2010 6:05 PM

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos
76

Please embed structured code or file contents in code tags for better readability.

Thomas

As for the actual problem, I'm not an XSLT expert, but your data declaration might be wrong, I'd try:

TYPES: BEGIN OF ty_mn,
        header_data  TYPE ty_head,
        item_data    TYPE TABLE OF ty_item,
        summary_data TYPE TABLE OF ty_summary,
       END OF ty_mn.

as a start.

Thomas

6 REPLIES 6

Former Member
0 Kudos
76

Here is my XSLT:

Here is the transformation: Also pretty simple...

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ... >

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

  <xsl:template match="/PEXR2002/IDOC">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <OUTPUT>
            <HEADER_DATA>
              <SNDPRN>
                <xsl:value-of select="EDI_DC40/SNDPRN"/>
              </SNDPRN>
              <BGMREF>
                <xsl:value-of select="E1IDKU1/BGMREF"/>
              </BGMREF>
              <MOABETRH>
                <xsl:value-of select="E1IDKU5/MOABETR"/>
              </MOABETRH>
              <CREATE_DATE>
                <xsl:value-of select="EDI_DC40/CREDAT"/>
              </CREATE_DATE>
              <SETTLEMENT_DATE>
                <xsl:value-of select="E1EDK03/DATUM"/>
              </SETTLEMENT_DATE>
              <NO_LINES>
                <xsl:value-of select="count(E1IDPU1)"/>
              </NO_LINES>
            </HEADER_DATA>
            <ITEM_DATA>
              <xsl:for-each select="E1IDPU1">
                <DOCNAME>
                  <xsl:value-of select="DOCNAME"/>
                </DOCNAME>
                <DOCNUMMR>
                  <xsl:value-of select="DOCNUMMR"/>
                </DOCNUMMR>
                <PRICING_DATA>
                  <xsl:for-each select="E1IDPU5[MOAQUAL = '006']">
                    <MOABETR>
                      <xsl:value-of select="MOABETR"/>
                    </MOABETR>
                  </xsl:for-each>
                </PRICING_DATA>
              </xsl:for-each>
            </ITEM_DATA>
            <SUMMARY_DATA>
              <xsl:for-each select="EDI_DS40">
                <STATUS_MESSAGE>
                  <xsl:value-of select="STAPA1"/>
                </STATUS_MESSAGE>
              </xsl:for-each>
            </SUMMARY_DATA>
        </OUTPUT>
      </asx:values>
    </asx:abap>
  </xsl:template>
</xsl:transform>

Edited by: Thomas Zloch on Jun 9, 2010 6:05 PM

Former Member
0 Kudos
76

Finally...the XML itself...just a PEXR2002 IDoc.

<?xml version="1.0"?>
<PEXR2002>
	<IDOC BEGIN="1">
		<EDI_DC40 SEGMENT="1">
			<TABNAM><![CDATA[EDI_DC40
			300
			0000000002640273
			640
			51
			2
			
			PEXR2002
			REMADV
			820
			X
			004010
			SAPPRD
			KU
			0000018645
			SAPPRD
			LS
			SAPPRD
			20100101
			050057
			000010110
			000000692
			000008515
		

			REM
			60127195
		
		
			017
			20100105
			000000
		

			INV
			90896629
			20091027
			
				006
				4090.72
				USD
			
			
				004
				4174.2
				USD
			
			
				003
				83.48
				USD
			
		
		
			INV
			90897520
			20091028
			
				006
				2727.15
				USD
			
			
				004
				2782.8
				USD
			
			
				003
				55.65
				USD
			
		
		
			300
			0000000002640273
			20100101
			050057
			50
			000
			EDI_MGR
			000000
		
	
"]]>

Edited by: Greg Foss on Jun 9, 2010 6:01 PM

Edited by: Thomas Zloch on Jun 9, 2010 6:08 PM

ThomasZloch
Active Contributor
0 Kudos
77

Please embed structured code or file contents in code tags for better readability.

Thomas

As for the actual problem, I'm not an XSLT expert, but your data declaration might be wrong, I'd try:

TYPES: BEGIN OF ty_mn,
        header_data  TYPE ty_head,
        item_data    TYPE TABLE OF ty_item,
        summary_data TYPE TABLE OF ty_summary,
       END OF ty_mn.

as a start.

Thomas

0 Kudos
76

Hey Thomas...thanks for fixing the layout of my code. I tried the tags but must have done it wrong.

As for the 'Type Table Of' within a Types...I get the error that "You cannot use Generic type definitions within structures". So, I tried to make standard table types (SE11) out of my definitions above and then use them...but the result was exactly the same.

I also tried the following type definition changes...but they too did not work.

TYPES: BEGIN OF ty_head,
          sndprn TYPE string,
          bgmref TYPE string,
          moabetrh TYPE string,
          create_date TYPE string,
          settlement_date TYPE string,
          no_lines TYPE string,
       END OF ty_head.

TYPES: BEGIN OF ty_pricing,
        moabetr TYPE string,
       END OF ty_pricing.

TYPES: ty_pricing1 TYPE STANDARD TABLE OF ty_pricing
          WITH NON-UNIQUE KEY moabetr.

TYPES: BEGIN OF ty_item,
          docname TYPE string,
          docnummr TYPE string,
          price TYPE ty_pricing1,
        END OF ty_item.

TYPES: BEGIN OF ty_summary,
          status_message TYPE string,
       END OF ty_summary.

TYPES: ty_item1 TYPE STANDARD TABLE OF ty_item
          WITH NON-UNIQUE KEY docname,
       ty_summary1 TYPE STANDARD TABLE OF ty_summary
          WITH NON-UNIQUE KEY status_message.

TYPES: BEGIN OF ty_mn,
        head  TYPE ty_head,
        item  TYPE ty_item1,
        summ  TYPE ty_summary1,
       END OF ty_mn.

TYPES: BEGIN OF ty_pos,
         item TYPE ty_item,
       END OF ty_pos.

DATA: t_pexr2002 TYPE STANDARD TABLE OF ty_mn.

Thanks for the try.

Greg

Edited by: Greg Foss on Jun 9, 2010 10:43 PM

0 Kudos
76

So Thomas was correct about the data definitions as were you about the syntax error(s). Your transformation isn't quite set up correctly to render the records in the table though. I took some of your code and stripped out the pricing reference just to show you the table appending for the items; the pricing will follow similarly in another nested level. First off, you'll want to declare something like this in your program:


DATA: BEGIN OF ls_mn,
         header_data  TYPE ty_head,
         item_data    TYPE ztt_item,   "<<-- this just has your two item
                                     " fields in a DDIC table type on my side
         summary_data TYPE ty_summary,
       END OF ls_mn.

DATA: pexr2002 LIKE ls_mn.  "<<-- this is not a table but a deep structure

And then in your XSLT program, you need a line definition:


          <ITEM_DATA>
            <xsl:for-each select="E1IDPU1">
              <ITEM_DATA_LINE>
                <DOCNAME>
                  <xsl:value-of select="DOCNAME"/>
                </DOCNAME>
                <DOCNUMMR>
                  <xsl:value-of select="DOCNUMMR"/>
                </DOCNUMMR>
              </ITEM_DATA_LINE>
            </xsl:for-each>
          </ITEM_DATA>

Edited by: Rob Burbank on Jun 9, 2010 5:01 PM

0 Kudos
76

Greg, be careful with your 1:N and 1:1 relationships between your ABAP types and XSLT source, there were many errors (solved by Thomas and Brad). Greg, I advise you to read the [ABAP documentation - asXML Canonical representation|http://help.sap.com/abapdocu_70/en/ABENABAP_XSLT_ASXML.htm]

Just one comment, it is possible to use this simplified code:


TYPES: BEGIN OF ty_mn,
        header_data  TYPE ty_head,
        item_data    TYPE TABLE OF ty_item WITH DEFAULT KEY,
        summary_data TYPE TABLE OF ty_summary WITH DEFAULT KEY,
       END OF ty_mn.