Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Working with table type any with mapping according to keys

Former Member
0 Kudos

Hi All ,

I have table type any with data and I need to fill structure type any according to respective key and verify that the field is have mapping .

i.e. I have a table <lt_itab> and I need to find the specific entry on it according to the key and the mapping .

I guess that the best way is to give example.

<lt_itab> - Is type any and can have lot of entries

lt_key - Is specified table with field_name and value

lt_map - Table with field_name which have mapping (have unique field name in every entry of the table )from f1..fn -

I need to fill fields in <ls_output> just if they appear in lt_map

<ls_output> - Is structure type any that in the end should have all the data from <ls_itab> according to the mapping and the keys of the table

<lt_itab> - table 

f1  f2  f3  f4  f5 f6 
1   2    3  4   5  6  
5   5    4  3   8  4  
6   9    2  5   3  5
1   3    3  4   2  1


lt_key  - table 

field_name   value
f1            1
f2            3



lt_map  - table

field_name 
f1
f2
f5
f6

<ls_output> - structure 

field  value 
f1  -   1 
f2  -   2
f3  "Not in mapping so it's empty
f4  "Not in mapping so it's empty
f5  -   2
f6  -   1

<ls_output> have the field values of the last entry of <lt_itab> according to the key of f1 and f2 and according to the mapping f3 and f4 are empty

since they are not appaer in lt_map

Regards

Joy

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

You have to loop fully your main table in order to get the records in according to they keys:

LOOP AT <LT_ITAB> ASSIGNING <WT_ITAB>.
   L_KO = SPACE. 
   LOOP AT LT_KEY.
        ASSIGN COMPONENT LT_KEY-FIELDNAME OF STRUCTURE <WT_ITAB> TO <FS_KEY>.
        IF <FS_KEY> NE LT_KEY-VALUE.
           L_KO = 'X'.
           EXIT.
        ENDIF.
    ENDLOOP.
    
    CHECK L_KO IS INITIAL.
    LOOP AT LT_MAP.
        ASSIGN COMPONENT LT_MAP-FIELDNAME OF STRUCTURE <WT_ITAB>      TO <FS_FROM>.
        ASSIGN COMPONENT LT_MAP-FIELDNAME OF STRUCTURE <WT_OUTPUT> TO <FS_TO>.
        <FS_TO> = <FS_FROM>.
    ENDLOOP.
    APPEND <WT_OUTPUT> TO <LT_OUTPUT>.
ENDLOOP.

Max

1 REPLY 1

Former Member
0 Kudos

Hi

You have to loop fully your main table in order to get the records in according to they keys:

LOOP AT <LT_ITAB> ASSIGNING <WT_ITAB>.
   L_KO = SPACE. 
   LOOP AT LT_KEY.
        ASSIGN COMPONENT LT_KEY-FIELDNAME OF STRUCTURE <WT_ITAB> TO <FS_KEY>.
        IF <FS_KEY> NE LT_KEY-VALUE.
           L_KO = 'X'.
           EXIT.
        ENDIF.
    ENDLOOP.
    
    CHECK L_KO IS INITIAL.
    LOOP AT LT_MAP.
        ASSIGN COMPONENT LT_MAP-FIELDNAME OF STRUCTURE <WT_ITAB>      TO <FS_FROM>.
        ASSIGN COMPONENT LT_MAP-FIELDNAME OF STRUCTURE <WT_OUTPUT> TO <FS_TO>.
        <FS_TO> = <FS_FROM>.
    ENDLOOP.
    APPEND <WT_OUTPUT> TO <LT_OUTPUT>.
ENDLOOP.

Max