on 02-28-2017 7:49 AM
Dear All.
we are trying to convert xml file to ABAP internal table using XSLT_TOOL by referring XML XSLT with ABAP
but we are facing the below issue.
Exception
and we suspect the XSLT code might be wrong, can you please suggest us further .
Input XML
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.002.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrPmtStsRpt>
<GrpHdr>
<MsgId>20120504-PSR/33</MsgId>
<CreDtTm>2012-05-04T22:34:16</CreDtTm>
<InitgPty>
<Id>
<OrgId>
<BICOrBEI>CITIUS33</BICOrBEI>
</OrgId>
</Id>
</InitgPty>
</GrpHdr>
<OrgnlGrpInfAndSts>
<OrgnlMsgId>V3C-4-PVT-Messageid</OrgnlMsgId>
<OrgnlMsgNmId>pain.001.001.03</OrgnlMsgNmId>
<OrgnlCreDtTm>2012-05-04T14:07:01</OrgnlCreDtTm>
<OrgnlNbOfTxs>75</OrgnlNbOfTxs>
<OrgnlCtrlSum>75</OrgnlCtrlSum>
<GrpSts>PART</GrpSts>
<StsRsnInf>
<AddtlInf>ACK - FILE PARTIALLY SUCCESSFUL</AddtlInf>
</StsRsnInf>
</OrgnlGrpInfAndSts>
</CstmrPmtStsRpt>
</Document>
XSLT Code
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:template match="Document">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<XML_OUTPUT>
<xsl:for-each select="CstmrPmtStsRpt">
<CstmrPmtStsRpt>
<HEAD>
<xsl:variable name="head" select="GrpHdr"/>
<MSGID>
<xsl:value-of select="$head/MsgId"/>
</MSGID>
<CREDTTM>
<xsl:value-of select="$head/CreDtTm"/>
</CREDTTM>
</HEAD>
<DETAILS>
<xsl:for-each select="OrgnlGrpInfAndSts">
<xsl:variable name="OrgnlGrpInfAndSts" select="."/>
<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>
<ORGNLNBOFTXS>
<xsl:value-of select="$OrgnlGrpInfAndSts/OrgnlNbOfTxs"/>
</ORGNLNBOFTXS>
<ORGNLCTRLSUM>
<xsl:value-of select="$OrgnlGrpInfAndSts/OrgnlCtrlSum"/>
</ORGNLCTRLSUM>
<GRPSTS>
<xsl:value-of select="$OrgnlGrpInfAndSts/GrpSts"/>
</GRPSTS>
<ADDTLINF>
<xsl:value-of select="$OrgnlGrpInfAndSts/AddtlInf"/>
</ADDTLINF>
</OrgnlGrpInfAndSts>
</xsl:for-each>
</DETAILS>
</CstmrPmtStsRpt>
</xsl:for-each>
</XML_OUTPUT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
ABAP Code:
TYPE-POOLS: ABAP, IXML.
TYPES: BEGIN OF T_AP_HEAD,
MSGID(20),
CREDTTM(10),
END OF T_AP_HEAD.
TYPES: BEGIN OF T_AP_DETAILS,
* inv_detail TYPE t_ap_detail,
CREDTTM TYPE ZCREDTTM,
BICORBEI TYPE ZBICORBEI,
ORGNLMSGID TYPE ZORGNLMSGID,
ORGNLMSGNMID TYPE ZORGNLMSGNMID,
ORGNLCREDTTM TYPE ZORGNLCREDTTM,
ORGNLNBOFTXS TYPE ZORGNLNBOFTXS,
ORGNLCTRLSUM TYPE ZORGNLCTRLSUM,
GRPSTS TYPE ZGRPSTS,
ADDTLINF TYPE ZADDTLINF,
END OF T_AP_DETAILS.
TYPES: BEGIN OF T_AP,
HEAD TYPE T_AP_HEAD,
DETAILS TYPE T_AP_DETAILS,
END OF T_AP.
DATA: XSLT_ERR TYPE REF TO CX_XSLT_EXCEPTION,
ERR_STRING TYPE STRING.
PARAMETERS: PA_FILE TYPE STRING DEFAULT 'C:\DB\demo_xslt.xml'.
DATA: GT_ITAB TYPE STANDARD TABLE OF CHAR2048.
DATA: IT_AIRPLUS TYPE STANDARD TABLE OF T_AP,
WA_AIRPLUS TYPE T_AP.
DATA: GT_RESULT_XML TYPE ABAP_TRANS_RESBIND_TAB,
GS_RESULT_XML TYPE ABAP_TRANS_RESBIND.
START-OF-SELECTION.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = PA_FILE
CHANGING
DATA_TAB = GT_ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
OTHERS = 19.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GET REFERENCE OF IT_AIRPLUS INTO GS_RESULT_XML-VALUE.
GS_RESULT_XML-NAME = 'CstmrPmtStsRpt'.
APPEND GS_RESULT_XML TO GT_RESULT_XML.
TRY.
CALL TRANSFORMATION ZINV_XSLT_EX "ZTEST0001
SOURCE XML GT_ITAB "l_xml_x1
RESULT (GT_RESULT_XML)." = IT_AIRPLUS "(GT_RESULT_XML)
.
* catch any error, very helpful if the XSLT isn't correct
CATCH CX_XSLT_EXCEPTION INTO XSLT_ERR.
ERR_STRING = XSLT_ERR->GET_TEXT( ).
WRITE: / 'Transformation error: ', ERR_STRING.
EXIT.
ENDTRY.
* SETTING A BREAKPOINT TO WATCH THE WORKAREA
* by the internal table "it_airplus"
BREAK-POINT.
LOOP AT IT_AIRPLUS INTO WA_AIRPLUS.
ENDLOOP.
The structure defined in the transformation and the structure of the XML file do not match.
Your XML file contains
<CstmrPmtStsRpt>
while the transformation expects
<asx:abap>
<asx:values>
<XML_OUTPUT>
<CstmrPmtStsRpt>
Inside of CstmrPmtStsRpt the transformation expects a separation into <HEAD> and <DETAILS>. Your XML file is using <GrpHdr> instead of <HEAD> and it has no additional tag for the details section at all (instead it directly starts with <OrgnlGrpInfAndSts>).
I think there are further mismatches besides the mentioned two.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.