Question

I want to receive data from an internal table which is a dynamic one.

For example, internal table has two fields: numbers - names

And it is filling with informations like:

enter image description here

How can I get only same datas? I want to get data base on numbers. I want to color the same numbers. I mean keyid's 1, 2, 6 are red, 3 and 4 are blue and 5 is yellow. Because of the internal table is dynamic I can't be sure there is always 1 into numbers.

Was it helpful?

Solution

I'm assuming you mean you don't know if your dynamic table always has the column you're looking for.

Use the Runtime Type Services (RTTS) to determine the structure of the dynamic table. The following bit of data will determine if your structure has a field called 'NUMBER'. You can use table lt_component to check which component you need to read ( ASSIGN COMPONENT number OF STRUCTURE <fs_line> TO <fs_field> ).

DATA:
    lr_tabledescr TYPE REF TO cl_abap_tabledescr,
    lr_datadescr  TYPE REF TO cl_abap_datadescr,
    lr_structdescr  TYPE REF TO cl_abap_structdescr,
    lr_typedescr    TYPE REF TO cl_abap_typedescr,
    lt_component    TYPE TABLE OF abap_componentdescr.

DATA tab TYPE TABLE OF sflight.

lr_tabledescr ?= cl_abap_datadescr=>describe_by_data( tab ).
lr_typedescr ?= lr_tabledescr->get_table_line_type( ).
lr_structdescr ?= lr_typedescr.
lt_component = lr_structdescr->get_components( ).


READ TABLE lt_component WITH KEY name = 'NUMBER'.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top