Skip to Content
0

XML file conversion through XSLT convertor into ABAP internal table through program

Mar 02, 2017 at 03:06 PM

246

avatar image
Former Member

We have developed the program where we are able to convert the XML file through XSLT converter into our internal table but we are facing the issue in fetching the data from XML file on the occasion of repeated XML tags. Please find the technical details on the issue. I am also uploading the XSLT file mapping, XML file and program for your reference. Please let me know how can we fetch the repeated XML tags into my internal table through program.

XSLT FILE MAPPING:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <CSTMRPMTSTSRPT_GET>
          <xsl:apply-templates select="//CSTMRPMTSTSRPT"/>
        </CSTMRPMTSTSRPT_GET>
      </asx:values>
    </asx:abap>
  </xsl:template>
  <xsl:template match="CSTMRPMTSTSRPT">
    <ITEM>
      <CSTMRPMTSTSRPT>
        <GRPHDR>
          <MSGID>
            <xsl:value-of select="GRPHDR/MSGID"/>
          </MSGID>
          <CREDTTM>
            <xsl:value-of select="GRPHDR/CREDTTM"/>
          </CREDTTM>
        </GRPHDR>
        <ORGNLGRPINFANDSTS>
          <ORGNLMSGID>
            <xsl:value-of select="ORGNLGRPINFANDSTS/ORGNLMSGID"/>
          </ORGNLMSGID>
          <ORGNLMSGNMID>
            <xsl:value-of select="ORGNLGRPINFANDSTS/ORGNLMSGNMID"/>
          </ORGNLMSGNMID>
          <ORGNLCREDTTM>
            <xsl:value-of select="ORGNLGRPINFANDSTS/ORGNLCREDTTM"/>
          </ORGNLCREDTTM>
        </ORGNLGRPINFANDSTS>
        <xsl:for-each select="ORGNLPMTINFANDSTS">
          <ORGNLPMTINFANDSTS>
            <ORGNLPMTINFID>
              <xsl:value-of select="ORGNLPMTINFID"/>
            </ORGNLPMTINFID>
            <TXINFANDSTS>
              <ORGNLENDTOENDID>
                <xsl:value-of select="TXINFANDSTS/ORGNLENDTOENDID"/>
              </ORGNLENDTOENDID>
              <TXSTS>
                <xsl:value-of select="TXINFANDSTS/TXSTS"/>
              </TXSTS>
              <STSRSNINF>
                <ORGTR>
                  <NM>
                    <xsl:value-of select="TXINFANDSTS/STSRSNINF/ORGTR/NM"/>
                  </NM>
                </ORGTR>
                <RSN>
                  <CD>
                    <xsl:value-of select="TXINFANDSTS/STSRSNINF/RSN/CD"/>
                  </CD>
                </RSN>
                <ADDTLINF>
                  <xsl:value-of select="TXINFANDSTS/STSRSNINF/ADDTLINF"/>
                </ADDTLINF>
              </STSRSNINF>
              <ORGNLTXREF>
                <AMT>
                  <INSTDAMT>
                    <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/AMT/INSTDAMT"/>
                  </INSTDAMT>
                </AMT>
                <REQDEXCTNDT>
                  <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/REQDEXCTNDT"/>
                </REQDEXCTNDT>
                <PMTTPINF>
                  <SVCLVL>
                    <CD>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/PMTTPINF/SVCLVL/CD"/>
                    </CD>
                  </SVCLVL>
                  <LCLINSTRM>
                    <PRTRY>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/PMTTPINF/LCLINSTRM/PRTRY"/>
                    </PRTRY>
                  </LCLINSTRM>
                </PMTTPINF>
                <PMTMTD>
                  <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/PMTMTD"/>
                </PMTMTD>
                <RMTINF>
                  <USTRD>
                    <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/RMTINF/USTRD"/>
                  </USTRD>
                </RMTINF>
                <DBTR>
                  <NM>
                    <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTR/NM"/>
                  </NM>
                  <PSTLADR>
                    <CTRY>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTR/PSTLADR/CTRY"/>
                    </CTRY>
                    <ADRLINE>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTR/PSTLADR/ADRLINE"/>
                    </ADRLINE>
                  </PSTLADR>
                </DBTR>
                <DBTRACCT>
                  <ID>
                    <OTHR>
                      <ID>
                        <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTRACCT/ID/OTHR/ID"/>
                      </ID>
                    </OTHR>
                  </ID>
                  <TP>
                    <PRTRY>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTRACCT/TP/PRTRY"/>
                    </PRTRY>
                  </TP>
                </DBTRACCT>
                <DBTRAGT>
                  <FININSTNID>
                    <BIC>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTRAGT/FININSTNID/BIC"/>
                    </BIC>
                    <PSTLADR>
                      <CTRY>
                        <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTRAGT/FININSTNID/PSTLADR/CTRY"/>
                      </CTRY>
                    </PSTLADR>
                  </FININSTNID>
                  <BRNCHID>
                    <ID>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/DBTRAGT/BRNCHID/ID"/>
                    </ID>
                  </BRNCHID>
                </DBTRAGT>
                <CDTRAGT>
                  <FININSTNID>
                    <BIC>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/CDTRAGT/FININSTNID/BIC"/>
                    </BIC>
                    <CLRSYSMMBID>
                      <MMBID>
                        <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/CDTRAGT/FININSTNID/CLRSYSMMBID/MMBID"/>
                      </MMBID>
                    </CLRSYSMMBID>
                  </FININSTNID>
                </CDTRAGT>
                <CDTR>
                  <NM>
                    <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/CDTR/NM"/>
                  </NM>
                </CDTR>
                <CDTRACCT>
                  <ID>
                    <IBAN>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/CDTRACCT/ID/IBAN"/>
                    </IBAN>
                  </ID>
                  <TP>
                    <PRTRY>
                      <xsl:value-of select="TXINFANDSTS/ORGNLTXREF/CDTRACCT/TP/PRTRY"/>
                    </PRTRY>
                  </TP>
                </CDTRACCT>
              </ORGNLTXREF>
            </TXINFANDSTS>
          </ORGNLPMTINFANDSTS>
        </xsl:for-each>
      </CSTMRPMTSTSRPT>
    </ITEM>
  </xsl:template>
</xsl:transform>

SAMPLE XML FILE:

<?xml version="1.0" encoding="utf-8"?>
  <CSTMRPMTSTSRPT>
    <GRPHDR>
      <MSGID>20120423-PSR/35</MSGID>
      <CREDTTM>2012-04-23T04:23:01</CREDTTM>
      <INITGPTY>
        <ID>
          <ORGID>
            <BICORBEI>MMBDUS33</BICORBEI>
          </ORGID>
        </ID>
      </INITGPTY>
    </GRPHDR>
    <ORGNLGRPINFANDSTS>
      <ORGNLMSGID>9999977022</ORGNLMSGID>
      <ORGNLMSGNMID>PAIN.001.001.03</ORGNLMSGNMID>
      <ORGNLCREDTTM>2012-04-23T10:10:28</ORGNLCREDTTM>
    </ORGNLGRPINFANDSTS>
    <ORGNLPMTINFANDSTS>
      <ORGNLPMTINFID>9999977022</ORGNLPMTINFID>
      <TXINFANDSTS>
        <ORGNLENDTOENDID>999900007312</ORGNLENDTOENDID>
        <TXSTS>ACSP</TXSTS>
        <STSRSNINF>
          <ORGTR>
            <NM>DIRECT</NM>
          </ORGTR>
          <RSN>
            <CD>NARR</CD>
          </RSN>
          <ADDTLINF>/00000000/CB ACCEPTED</ADDTLINF>
        </STSRSNINF>
        <ORGNLTXREF>
          <AMT>
            <INSTDAMT CCY="BGN">1.01</INSTDAMT>
          </AMT>
          <REQDEXCTNDT>2012-04-23</REQDEXCTNDT>
          <PMTTPINF>
            <SVCLVL>
              <CD>NURG</CD>
            </SVCLVL>
            <LCLINSTRM>
              <PRTRY>555</PRTRY>
            </LCLINSTRM>
          </PMTTPINF>
          <PMTMTD>TRF</PMTMTD>
          <RMTINF>
            <USTRD>9999951847</USTRD>
          </RMTINF>
          <DBTR>
            <NM>TEST DEBTOR NAME</NM>
            <PSTLADR>
              <CTRY>BG</CTRY>
              <ADRLINE>ADDRESS LINE1</ADRLINE>
            </PSTLADR>
          </DBTR>
          <DBTRACCT>
            <ID>
              <OTHR>
                <ID>9999999999</ID>
              </OTHR>
            </ID>
            <TP>
              <PRTRY>CACC</PRTRY>
            </TP>
          </DBTRACCT>
          <DBTRAGT>
            <FININSTNID>
              <BIC>USDABGSF</BIC>
              <PSTLADR>
                <CTRY>BG</CTRY>
              </PSTLADR>
            </FININSTNID>
            <BRNCHID>
              <ID>888</ID>
            </BRNCHID>
          </DBTRAGT>
          <CDTRAGT>
            <FININSTNID>
              <BIC>WEBKBGSF</BIC>
              <CLRSYSMMBID>
                <MMBID>WEBK9999</MMBID>
              </CLRSYSMMBID>
            </FININSTNID>
          </CDTRAGT>
          <CDTR>
            <NM>CREDITOR NAME</NM>
          </CDTR>
          <CDTRACCT>
            <ID>
              <IBAN>BG16999999999999</IBAN>
            </ID>
            <TP>
              <PRTRY>CACC</PRTRY>
            </TP>
          </CDTRACCT>
        </ORGNLTXREF>
      </TXINFANDSTS>
    </ORGNLPMTINFANDSTS>
    <ORGNLPMTINFANDSTS>
      <ORGNLPMTINFID>9999977022</ORGNLPMTINFID>
      <TXINFANDSTS>
        <ORGNLENDTOENDID>99990000007012</ORGNLENDTOENDID>
        <TXSTS>ACSP</TXSTS>
        <STSRSNINF>
          <ORGTR>
            <NM>DIRECT</NM>
          </ORGTR>
          <RSN>
            <CD>NARR</CD>
          </RSN>
          <ADDTLINF>/00000000/CB ACCEPTED</ADDTLINF>
        </STSRSNINF>
        <ORGNLTXREF>
          <AMT>
            <INSTDAMT CCY="BGN">1.77</INSTDAMT>
          </AMT>
          <REQDEXCTNDT>2012-04-23</REQDEXCTNDT>
          <PMTTPINF>
            <SVCLVL>
              <CD>NURG</CD>
            </SVCLVL>
            <LCLINSTRM>
              <PRTRY>555</PRTRY>
            </LCLINSTRM>
          </PMTTPINF>
          <PMTMTD>TRF</PMTMTD>
          <RMTINF>
            <USTRD>99999313299</USTRD>
          </RMTINF>
          <DBTR>
            <NM>DEBTOR NAME</NM>
            <PSTLADR>
              <CTRY>BG</CTRY>
              <ADRLINE>ADDRESSLINE 1</ADRLINE>
            </PSTLADR>
          </DBTR>
          <DBTRACCT>
            <ID>
              <OTHR>
                <ID>BG88888999999999999</ID>
              </OTHR>
            </ID>
            <TP>
              <PRTRY>CACC</PRTRY>
            </TP>
          </DBTRACCT>
          <DBTRAGT>
            <FININSTNID>
              <BIC>USDABGSF</BIC>
              <PSTLADR>
                <CTRY>BG</CTRY>
              </PSTLADR>
            </FININSTNID>
            <BRNCHID>
              <ID>888</ID>
            </BRNCHID>
          </DBTRAGT>
          <CDTRAGT>
            <FININSTNID>
              <BIC>USDABGSF</BIC>
              <CLRSYSMMBID>
                <MMBID>XXXX9999</MMBID>
              </CLRSYSMMBID>
            </FININSTNID>
          </CDTRAGT>
          <CDTR>
            <NM>CREDITOR NAME</NM>
          </CDTR>
          <CDTRACCT>
            <ID>
              <IBAN>BG888889999999999999</IBAN>
            </ID>
            <TP>
              <PRTRY>CACC</PRTRY>
            </TP>
          </CDTRACCT>
        </ORGNLTXREF>
      </TXINFANDSTS>
    </ORGNLPMTINFANDSTS>
      </CSTMRPMTSTSRPT>

PROGRAM that was developed to convert the same:

TYPE-POOLS: ABAP, IXML.
TYPES: BEGIN OF TP_PRTY,
       PRTRY(5),
       END OF TP_PRTY,
       BEGIN OF ID_IBAN,
         IBAN(25),
       END OF ID_IBAN,
       BEGIN OF CDTRACCT,     "cdtracct
         ID TYPE ID_IBAN,
         TP TYPE TP_PRTY,
       END OF  CDTRACCT,
       BEGIN OF CLRSYSMMBID,
         MMBID(10),
       END OF CLRSYSMMBID,
      BEGIN OF FININSTNID,
         BIC(10),
       END OF FININSTNID,
       BEGIN OF CDTRAGT,
         FININSTNID TYPE FININSTNID,     "cdtragt
         CLRSYSMMBID TYPE CLRSYSMMBID,
       END OF CDTRAGT,
       BEGIN OF PSTLADR,
        CTRY(4),
       END OF PSTLADR,
       BEGIN OF BRNCHID,
         ID(5),
       END OF  BRNCHID,
       BEGIN OF DBTRAGT,                "dbtragt
         FININSTNID TYPE FININSTNID,
         PSTLADR TYPE PSTLADR,
         BRNCHID TYPE BRNCHID,
        END OF  DBTRAGT,
      BEGIN OF OTHER,
        ID(15),
     END OF  OTHER,
       BEGIN OF DBTRACCT,         "dbtragt
         ID TYPE OTHER,
         TP TYPE TP_PRTY,
       END OF DBTRACCT,
       BEGIN OF DBTR,            "dbtr
         NM(40),
         PSTLADR TYPE PSTLADR,
      END OF  DBTR,
      BEGIN OF RMTINF,
        USTRD(20),
      END OF  RMTINF,
      BEGIN OF SVCLVL,
        CD(5),
      END OF SVCLVL,
      BEGIN OF LCLINSTRM,
        PRTRY(5),
      END OF LCLINSTRM,
     BEGIN OF PMTTPINF,
        SVCLVL TYPE SVCLVL,
        LCLINSTRM TYPE LCLINSTRM,
      END OF   PMTTPINF,
      BEGIN OF AMT,
        INSTDAMT(20),
      END OF AMT,
      BEGIN OF CDTR,
        NM(35),
      END OF  CDTR.

TYPES: BEGIN OF ORGNLTXREF,
       AMT TYPE AMT,
       REQDEXCTNDT(12),
       PMTTPINF TYPE PMTTPINF,
       PMTMTD(5),
       RMTINF TYPE  RMTINF,
       DBTR TYPE DBTR,
*       DBTRACCT TYPE DBTRACCT,
       DBTRACCT TYPE DBTRACCT,
       DBTRAGT TYPE DBTRAGT,
       CDTRAGT TYPE CDTRAGT,
      CDTR TYPE CDTR,
       CDTRACCT TYPE CDTRACCT,
      END OF ORGNLTXREF.
TYPES: BEGIN OF ORGTR,
       NM(10),
       END OF ORGTR,
       BEGIN OF RNS,
       CD(5),
       END OF RNS,
       BEGIN OF STSRNSINF,
       ORGTR TYPE ORGTR,
      RNS TYPE RNS,
       ADDTINF(50),
       END OF STSRNSINF.
TYPES: BEGIN OF TXINFANDSTS,
       ORGNLENDTOENDID(15),
       TXSTS(5),
       STSRNSINF TYPE STSRNSINF,
       ORGNLTXREF TYPE ORGNLTXREF,
      END OF TXINFANDSTS.
TYPES: BEGIN OF ORGNLPMTINFANDSTS,
       ORGNLPMTINFID(15),
       TXINFANDSTS TYPE TXINFANDSTS,
       END OF ORGNLPMTINFANDSTS.
TYPES: BEGIN OF ORGNLGRPINFANDSTS,
      ORGNLMSGID(15),
       ORGNLMSGNMID(20),
       ORGNLCREDTTM(20),
       END OF  ORGNLGRPINFANDSTS.
TYPES: BEGIN OF GRPHDR,
       MSGID(20),
       CREDTTM(20),
       END OF GRPHDR.
TYPES: BEGIN OF CSTMRPMTSTSRPT,
       GRPHDR TYPE GRPHDR,
       ORGNLGRPINFANDSTS TYPE ORGNLGRPINFANDSTS,
*       ORGNLPMTINFANDSTS type STANDARD TABLE OF ORGNLPMTINFANDSTS WITH NON-UNIQUE DEFAULT KEY,
        ORGNLPMTINFANDSTS type ORGNLPMTINFANDSTS,
       END OF CSTMRPMTSTSRPT.
TYPES: BEGIN OF TY_FINAL,
       CSTMRPMTSTSRPT TYPE CSTMRPMTSTSRPT,
       END OF TY_FINAL.
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,   "CSTMRPMTSTSRPT,
     WA_FINAL TYPE          TY_FINAL.
.............................................
GET REFERENCE OF IT_FINAL INTO GS_RESULT_XML-VALUE.
GS_RESULT_XML-NAME = 'CSTMRPMTSTSRPT_GET'.
APPEND GS_RESULT_XML TO GT_RESULT_XML.
* Perform the XSLT stylesheet
TRY.
    CALL TRANSFORMATION Z_XSLT_FINAL
    SOURCE XML GT_ITAB
    RESULT (GT_RESULT_XML).
  CATCH CX_ROOT INTO GS_RIF_EX.
    GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).
    MESSAGE GS_VAR_TEXT TYPE 'E'.
ENDTRY.

Error screen shot:

The highlighted structure holds only first value item, But it should be repeat another value items. We are not able to capture the rest of other repeated tags

Thanks

capture.png (11.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Sandra Rossi Mar 02, 2017 at 07:39 PM
0

If I'm not wrong, you should use in your abap:

ORGNLPMTINFANDSTS type standard table of ORGNLPMTINFANDSTS WITH NON-UNIQUE DEFAULT KEY,

and in your XSLT:

<ORGNLPMTINFANDSTS>
  <xsl:for-each select="ORGNLPMTINFANDSTS">
    <item>
      <ORGNLPMTINFID>
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanx for your valuable reply, now data is coming in internal table. I was confused with XSLT code.

Thank you.

0
avatar image
Former Member Mar 03, 2017 at 08:04 AM
0

Dear Sandra,

Thanx for your valuable reply, now data is coming in internal table. I was confused with XSLT code.

Thank you.

Share
10 |10000 characters needed characters left characters exceeded