Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Dynamic table creation using RTTS.

I was reading the blog published by Pieter Lemaire on (Dynamic tables in ALV with RTTI); there he has explained some dynamic functionality using RTTS – I thought the way he was creating the dynamic internal tables using RTTS could be achieved in a much simpler way; therefore I thought of writing this blog to show that how easily we can generate dynamic internal tables & work areas from user definitions using RTTS.  Please see the code developed below.

PARAMETERS:: p_table(30) TYPE c.

DATA:

      it_component
TYPE abap_component_tab,
      wa_component
TYPE abap_componentdescr,
      o_ref_type
TYPE REF TO cl_abap_typedescr,
      o_ref_struct
TYPE REF TO cl_abap_structdescr,
      o_ref_table
TYPE REF TO cl_abap_tabledescr,
      o_table
TYPE REF TO data,
      o_workarea
TYPE REF TO data.

FIELD-SYMBOLS:
               <fs>
TYPE any,
               <fs_table>
TYPE ANY TABLE.


*Calling this method to get the TYPE Definition.

cl_abap_typedescr
=>describe_by_name(
 
EXPORTING
    p_name        
= p_table
  RECEIVING
    p_descr_ref   
= o_ref_type
 
EXCEPTIONS
   type_not_found
= 1 ).

CHECK o_ref_type IS BOUND.
o_ref_struct ?= o_ref_type
.

*Calling to get the components of the structure
it_component[]
= o_ref_struct->get_components( ).

IF it_component[] IS NOT INITIAL.
 
CLEAR:
        o_ref_struct
.

*Factory Method
  o_ref_struct
= cl_abap_structdescr=>create( it_component ).

 
CHECK o_ref_struct IS BOUND.
 
CREATE DATA o_workarea TYPE HANDLE o_ref_struct.
 
ASSIGN o_workarea->* TO <fs>.


*Factory Method.
  o_ref_table
= cl_abap_tabledescr=>create(
  p_line_type
= o_ref_struct
  p_table_kind
= cl_abap_tabledescr=>tablekind_std ).

 
CHECK o_ref_table IS BOUND.
 
CREATE DATA o_table TYPE HANDLE o_ref_table.
 
ASSIGN o_table->* TO <fs_table>.

ENDIF.



3 Comments