Hi,
I often have the requirement to copy an internal table into another and add/change some of the target's table members. E.g.:
REPORT zsdsm_mf_test_corresponding. INCLUDE <icons>. TYPES t_bapicond TYPE bapicond. TYPES: BEGIN OF t_bapicond2. TYPES: icon TYPE icon_d. INCLUDE TYPE bapicond. TYPES: END OF t_bapicond2. DATA: lt_source TYPE STANDARD TABLE OF t_bapicond ,lt_target TYPE STANDARD TABLE OF t_bapicond2 . START-OF-SELECTION. BREAK-POINT. "Sample Data lt_source = VALUE #( LET o_rnd = cl_abap_random_int=>create( seed = CONV i( sy-uzeit ) min = 1 max = 599 ) IN ( itm_number = lines( lt_source ) * 10 applicatio = 'V' cond_value = o_rnd->get_next( ) ) ( itm_number = lines( lt_source ) * 10 applicatio = 'V' cond_value = o_rnd->get_next( ) condisacti = abap_true ) ( itm_number = lines( lt_source ) * 10 applicatio = 'V' cond_value = o_rnd->get_next( ) condisacti = abap_true ) ( itm_number = lines( lt_source ) * 10 applicatio = 'V' cond_value = o_rnd->get_next( ) ) ( itm_number = lines( lt_source ) * 10 applicatio = 'V' cond_value = o_rnd->get_next( ) ) ). "OK lt_target = CORRESPONDING #( lt_source ). "OK lt_target = VALUE #( FOR wa IN lt_source ( CORRESPONDING #( wa ) ) ). "All inactive conditions should get a yellow icon! <<< "This works pretty well usign "old" coding... CLEAR: lt_target[]. LOOP AT lt_source ASSIGNING FIELD-SYMBOL(<fs_src>). APPEND CORRESPONDING #( <fs_src> ) TO lt_target REFERENCE INTO DATA(ref_tgt). ref_tgt->icon = COND #( WHEN <fs_src>-condisacti = abap_true THEN icon_led_yellow ELSE icon_space ). ENDLOOP. "How to do this way? Using FOR expression and CORRESPONDING * lt_target = VALUE #( * FOR wa IN lt_source ( * CORRESPONDING #( wa ) * ICON = COND icon_d( WHEN wa-condisacti = abap_true THEN icon_led_yellow ELSE icon_space ) * ) * ). BREAK-POINT.
Starting from line 54 I tried to replace the coding from lines 44 up to 51, but I had no luck so far.
Any hints?
Thanks,
Michael