Search code examples
xmlxml-parsingtransformationabapabap-st

need help parsing XML that contains namespace into ABAP internal table


I am trying to convert this XML file into ABAP internal table where the root tag <CBISDDStsRptLogMsg.... \> contains namespace and my Simple Transformation is dumping an exception without much clear information.

Here is the screenshot of the exception CX_ST_MATCH_ELEMENT.

exception cx_st match_element

My objective is to get the values from the Rsn and AddtlInf tags below:

    <TxInfAndSts> <----NOTE: this is repetitive
         <StsRsnInf>
         <Rsn>
            <CD>ABC</CD>
         </Rsn>
         <AddtlInf>XYZ</AddtlInf>

Here is the snippet of the XML provided by the client:

 <?xml version="1.0" encoding="utf-8" standalone="no"?>
<CBISDDStsRptLogMsg xmlns="urn:CBI:xsd:CBISDDStsRptLogMsg.00.01.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <GrpHdr>
        <MsgId>.....</MsgID>
    </GrpHdr>
    <OrgnlGrpInfAndSts>
        ...

                 ...
    </OrgnlGrpInfAndSts>
    <OrgnlPmtInfAndSts>
        <OrgnlPmtInfId>...</OrgnlPmtInfId>
        <TxInfAndSts>
            <OrgnlInstrId>.....</OrgnlInstrId>
            <OrgnlEndToEndId>.....</OrgnlEndToEndId>
            <TxSts>.....</TxSts>
            <StsRsnInf>
                <Orgtr>
                    <Nm>.....</Nm>
                </Orgtr>
                <Rsn>
                    <Cd>ABC</Cd>
                </Rsn>
                <AddtlInf>XYZ</AddtlInf>
            </StsRsnInf>
                </TxInfAndSts>
         </OrgnlPmtInfAndSts>
</CBISDDStsRptLogMsg>

and here is the snippet of my STRANS deserialization transformation code:

if i debug this transformation, it is dumping when it reaches the <OrgnlPmtInfAndSts> tag.

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary">

  <tt:root name="CBISDDStsRptLogMsg" type="ddic:ZEUDDR_XML_IT"/>

  <tt:template>
    <CBISDDStsRptLogMsg xmlns="urn:CBI:xsd:CBISDDStsRptLogMsg.00.01.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tt:ref=".CBISDDStsRptLogMsg">
      <tt:skip name="GrpHdr"/>
      <tt:skip name="OrgnlGrpInfAndSts"/>
      <OrgnlPmtInfAndSts>
        <tt:skip name="OrgnlPmtInfId"/>
        <tt:loop ref="ITEMS">
          <TxInfAndSts>
            <tt:skip name="OrgnlInstrId"/>
            <tt:skip name="OrgnlEndToEndId"/>
            <tt:skip name="TxSts"/>
            <StsRsnInf>
              <tt:skip name="Orgtr"/>
              <Rsn>
                <Cd tt:value-ref="REASON_CODE"/>
              </Rsn>
              <AddtlInf tt:value-ref="REASON_TEXT"/>
            </StsRsnInf>
            <OrgnlTxRef>

            </OrgnlTxRef>
          </TxInfAndSts>
        </tt:loop>
      </OrgnlPmtInfAndSts>

    </CBISDDStsRptLogMsg>
  </tt:template>

</tt:transform>

I have ran out of idea on why the error is happening even when I have provided the exact tag names. Would appreciate if you could advise what is the error about and how to resolve it.


Solution

  • The issue is related to skip because you refer to an element without indicating its namespace.

    As you are using the default namespace (xmlns="..."), you must add a dummy namespace prefix corresponding to the same namespace and it should work, e.g.:

        <CBISDDStsRptLogMsg 
               xmlns="urn:CBI:xsd:CBISDDStsRptLogMsg.00.01.00"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               tt:ref=".CBISDDStsRptLogMsg"
               xmlns:dummy="urn:CBI:xsd:CBISDDStsRptLogMsg.00.01.00">        <!-- added xmlns:dummy="..." -->
          <tt:skip name="dummy:GrpHdr"/>                                     <!-- added dummy: -->
          <tt:skip name="dummy:OrgnlGrpInfAndSts"/>                          <!-- added dummy: -->
    

    Reference thread in SAP forum: https://answers.sap.com/questions/13977108/sap-simple-transformation-deserialize-strange-resu.html