diff --git a/src/rtti/cl_abap_structdescr.clas.abap b/src/rtti/cl_abap_structdescr.clas.abap index 26bb4600..e82b7535 100644 --- a/src/rtti/cl_abap_structdescr.clas.abap +++ b/src/rtti/cl_abap_structdescr.clas.abap @@ -69,12 +69,39 @@ CLASS cl_abap_structdescr DEFINITION PUBLIC INHERITING FROM cl_abap_complexdescr METHODS update_components. DATA mt_refs TYPE component_table. + DATA mt_refs_comp TYPE component_table. ENDCLASS. CLASS cl_abap_structdescr IMPLEMENTATION. METHOD get_symbols. - ASSERT 1 = 'todo'. + DATA lt_components TYPE component_table. + DATA ls_symbol LIKE LINE OF p_result. + DATA lt_symbols TYPE symbol_table. + DATA lo_structdescr TYPE REF TO cl_abap_structdescr. + + FIELD-SYMBOLS LIKE LINE OF lt_components. + FIELD-SYMBOLS LIKE LINE OF lt_symbols. + + lt_components = get_components( ). + LOOP AT lt_components ASSIGNING . + IF -name IS NOT INITIAL. + ls_symbol-name = -name. + ls_symbol-type = -type. + INSERT ls_symbol INTO TABLE p_result. + ENDIF. + IF -as_include = abap_true. + lo_structdescr ?= -type. + lt_symbols = lo_structdescr->get_symbols( ). + LOOP AT lt_symbols ASSIGNING . + CONCATENATE -name -suffix INTO ls_symbol-name. + CONCATENATE -name -suffix INTO ls_symbol-name. + ls_symbol-type = -type. + INSERT ls_symbol INTO TABLE p_result. + ENDLOOP. + ENDIF. + ENDLOOP. + ENDMETHOD. METHOD get. @@ -113,21 +140,14 @@ CLASS cl_abap_structdescr IMPLEMENTATION. ENDMETHOD. METHOD get_included_view. - DATA ls_component LIKE LINE OF components. DATA ls_view LIKE LINE OF p_result. DATA ls_ref LIKE LINE OF mt_refs. - LOOP AT components INTO ls_component. + LOOP AT mt_refs INTO ls_ref WHERE as_include = abap_false. CLEAR ls_view. - ls_view-name = ls_component-name. - READ TABLE mt_refs WITH KEY name = ls_component-name INTO ls_ref. - IF sy-subrc = 0. - ls_view-type = ls_ref-type. - ENDIF. - IF ls_ref-as_include = abap_true. - CONTINUE. - ENDIF. + ls_view-name = ls_ref-name. + ls_view-type = ls_ref-type. INSERT ls_view INTO TABLE p_result. ENDLOOP. @@ -196,8 +216,9 @@ CLASS cl_abap_structdescr IMPLEMENTATION. WRITE '@KERNEL }'. ls_ref-as_include = lv_as_include. - WRITE '@KERNEL if (INPUT.data?.getSuffix) {'. - WRITE '@KERNEL lv_as_include.set(INPUT.data?.getSuffix()?.[name.toLowerCase()] || "");'. + WRITE '@KERNEL if (INPUT.data?.getRenamingSuffix) {'. + WRITE '@KERNEL lv_suffix.set(INPUT.data?.getRenamingSuffix()?.[name.toLowerCase()] || "");'. + TRANSLATE lv_suffix TO UPPER CASE. WRITE '@KERNEL }'. ls_ref-suffix = lv_suffix. @@ -208,10 +229,17 @@ CLASS cl_abap_structdescr IMPLEMENTATION. ENDMETHOD. METHOD update_components. - DATA ls_component LIKE LINE OF components. + DATA ls_component LIKE LINE OF components. + DATA lo_structdescr TYPE REF TO cl_abap_structdescr. + DATA lt_components TYPE abap_component_tab. + DATA lv_name TYPE string. FIELD-SYMBOLS LIKE LINE OF mt_refs. + FIELD-SYMBOLS LIKE LINE OF lt_components. CLEAR components. + + mt_refs_comp = mt_refs. + LOOP AT mt_refs ASSIGNING . ls_component-name = -name. ls_component-type_kind = -type->type_kind. @@ -219,10 +247,22 @@ CLASS cl_abap_structdescr IMPLEMENTATION. ls_component-decimals = -type->decimals. APPEND ls_component TO components. ENDLOOP. + +* the mt_refs contain really everything available in runtime +* the mt_ref_comp contains only the components that are not added as "as include" (needed for get_components) + LOOP AT mt_refs ASSIGNING WHERE as_include = abap_true. + lo_structdescr ?= -type. + lt_components = lo_structdescr->get_components( ). + LOOP AT lt_components ASSIGNING . + CONCATENATE -name -suffix INTO lv_name. + DELETE mt_refs_comp WHERE name = lv_name. + ENDLOOP. + ENDLOOP. + ENDMETHOD. METHOD get_components. - rt_components = mt_refs. + rt_components = mt_refs_comp. ENDMETHOD. METHOD get_component_type. diff --git a/src/rtti/cl_abap_structdescr.clas.testclasses.abap b/src/rtti/cl_abap_structdescr.clas.testclasses.abap index f7d489ed..c641da59 100644 --- a/src/rtti/cl_abap_structdescr.clas.testclasses.abap +++ b/src/rtti/cl_abap_structdescr.clas.testclasses.abap @@ -17,6 +17,8 @@ CLASS ltcl_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL. METHODS get_included_view2 FOR TESTING RAISING cx_static_check. METHODS get_included_view3 FOR TESTING RAISING cx_static_check. METHODS length FOR TESTING RAISING cx_static_check. + METHODS get_components_include FOR TESTING RAISING cx_static_check. + METHODS get_symbols FOR TESTING RAISING cx_static_check. ENDCLASS. @@ -355,4 +357,64 @@ CLASS ltcl_test IMPLEMENTATION. ENDMETHOD. + METHOD get_components_include. + + TYPES: BEGIN OF ty_struc, + b TYPE c LENGTH 1, + END OF ty_struc. + + TYPES BEGIN OF ty_struc_root. + INCLUDE TYPE ty_struc AS nest RENAMING WITH SUFFIX _n. + TYPES: + a TYPE c LENGTH 1, + END OF ty_struc_root. + + DATA ls_data TYPE ty_struc_root. + DATA lo_struct TYPE REF TO cl_abap_structdescr. + DATA lt_components TYPE cl_abap_structdescr=>component_table. + + lo_struct ?= cl_abap_structdescr=>describe_by_data( ls_data ). + lt_components = lo_struct->get_components( ). + + cl_abap_unit_assert=>assert_equals( + exp = 2 + act = lines( lt_components ) ). + + ENDMETHOD. + + METHOD get_symbols. + + TYPES: BEGIN OF ty_struc, + b TYPE c LENGTH 1, + END OF ty_struc. + + TYPES BEGIN OF ty_struc_root. + INCLUDE TYPE ty_struc AS nest RENAMING WITH SUFFIX _n. + TYPES: + a TYPE c LENGTH 1, + END OF ty_struc_root. + + DATA ls_data TYPE ty_struc_root. + DATA lo_struct TYPE REF TO cl_abap_structdescr. + DATA lt_symbols TYPE cl_abap_structdescr=>symbol_table. + + lo_struct ?= cl_abap_structdescr=>describe_by_data( ls_data ). + lt_symbols = lo_struct->get_symbols( ). + + cl_abap_unit_assert=>assert_equals( + exp = 3 + act = lines( lt_symbols ) ). + + READ TABLE lt_symbols WITH KEY name = 'A' TRANSPORTING NO FIELDS. + cl_abap_unit_assert=>assert_subrc( + exp = 0 + act = sy-subrc ). + + READ TABLE lt_symbols WITH KEY name = 'B_N' TRANSPORTING NO FIELDS. + cl_abap_unit_assert=>assert_subrc( + exp = 0 + act = sy-subrc ). + + ENDMETHOD. + ENDCLASS. \ No newline at end of file