ABAP Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Transformations for XML → ST - Simple Transformations → ST - Access to ABAP Objects from ST
ST - tt:call-method, Call Static Methods
<tt:call-method class="class" [s-|d-]name="meth"
[writer = "writer_para"]
[reader = "reader_para"]
Using this variant of the statement tt:call-method, a static method of a global ABAP Objects class can be called in an ST program as follows: class can be used to specify a class from the class library and meth can be used to specify a visible method of this class. This is not case-sensitive. The method is called for both serializations and deserializations when name is declared; it is called for serializations only when s-name is declared and for deserializations only when d-name is declared.
The interface parameters para1, para2, … of the called method can or must be bound to actual parameters, using the ST command tt:with-parameter. The attribute name specifies the name of a formal parameter. An actual parameter is bound to this attribute only in serializations (if s-name is specified) and only in deserializations (if d-name is specified). In certain cases, this allows a single method to be used for both directions. As actual parameters, ref can be used to specify data roots, var to specify variables or parameters, and val to specify values. Depending on the kind of formal parameter, the values of the specified actual parameters are either passed in the call or used when the called method ends.
When actual parameters are used, read-only access to data roots is possible only in serializations, which is why they can only be passed to input parameters of the method. In the reverse case (deserializations), only write access to data roots is possible, which is why they can be used only by output parameters or return codes.
The type of an actual parameter must match the typing of the interface parameter. The type of a data root, which can itself be typed in the statement tt:root, is determined by the type of the bound ABAP data object. Parameters and variables do not have a static type, unless the addition ref-type of the statements tt:parameter or tt:variable defines them as reference variables. Data reference variables defined in this way can be bound to interface parameters of the same type.
When a method is called, control passes from the ST processor to the ABAP processor of the ABAP runtime
environment. There are no restrictions on which statements can be executed in the method. If
RETURN is used to exit a method correctly, control passes to the ST processor
again and the ST program resumes after tt:call-method. Otherwise, the control does not pass back to the ST program:
- If a statement such as
SUBMITwithout the addition
AND RETURN, or
LEAVE TO TRANSACTIONis used to exit the method, the program responds as if the method were called from an ABAP program; that is, the current internal mode is deleted, together with the ST program.
- If the method is terminated by a class-based exception, and the exception is propagated from the
method, the statement
CALL TRANSFORMATIONis terminated with the handleable exception CX_ST_CALL_METHOD_ERROR. The EXCEPTION_NAME attribute of the exception object is then given the name of the original exception.
- Non-class-based exceptions cannot be handled. A method terminated using a non-class-based exception always causes a runtime error.
If ABAP data objects are modified in the called method, and these data objects are bound to data roots of the calling ST program, these modifications take effect immediately in the ST program. The following restriction applies: If a method is called within a tt:loop loop, serialization within the method (and within further nested tt:loop loops) only permits read-only access to the current internal table or its components. Deserialization within the method does not allow any access. Otherwise, a runtime error occurs.
Using the optional attributes writer and reader, the input parameters writer_para or reader_para of the called method can be specified. These parameters must have the references types IF_SXML_WRITER or IF_SXML_READER. If s-name is specified, only writer can be specified. If d-name is specified, only reader can be specified. If name is specified, both attributes can be specified. writer is used for serialization and reader is used for deserialization. These attributes can be used to pass a reference to the XML writer or the XML reader (created by CALL TRANSFORMATION) to called method. In the method, the relevant interface can be used to access the reader or writer.
If variables or parameters are bound to the interface parameters of called methods, note that these variables or parameters can be serialized or deserialized only if they contain elementary values.
The following transformation exists as DEMO_ST_WITH_METHOD_CALL in AS ABAP. 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.
<tt:attribute name="Carrier" value-ref="CARRNAME"/>
<tt:with-parameter name="CARRID" ref="carrid"/>
<tt:attribute name="ID" value-ref="CONNID"/>
The simple transformation can be called in a different method MAIN of the same class DEMO_ST_WITH_METHOD_CALL as follows:
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.
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 xml_string.
CATCH cx_st_call_method_error INTO exc.
MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'.
cl_abap_browser=>show_xml( EXPORTING xml_string = xml_string ).
The internal tables
both static attributes of the class.
scarr_tab is filled and passed to the
transformation data root with the same name;
spfli_tab, however, remains
empty and is filled in a different way (in the method GET_SPFLI called from the simple transformation) in each loop, in accordance with the parameter
The method MAIN is bound to the transaction code DEMO_ST_METHOD_CALL and produces the following result:
<Flights Carrier="American Airlines">
<Flights Carrier="Air Berlin">
The program above uses the binding of the attribute
spfli_tab to the simple
transformation, and write access to this attribute in the called method, to enable write access to data nodes in serializations within the ST program.