Skip to Content
avatar image
Former Member

Simple Transformation XML to ABAP - error CX_ST_MATCH_ELEMENT

Hi all,

I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is

 <?xml version="1.0" encoding="iso-8859-1" ?> 
- <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
- <asx:values>
  <NETWORK>E60000000000</NETWORK> 
  <OPERAZIONE>0010</OPERAZIONE> 
- <TABELLA>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
  <MANDT>300</MANDT> 
  <NETWORK>E60000000000</NETWORK> 
  <OPERAZIONE>0010</OPERAZIONE> 
  <ID_ACT>1</ID_ACT> 
  <DESC_ACT>ATTIVITÀ1</DESC_ACT> 
  <LONG_TXT></LONG_TXT> 
  <MAKE_BUY></MAKE_BUY> 
  <WP></WP> 
  <EVENTO_TECH></EVENTO_TECH> 
  <TIPO_LEGAME></TIPO_LEGAME> 
  <CONSEGNA></CONSEGNA> 
  </ROW>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
  <MANDT>300</MANDT> 
  <NETWORK>E60000000000</NETWORK> 
  <OPERAZIONE>0010</OPERAZIONE> 
  <ID_ACT>2</ID_ACT> 
  <DESC_ACT>ATTIVITÀ2</DESC_ACT> 
  <LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT> 
  <MAKE_BUY>M</MAKE_BUY> 
  <WP></WP> 
  <EVENTO_TECH></EVENTO_TECH> 
  <TIPO_LEGAME></TIPO_LEGAME> 
  <CONSEGNA></CONSEGNA> 
  </ROW>
  </TABELLA>
  </asx:values>
  </asx:abap>

my transformation is

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

  <tt:root name="ROOT"></tt:root>
  <tt:root name="NETWORK"></tt:root>
  <tt:root name="OPERAZIONE"></tt:root>
  <tt:template>
  <abap>
    <values>
       <network>
           <tt:value ref="NETWORK"></tt:value>
       </network>
       <operazione>
           <tt:value ref="OPERAZIONE"></tt:value>
       </operazione>
       <tabella>
          <tt:loop ref=".ROOT" name="line">
            <mandt>
              <tt:value ref="$line.mandt"></tt:value>
            </mandt>
            <network>
              <tt:value ref="$line.network"></tt:value>
            </network>
            <OPERAZIONE>
              <tt:value ref="$line.OPERAZIONE"></tt:value>
            </OPERAZIONE>
            <ID_ACT>
              <tt:value ref="$line.ID_ACT"></tt:value>
            </ID_ACT>
            <DESC_ACT>
              <tt:value ref="$line.DESC_ACT"></tt:value>
            </DESC_ACT>
            <LONG_TXT>
              <tt:value ref="$line.LONG_TXT"></tt:value>
            </LONG_TXT>
            <MAKE_BUY>
              <tt:value ref="$line.MAKE_BUY"></tt:value>
            </MAKE_BUY>
            <WP>
              <tt:value ref="$line.WP"></tt:value>
            </WP>
            <EVENTO_TECH>
              <tt:value ref="$line.EVENTO_TECH"></tt:value>
            </EVENTO_TECH>
            <TIPO_LEGAME>
              <tt:value ref="$line.TIPO_LEGAME"></tt:value>
            </TIPO_LEGAME>
            <CONSEGNA>
              <tt:value ref="$line.CONSEGNA"></tt:value>
            </CONSEGNA>
         </tt:loop>
        </tabella>
      </values>
    </abap>
  </tt:template>
</tt:transform>

when I execute my code


the system dump with this error

ST_MATCH_FAIL

excep. CX_ST_MATCH_ELEMENT

TRY.

CALL TRANSFORMATION ('ZT_NETWORK')

SOURCE XML lv_xml_data_string

RESULT network = l_network

operazione = l_operazione

root = it_data_tmp.

CATCH cx_sy_conversion_data_loss .

CATCH cx_xslt_exception INTO xslt_error.

xslt_message = xslt_error->get_text( ).

WRITE:/ xslt_message .

ENDTRY.

Any help?

thanks

enzo

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 20, 2009 at 11:01 PM

    > I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is

    >

     <?xml version="1.0" encoding="iso-8859-1" ?> 
    >  <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    >  <asx:values>

    Your XML is strange, it looks like a mix of pdf form content (xfa) and identity transformation (asx).

    Could you explain more ?

    Anyway, I tried to find out the errors (not only cx_st_match_element, that was just a catch missing), it works with the following program. Here are the main issues I have found :

    - always catch exception class cx_st_error when you use simple transformations (it contains cx_st_match_element and all other simple transformation exceptions)

    - xml "asx:abap" and "asx:values" in your input XML are useless, they are only used by identity transformation ("ID"); you may keep them if you want, but I advise you to see why they are in the xml !

    - Use same case in your tags (if xml contains in the transformation so that it corresponds to the input XML

    - I renamed all abap names with prefix ABAP_ so that to clearly differentiate xml tags and abap field names (so that it is more easy to understand, for every sdn reader; I hope it will help as I didn't find many threads in the forum).

    Simple transformation :

    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
    
      <tt:root name="ABAP_NETWORK"></tt:root>
      <tt:root name="ABAP_OPERAZIONE"></tt:root>
      <tt:root name="ABAP_TABELLA"></tt:root>
    
      <tt:template>
        <ROOT>
          <NETWORK>
            <tt:value ref=".ABAP_NETWORK"></tt:value>
          </NETWORK>
          <OPERAZIONE>
            <tt:value ref=".ABAP_OPERAZIONE"></tt:value>
          </OPERAZIONE>
          <TABELLA>
            <tt:loop ref=".ABAP_TABELLA" name="line">
              <ROW>
                <MANDT>
                  <tt:value ref="$line.ABAP_MANDT"></tt:value>
                </MANDT>
                <NETWORK>
                  <tt:value ref="$line.ABAP_NETWORK"></tt:value>
                </NETWORK>
                <OPERAZIONE>
                  <tt:value ref="$line.ABAP_OPERAZIONE"></tt:value>
                </OPERAZIONE>
                <ID_ACT>
                  <tt:value ref="$line.ABAP_ID_ACT"></tt:value>
                </ID_ACT>
                <DESC_ACT>
                  <tt:value ref="$line.ABAP_DESC_ACT"></tt:value>
                </DESC_ACT>
                <LONG_TXT>
                  <tt:value ref="$line.ABAP_LONG_TXT"></tt:value>
                </LONG_TXT>
                <MAKE_BUY>
                  <tt:value ref="$line.ABAP_MAKE_BUY"></tt:value>
                </MAKE_BUY>
                <WP>
                  <tt:value ref="$line.ABAP_WP"></tt:value>
                </WP>
                <EVENTO_TECH>
                  <tt:value ref="$line.ABAP_EVENTO_TECH"></tt:value>
                </EVENTO_TECH>
                <TIPO_LEGAME>
                  <tt:value ref="$line.ABAP_TIPO_LEGAME"></tt:value>
                </TIPO_LEGAME>
                <CONSEGNA>
                  <tt:value ref="$line.ABAP_CONSEGNA"></tt:value>
                </CONSEGNA>
              </ROW>
            </tt:loop>
          </TABELLA>
        </ROOT>
      </tt:template>
    </tt:transform>
    

    Program and XML included :

    REPORT  zsro2.
    DATA l_network TYPE string.
    DATA l_operazione TYPE string.
    DATA : BEGIN OF lt_data_tmp OCCURS 0,
             abap_mandt      TYPE string,
             abap_network    TYPE string,
             abap_operazione TYPE string,
             abap_id_act     TYPE string,
             abap_desc_act   TYPE string,
             abap_long_txt   TYPE string,
             abap_make_buy   TYPE string,
             abap_wp         TYPE string,
             abap_evento_tech TYPE string,
             abap_tipo_legame TYPE string,
             abap_consegna   TYPE string,
           END OF lt_data_tmp.
    DATA xslt_error TYPE REF TO cx_xslt_exception.
    DATA lo_st_error TYPE REF TO cx_st_error.
    DATA lv_xml_data_string TYPE string.
    DATA xslt_message TYPE string.
    DEFINE conc.
      concatenate lv_xml_data_string &1 into lv_xml_data_string.
    END-OF-DEFINITION.
    *conc '<?xml version="1.0" encoding="iso-8859-1" ?>'.
    *conc '<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">'.
    *conc '  <asx:values>'.
    conc ' <ROOT>'.
    conc '    <NETWORK>E60000000000</NETWORK> '.
    conc '    <OPERAZIONE>0010</OPERAZIONE> '.
    conc '    <TABELLA>'.
    conc '      <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
    conc '        <MANDT>300</MANDT> '.
    conc '        <NETWORK>E60000000000</NETWORK> '.
    conc '        <OPERAZIONE>0010</OPERAZIONE> '.
    conc '        <ID_ACT>1</ID_ACT> '.
    conc '        <DESC_ACT>ATTIVITÀ1</DESC_ACT> '.
    conc '        <LONG_TXT></LONG_TXT> '.
    conc '        <MAKE_BUY></MAKE_BUY> '.
    conc '        <WP></WP> '.
    conc '        <EVENTO_TECH></EVENTO_TECH> '.
    conc '        <TIPO_LEGAME></TIPO_LEGAME> '.
    conc '        <CONSEGNA></CONSEGNA> '.
    conc '      </ROW>'.
    conc '      <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
    conc '        <MANDT>300</MANDT> '.
    conc '        <NETWORK>E60000000000</NETWORK> '.
    conc '        <OPERAZIONE>0010</OPERAZIONE> '.
    conc '        <ID_ACT>2</ID_ACT> '.
    conc '        <DESC_ACT>ATTIVITÀ2</DESC_ACT> '.
    conc '        <LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT> '.
    conc '        <MAKE_BUY>M</MAKE_BUY> '.
    conc '        <WP></WP> '.
    conc '        <EVENTO_TECH></EVENTO_TECH> '.
    conc '        <TIPO_LEGAME></TIPO_LEGAME> '.
    conc '        <CONSEGNA></CONSEGNA> '.
    conc '      </ROW>'.
    conc '    </TABELLA>'.
    conc ' </ROOT>'.
    *conc '  </asx:values>'.
    *conc '</asx:abap>'.
    DATA lv_xml_data_string_2 TYPE string.
    
    TRY.
        CALL TRANSFORMATION zsro
              SOURCE
                XML lv_xml_data_string
              RESULT
                abap_network    = l_network
                abap_operazione = l_operazione
                abap_tabella    = lt_data_tmp[].
      CATCH cx_sy_conversion_data_loss .
      CATCH cx_st_error INTO lo_st_error.
        xslt_message = lo_st_error->get_text( ).
        WRITE:/ xslt_message .
      CATCH cx_xslt_exception INTO xslt_error.
        xslt_message = xslt_error->get_text( ).
        WRITE:/ xslt_message .
    ENDTRY.
    BREAK-POINT.
    

    Add comment
    10|10000 characters needed characters exceeded