Fix RTTI method call

This commit is contained in:
Daniel Reger
2023-01-13 17:19:25 +01:00
parent e0df939dde
commit ee9be65b06

View File

@@ -1294,47 +1294,34 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(st) = CAST cl_abap_structdescr( DATA(st) = CAST cl_abap_structdescr(
cl_abap_tabledescr=>describe_by_name( table_name ) ). cl_abap_tabledescr=>describe_by_name( table_name ) ).
"Retrieving primary keys of the database table
DATA(field_list) = st->get_ddic_field_list( ).
"Declaring internal table to hold the primary keys
DATA itab_keys TYPE abap_keydescr_tab.
"Declaring an internal table to hold the components; "Declaring an internal table to hold the components;
"it will include the component name and the component type "it will include the component name and the component type
DATA comp_table TYPE cl_abap_structdescr=>component_table. DATA comp_table TYPE cl_abap_structdescr=>component_table.
"Looping across the retrieved field list to extract information "Looping across the retrieved field list to extract information
LOOP AT field_list ASSIGNING FIELD-SYMBOL(<field>). "In principle, you could also just use method get_components( ) :)
LOOP AT st->components ASSIGNING FIELD-SYMBOL(<field>).
"Adding name of the component and its type, which is retrieved using the "Adding name of the component and its type, which is retrieved using the
"get_component_type method, are added to the internal table that holds the components "get_component_type method, are added to the internal table that holds the components
APPEND VALUE #( name = <field>-fieldname APPEND VALUE #( name = <field>-name
type = st->get_component_type( <field>-fieldname ) ) TO comp_table. type = st->get_component_type( <field>-name ) ) TO comp_table.
"The keyflag field determines whether a field is key field or not.
"Here, it is jsut meant to have the same keys for the internal table
"as the database table.
IF <field>-keyflag = 'X'.
"Adding the name of the field to the internal table holding the primary keys
APPEND VALUE #( name = <field>-fieldname ) TO itab_keys.
ENDIF.
"Just for fun. The SELECT statement further down includes a dynamic specification "Just for fun. The SELECT statement further down includes a dynamic specification
"of the ORDER BY clause :) "of the ORDER BY clause :)
"In this case, just using the second field since MANDT is the first. "In this case, just using the second field since MANDT is the first.
IF sy-tabix = 2. IF sy-tabix = 2.
DATA(dyn_order_by) = <field>-fieldname. DATA(dyn_order_by) = <field>-name.
ENDIF. ENDIF.
ENDLOOP. ENDLOOP.
"Creating an internal table type "Creating an internal table type
"Note: The parameter p_key is not filled here, i. e. the default key is used.
DATA(itab_type) = cl_abap_tabledescr=>create( DATA(itab_type) = cl_abap_tabledescr=>create(
p_line_type = st p_line_type = st
p_table_kind = cl_abap_tabledescr=>tablekind_sorted p_table_kind = cl_abap_tabledescr=>tablekind_sorted
p_unique = cl_abap_typedescr=>true p_unique = cl_abap_typedescr=>true ).
p_key = itab_keys ).
"Creating an internal table based on the created table type "Creating an internal table based on the created table type
DATA ref_tab TYPE REF TO data. DATA ref_tab TYPE REF TO data.
@@ -1348,8 +1335,6 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
UP TO 3 ROWS. UP TO 3 ROWS.
output->display( |Type/Database table name determined at runtime: { table_name }| ). output->display( |Type/Database table name determined at runtime: { table_name }| ).
output->display( |Primary table keys of the created table type:| ).
output->display( input = itab_type->get_keys( ) name = `itab_type->get_keys( )` ).
output->display( |Internal table entries (ordered by { dyn_order_by }):| ). output->display( |Internal table entries (ordered by { dyn_order_by }):| ).
output->display( input = ref_tab->* name = `ref_tab->*` ). output->display( input = ref_tab->* name = `ref_tab->*` ).