spatium tech
← Tutorials ABAP
ABAP RANGE LOOP FOR
June 15, 2026

FILL RANGE TABLES IN ABAP

spatium tech
1 min
article

Often we need to create dynamic filters using Ranges. But do you still program as if it were the 2000s?

Forget the obsolete RANGES with Header Line! Today, mastering the evolution of the language is synonymous with clean code and performance. Check out these 2 modern ways to solve the problem:

1 - The State of the Art: Modern (VALUE + FOR)

Ideal for solving everything in a single expression, keeping the code clean and direct.

    DATA lt_carr_id_range TYPE RANGE OF spfli-carrid.
    
    lt_carr_id_range = VALUE #( FOR <fs_spfli> IN lt_spfli
                               ( sign   = 'I'
                                 option = 'EQ'
                                 low    = <fs_spfli>-carrid ) ).

2 - The Essential Hybrid: Classic (LOOP + APPEND VALUE)

The well-known loop structure, but updated: the APPEND VALUE eliminates the need to declare a Work Area.

DATA lt_carr_id_range TYPE RANGE OF spfli-carrid.

LOOP AT lt_spfli INTO DATA(ls_spfli).
  APPEND VALUE #( sign   = 'I'
                  option = 'EQ'
                  low    = ls_spfli-carrid ) TO lt_carr_id_range.
ENDLOOP.

GOLDEN TIP: In method 1, if you don't want to declare the range variable on the line above, you can use inline declaration by creating a local or global type, like this:

DATA(lt_range) = VALUE range_type( ... )

Fewer lines of code, more productivity!

And you, which of these two forms do you use most in your daily routine?

Rate this content

to rate

Comments

0
Be the first to comment.
Log in to comment
New posts straight to you
Sign up for free. No spam, just content.