Ansicht
Dokumentation

ABENST_TT_CREATE - ST TT CREATE

ABENST_TT_CREATE - ST TT CREATE

General Material Data   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

- tt:create-object, Create Objects

tt:create-object var="oref" $[class="class"$]>
  $[tt:with-parameter name="para1"
                      $[ref="node1"$|val="val1"$|var="var1"$] />
   tt:with-parameter name="para2"
                      $[ref="node2"$|val="val2"$|var="var2"$] />
   ...$]
/tt:create-object>


Effect

The statement tt:create-object can be used to create an instance of a global ABAP Objects class in an ST program. var can be used to specify a variable or a parameter of the ST program. The variable or parameter must have been created as a class reference variable or an interface reference variable with the addition ref-type.

The object is created in the internal session of the ABAP program that called the ST program. If the attribute class is not specified, var must be a class reference variable and an instance of the corresponding class is created. If the attribute class is specified, an instance of the specified class is created. A global class from the ABAP class library can be specified for class, either more special or the same as the static type of the reference variable var:

  • If var is a class reference variable, class must be the class or subclass of the class of var.
  • If var is an interface reference variable, class must implement the interface of var.

The interface parameters para1, para2, ... of the instance constructor of the class of the object can or must be bound to actual parameters, using the ST statement tt:with-parameter. The same rules apply here as to regular method calls. Constructor exceptions are also handled in the same way as exceptions for regular method calls.

After the object has been created, the reference variable var points to the object and can be used to call instance methods.

Example

The following Simple Transformation uses the variable ovar to create an object of the class cls and passes the data root PARA to the parameter repl of its instance constructor. The method convert is then called, whose input/output parameter is assigned the variable result. Note that a data root cannot be assigned to an input/output parameter, neither in serializations nor in deserializations.

tt:transform
  xmlns:tt="http://www.sap.com/transformation-templates">
  tt:root name="ROOT"/>
  tt:root name="PARA"/>
  tt:variable name="ovar" ref-type="cls"/>
  tt:variable name="result"/>
  tt:template>
    tt:create-object var="ovar">
      tt:with-parameter name="repl" ref="PARA"/>
    /tt:create-object>
    tt:assign ref="ROOT" to-var="result"/>
    tt:call-method s-name="convert" var="ovar">
      tt:with-parameter name="text" var="result"/>
    /tt:call-method>
    Result>
      tt:write var="result"/>
    /Result>
  /tt:template>
/tt:transform>

The following is an example of a calling ABAP program:

DATA xml_string TYPE string.
DATA text       TYPE string VALUE '1 2 3'.
DATA repl       TYPE string value '*'.
DATA exc        TYPE REF TO cx_st_call_method_error.

TRY.
    CALL TRANSFORMATION ...
      SOURCE root = text
             para = repl
      RESULT XML xml_string.
      cl_abap_browser=>show_xml( xml_string = xml_string ).
  CATCH cx_st_call_method_error INTO exc.
    ...
ENDTRY.

The constructor and the method convert of the class cls are defined as follows:

METHOD constructor.
  me->repl = repl.
ENDMETHOD.
METHOD convert.
  REPLACE ALL OCCURRENCES OF ` ` IN text WITH repl.
ENDMETHOD.

The result of the transformation is as follows:

Result>1*2*3/Result>






Fill RESBD Structure from EBP Component Structure   PERFORM Short Reference  
This documentation is copyright by SAP AG.

Length: 7094 Date: 20240418 Time: 062101     sap01-206 ( 78 ms )