简体   繁体   中英

CX_ST_MATCH_ELEMENT in ABAP Simple Transformation

I am trying to transform a simple XML to ABAP and use the transaction XSLT_TOOL . The dump I get

Errores tiempo ejec. ST_MATCH_FAIL Excepción
CX_ST_MATCH_ELEMENT Fecha y hora 31.07.2017 18:55:46

XML:

<?xml version="1.0" encoding="UTF-8"?>
<objects type="array">
    <object>
        <transaction-id type="integer">28</transaction-id>
        <message type="symbol">FAILURE</message>
        <errors type="array">
            <error>
                <row type="integer">0</row>
                <field>Sin datos</field>
                <message>El Json no puede estar en blanco.</message>
            </error>
        </errors>
    </object>
</objects>

xslt_工具

在此处输入图像描述

This is the generated by the program:

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">   <tt:root name="ZDGR2_RETORNOINVOCACION" type="ddic:ZDGR2_RETORNOINVOCACION"/>   <tt:template>
    <ZDGR2_RETORNOINVOCACION>
      <MESSAGE tt:value-ref=".ZDGR2_RETORNOINVOCACION.MESSAGE"/>
      <TRANSACTION_ID tt:value-ref=".ZDGR2_RETORNOINVOCACION.TRANSACTION_ID"/>
      <ERRORS>
        <tt:loop ref=".ZDGR2_RETORNOINVOCACION.ERRORS">
          <ZDGR2_ERRORS>
            <FILA tt:value-ref="FILA"/>
            <FIELD tt:value-ref="FIELD"/>
            <MESSAGE tt:value-ref="MESSAGE"/>
          </ZDGR2_ERRORS>
        </tt:loop>
      </ERRORS>
    </ZDGR2_RETORNOINVOCACION>   
</tt:template> </tt:transform>

This the simple program:

DATA: lv_xml Type string. 
DATA: it_resultado type ZDGR2_RETORNOINVOCACION. 
CONCATENATE '<?xml version="1.0" encoding="UTF-8"?><objects type="array"><object><transaction-id type="integer">28</transaction-id><message type="symbol">FAILURE</message><errors type="array"><error><row type="integer">0</row><field>Sin datos</field>' '<message>El Json no puede estar en blanco.</message></error></errors></object></objects>' INTO lv_xml. 

CALL TRANSFORMATION zdgr2_retornoinvocacion
     SOURCE XML lv_xml
     RESULT zdgr2_retornoinvocacion = it_resultado.

What am I doing wrong?

This dump happens when the tags in the XML not have the same name or order as in the transformation.

In your example i see multible problems:

Your XML structure starts like this:

<object>
   <transaction-id type="integer">28</transaction-id>
   <message type="symbol">FAILURE</message>

But your Transformation starts like this:

<ZDGR2_RETORNOINVOCACION>
  <MESSAGE tt:value-ref=".ZDGR2_RETORNOINVOCACION.MESSAGE"/> 
  <TRANSACTION_ID tt:value-ref=".ZDGR2_RETORNOINVOCACION.TRANSACTION_ID"/>

So in my opinion <ZDGR2_RETORNOINVOCACION> should be named <object> and <MESSAGE> and <TRANSACTION_ID> have to be swaped.

Also in the error substructure you have some missmatches

 <error>
     <row type="integer">0</row>
     <field>Sin datos</field>
     <message>El Json no puede estar en blanco.</message>
  </error>

<ZDGR2_ERRORS>
     <FILA tt:value-ref="FILA"/>
     <FIELD tt:value-ref="FIELD"/>
     <MESSAGE tt:value-ref="MESSAGE"/>
</ZDGR2_ERRORS>

<ZDGR2_ERRORS> should be named <error> and <FILA> should be named <row> .

So the important rule is that the tags have the same name and order in the xml file (its not case sensitive so it does not matter if its <OBJECT> or <object> ).

A advice from my side is, you can debug the transformation. Go through step by step and by the tag it dumps most of the times the name or the order is not ok. So you can find the errors fast and you dont have to compare the whole xml structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM