Mentor SAP

 

Dynamically Generated Internal Table and Dynamic SELECT

 

Runtime Type Creation (RTTC)

 

In the figure, the CL_ABAP_REFDESCR, CL_ABAP_STRUCTDESCR, and CL_ABAP_TABLEDESCR classes are enhanced with a CREATE method, while the CL_ABAP_ELEMDESCR class receives an appropriate GET method for each built-in elementary ABAP type such as, GET_I, GET_F, GET_C, GET_STRING.

 

These methods return pointers to an instance of the respective class. In contrast to the DESCRIBE methods of the root class, the attribute values of this instance do not come from analyzing a data object, a reference, or a named type. Instead, they are passed on to the RTTC method explicitly.

 

The method signatures have been designed accordingly. While the GET_I method does not need any other input (type i is complete), method GET_P has two import parameters defined: one for length and the other for the number of decimal places.

 

The CREATE method for reference types expects the pointer to the description object for the referenced type, while the CREATE method for structure types expects a list with names and types of the components. When table types are generated, a reference to an RTTI object that describes the line type is expected (among other things).

 

 

 

The figure shows how to generate a table type dynamically with RTTC.

 

You are required to specify only the P_LINE_TYPE parameter for the CREATE method. The parameter is of type REF TO CL_ABAP_DATADESCR and needs to be supplied with a reference to any description object for a data type.  In the example shown in the figure, SPFLI is used as the line type. The DESCRIBE_BY_NAME method returns the matching description object.

 

The optional parameters are used to define the table type and key. If you do not specify them, a standard table with a non-unique standard key is used by default.

 

Use of RTTC Types

To dynamically create a data object with this specific type, use the dynamically generated type in the CREATE DATA statement.

 

Use the HANDLE addition with the CREATE DATA statement to generate a data object whose type matches the specified type description object. Specify the HANDLE as a reference variable with static type CL_ABAP_DATADESCR or one of its subclasses. The type object may have been created based on existing data types, using RTTI methods or by dynamically defining a new data type.