ABAP - Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  ST - Simple Transformations →  ST - Examples → 

Simple Transformation, Method Call

This example demonstrates the call of a static method from a simple transformation.

Source Code

METHOD main.
  DATA:  scarr_tab  TYPE SORTED TABLE OF scarr
                    WITH UNIQUE KEY carrid.

         FROM scarr
         INTO TABLE @scarr_tab.
  IF sy-subrc <> 0.
      CALL TRANSFORMATION demo_st_with_method_call
        SOURCE scarr_tab = scarr_tab
               spfli_tab = spfli_tab
        RESULT XML data(xml).
        cl_demo_output=>display_xml( xml ).
    CATCH cx_st_call_method_error INTO data(exc).
      cl_demo_output=>display_text( exc->get_text( ) ).


The method MAIN of the global class CL_DEMO_CALL_FROM_ST calls an ST program DEMO_ST_WITH_METHOD_CALL and passes the static attributes SCARR_TAB and SPFLI_TAB of this class to the data roots of the transformation with the same name. The table SCARR_TAB is filled and SPFLI_TAB is passed empty. The ST program is as follows:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="SCARR_TAB"/>
  <tt:root name="SPFLI_TAB"/>
  <tt:variable name="carrid"/>
      <tt:loop ref=".SCARR_TAB">
          <tt:attribute name="Carrier" value-ref="CARRNAME"/>
          <tt:assign ref="carrid" to-var="carrid"/>
          <tt:call-method class="CL_DEMO_CALL_FROM_ST"
            <tt:with-parameter name="CARRID" var="carrid"/>
          <tt:loop ref=".SPFLI_TAB">
              <tt:attribute name="ID" value-ref="CONNID"/>
                <tt:value ref="CITYFROM"/>
                <tt:value ref="CITYTO"/>

In a serialization in a tt:loop loop, it uses the data root SCARR_TAB to call the static method GET_FLIGHTS of the global class CL_DEMO_CALL_FROM_ST. This passes the component carrid of the internal table scarr_tab to the input parameter of the method. In the method, spfli_tab is filled in a different way in each loop, in accordance with the parameters passed.