Reputation: 1
I've got a task to flat out a deeply nested structure and gather all of the values from the fields. So far I manage to do the first part of the task but I've got a problem with taking out values from the fields of internal tables that are nested within my main structure, does anyone got an idea how to do that ?
The structure look like this, Main table has a couple of columns and each column has internal table or another deeply nested structure. Both structures has its own fields with values and another structures in it. It goes up to 8 level of depth in terms of volume so it's not all of the fields that I've descibed here (around 284 fields in total). And yes, the types of those internal tables are different:
DATA: lo_structure_descriptor type ref to cl_abap_structdescr,
lo_structure_descriptor_tmp type ref to cl_abap_structdescr,
lo_table_descriptor type ref to cl_abap_tabledescr,
lt_structure_components_nested type cl_abap_structdescr=>component_table,
lt_structure_components_flat type cl_abap_structdescr=>component_table,
lv_index type sy-tabix.
lo_table_descriptor ?= cl_abap_structdescr=>describe_by_data( lt_result_table_nested ).
lo_structure_descriptor ?= lo_table_descriptor->get_table_line_type( ).
lt_structure_components = lo_structure_descriptor->get_components( ).
loop at lt_structure_components_nested ASSIGNING FIELD-SYMBOL(<fs_component>).
lv_index = sy-tabix.
IF <fs_component>-type->kind EQ 'E'.
* Add only elemantary components to component table
***Here i've tried to pass a value of component**
ASSIGN COMPONENT <fs_component>-name OF STRUCTURE lt_result_table_nested TO <fs_table>.
ASSIGN COMPONENT <fs_component>-name OF STRUCTURE <fs_table> TO <fs_field>.
***Here i've tried to pass a value of component**
APPEND <fs_component> to lt_structure_components_flat.
ENDIF.
IF <fs_component>-type->kind EQ 'S'.
* Expand nested structures before adding their elements to component table
lo_structure_descriptor_tmp ?= <fs_component>-type.
data(nested_components) = lo_structure_descriptor_tmp->get_components( ).
loop at nested_components ASSIGNING FIELD-SYMBOL(<fs_nested_component>).
if line_exists( lt_structure_components_nested[ name = <fs_nested_component>-name ] ).
* Workaround for duplicate file-names
<fs_nested_component>-name = <fs_comp>-name && `_` && <fs_new_comp>-name.
ENDIF.
* Insert after current index (preserves sort order)
INSERT <fs_nested_component> INTO lt_structure_components_nested INDEX ( lv_index + sy-tabix ).
ENDLOOP.
ENDIF.
ENDLOOP.
Upvotes: 0
Views: 416