Skip to Content

Is there a new syntax (740, 750, 751) to MODIFY same internal table?

Hello All,

I was wondering if there's a new way to modify same internal table with new syntax. The old way would be looping thru and modify it.

For condition based, MODIFY internal_table FROM work_area WHERE (condition) would do the trick, however, doing it unconditionally would require a LOOP.

LOOP AT internal_table ASSIGNING FIELD-SYMBOL(<field_symbol>).
  <field_symbol>-field = value.
ENDLOOP.

Since ABAP lang has evolved - right from 740, 750 and now 751; and it still is evolving, is there a new way to do it which I probably missed?

If no, then can we have something like

internal_table[ 1..lines( internal_table ) ]-field = value.

I know it's like always asking for more which raises some eye-brows because there are a few, (who I know), are still averse to using the new syntax.

But, as they say - When the storm has swept by, the wicked are gone, but the righteous stand firm forever! ;-)

Cheers!

Add comment
10|10000 characters needed characters exceeded

  • Duh! It came out to be very simple. Thanks Horst, your blogs always help me!

    internal_table = VALUE #( FOR <field_symbol> IN internal_table
                       LET lv_value = value IN
                       ( VALUE #( BASE CORRESPONDING #( <field_symbol> ) field = lv_value ) )
                     ).                 
  • But... is that better than a loop at? Is it more readable? Does it give a performance gain?

  • Get RSS Feed

3 Answers

  • Best Answer
    Apr 18, 2017 at 09:04 AM

    Look up the documentation and examples for the constructor operators VALUE, REDUCE, FILTER, CORRESPONDING, COND, ....

    You can combine them and use the same table at LHS and RHS.

    itab = operator #( ... FOR wa IN itab ... )

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 17, 2017 at 12:05 PM
    DATA lt TYPE some_table.
    DATA ls TYPE LINE OF some_table.
    ls-field = some_value.
    MODIFY lt FROM ls WHERE field <> some_value TRANSPORTING field.

    That will change whole table.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 04 at 05:10 AM

    There is a solution using an auxiliary table with a LET expression inside the VALUE constructor operator. See following code:

    TYPES:
      BEGIN OF lst_struct,
        field1 TYPE i,
        field2 TYPE char10,
        field3 TYPE char10,
      END OF lst_struct,
      ltt_table TYPE STANDARD TABLE OF lst_struct WITH DEFAULT KEY.
    
    CONSTANTS: lc_done  TYPE char4 VALUE 'Done'.
    DATA(lt_table) = VALUE ltt_table( ( field1 = 1 field2 = 'Test1' field3 = 'Warnigs' )
                                      ( field1 = 4 field2 = 'Test2' field3 = 'Failed' ) ).
    lt_table = VALUE #( LET lt_temp = lt_table IN FOR ls_temp IN lt_temp
                        ( field1 = ls_temp-field1
                          field2 = ls_temp-field2
                          field3 = lc_done ) ).

    You cannot use the same table because the VALUE operator creates a new table (deletes all existing data) and if you try it with the addition BASE, it will enter in an infinite loop ;)

    Add comment
    10|10000 characters needed characters exceeded