Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Another variant to class CL_ALV_TABLE_CREATE that was described on the page

Dynamic Internal table

is the use of Runtime Type Identification classes (RTTI classes).

As described in the earlier blog, there are cases where the structure and table type are not known at design time. For example if you want to create a generic method with input parameters of 'type ref to data'. There are multiple descriptor classes provided by SAP Basis:

  • CL_ABAP_TYPEDESCR
  • CL_ABAP_DATADESCR
  • CL_ABAP_STRUCTDESCR
  • CL_ABAP_TABLEDESCR

see also https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapassign_mem_area_dynamic_dobj.htm

 

Below some coding examples how to use them...

Create a dynamic structure

  DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
  DATA lr_structure TYPE REF TO data.
  lr_structdescr ?= cl_abap_typedescr=>describe_by_data_ref( ir_data ).
  CREATE DATA lr_structure TYPE HANDLE lr_structdescr.
  ASSIGN lr_structure->* TO FIELD-SYMBOL(<fs_structure>).


Create a dynamic table of a known structure

    DATA lr_table TYPE REF TO data.
    DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
    lr_structdescr ?= cl_abap_typedescr=>describe_by_data_ref( ref #( ls_structure ) ).
    DATA lr_tabledescr TYPE REF TO cl_abap_tabledescr.
    lr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = lr_structdescr ).
    CREATE DATA lr_table TYPE HANDLE lr_tabledescr.
    ASSIGN lr_table->* TO FIELD-SYMBOL(<ft_table>).


You can of course add to the first example and create the dynamic table out of the dynamic structure

  DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
  DATA lr_structure TYPE REF TO data.
  lr_structdescr ?= cl_abap_typedescr=>describe_by_data_ref( ir_data ).
  CREATE DATA lr_structure TYPE HANDLE lr_structdescr.   
  lr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = lr_structdescr ).
  CREATE DATA lr_table TYPE HANDLE lr_tabledescr.
  ASSIGN lr_table->* TO FIELD-SYMBOL(<ft_table>).


Accessing a specific field of dynamic structure

  ASSIGN COMPONENT 'key' OF STRUCTURE <fs_structure> TO FIELD-SYMBOL(<lv_key>).

  Here 'key' is a data field of the structure.

 

 

 

 

 

  • No labels