Cold_Class
Cold_Class

Reputation: 3484

Fill range table from itab using LET

I found this code for filling a range table (source is already offline):

DATA   lr_vkorg   TYPE RANGE OF vkorg.
TYPES: lr_range_t TYPE RANGE OF vkorg.

lr_vkorg = VALUE lr_range_t(
          LET s = 'I'
              o = 'EQ'
          IN sign   = s
             option = o
             ( low = '1100' )
             ( low = '1200' )
             ( low = '1300' )
             ( low = '1400' )
             ( low = '1500' )
).

But instead of doing something like this:

( low = '1' )
( low = '2' )
...

I want to fill it with the values of an internal table ['1', '2', ...].
Does anyone have an idea how to do this?

Update: This is how I did it based on the answer:

DATA:
  lt_itab       TYPE TABLE OF string,
  lt_range_itab TYPE RANGE OF string
  .

APPEND '1'  TO lt_itab.
APPEND '2'  TO lt_itab.
APPEND '3'  TO lt_itab.
APPEND '4'  TO lt_itab.

lt_range_itab = VALUE #(
  FOR <ls_itab> IN lt_itab
  ( sign = 'I'
    option = 'EQ'
    low = <ls_itab> )
).

Upvotes: 3

Views: 64543

Answers (2)

Gurunath reddy
Gurunath reddy

Reputation: 31

lr_vkorg = VALUE # ( sign   = 'I'  option = 'EQ' ( low = '1100' ) ( low = '1200' )
             ( low = '1300' ) ( low = '1400' )   ( low = '1500' ) ). 

Upvotes: 3

Suncatcher
Suncatcher

Reputation: 10621

You can declare macro utilizing your declared structures like this:

DEFINE range.
 lr_vkorg = VALUE lr_range_t( BASE lr_vkorg ( sign = 'I' option = 'EQ' low = &1 ) ).
END-OF-DEFINITION.

And then fill your ranges with this one-liner:

range: '1100', '1200', '1300', '1400', '1500', '1600'.

If we speak about filling range from itab, use this statement:

lr_vkorg = VALUE #( FOR ls_vkorg IN gt_vkorg
                  ( sign = 'I'
                    option = 'EQ'
                    low = ls_vkorg-vkorg )
                  ).

Upvotes: 5

Related Questions