Skip to content

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

Simple Transformation, Method Call

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

Other versions: 7.31 | 7.40 | 7.54

Source Code

METHOD main.
  DATA:  scarr_tab  TYPE SORTED TABLE OF scarr
                    WITH UNIQUE KEY carrid,
         xml_string TYPE string,
         exc        TYPE REF TO cx_st_call_method_error.

  SELECT *
         FROM scarr
         INTO TABLE scarr_tab.

  IF sy-subrc <> 0.
    RETURN.
  ENDIF.

  TRY.
      CALL TRANSFORMATION demo_st_with_method_call
        SOURCE scarr_tab = scarr_tab
               spfli_tab = spfli_tab
        RESULT XML xml_string.
    CATCH cx_st_call_method_error INTO exc.
      MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'.
      RETURN.
  ENDTRY.

  cl_abap_browser=>show_xml( EXPORTING xml_string = xml_string ).

ENDMETHOD.

Description

The method main of the global class DEMO_ST_WITH_METHOD_CALL 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:

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="SCARR_TAB"/>
  <tt:root name="SPFLI_TAB"/>
  <tt:template>
    <Flights>
      <tt:loop ref=".SCARR_TAB">
        <Flights>
          <tt:attribute name="Carrier" value-ref="CARRNAME"/>
          <tt:call-method class="CL_DEMO_CALL_FROM_ST" s-name="GET_FLIGHTS">
            <tt:with-parameter name="CARRID" ref="carrid"/>
          </tt:call-method>
          <tt:loop ref=".SPFLI_TAB">
            <Connection>
              <tt:attribute name="ID" value-ref="CONNID"/>
              <From>
                <tt:value ref="CITYFROM"/>
              </From>
              <To>
                <tt:value ref="CITYTO"/>
             </To>
            </Connection>
          </tt:loop>
        </Flights>
      </tt:loop>
    </Flights>
  </tt:template>
</tt:transform>

During the serialization, the transformation calls the static method GET_FLIGHTS of the global class CL_DEMO_CALL_FROM_ST in a tt:loop loop over the data root SCARR_TAB. 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.