Create Range tables using ABAP new syntax
Range Table Structure
Field |
Values |
SIGN |
‘I’ = Include |
OPTION |
‘EQ’ = Equal |
LOW |
the lower
limit of the interval |
HIGH |
the higher
limit of the interval |
The range table is used with select query where conditions to fetch the records from table and also with loops, logical checks like if records meet certain criteria. With the introduction of new syntax in ABAP, creating and populating range table is easy.
In the old syntax to create a range table we must create a
work area with selopt or range of type and then fill sign, option, low and high
fields and then append it to range internal table. Same functionality can be
achieved using new syntax with less code.
Example 1: To create and populate range table from constants
TYPES lr_bukrs_type TYPE RANGE OF bukrs. DATA : lr_bukrs_01 TYPE lr_bukrs_type, "Table 1 DATA(lr_bukrs_01) = VALUE lr_bukrs_type( sign = 'I' option = 'EQ' ( low = '01' ) ( low = '02' ) ( low = '03' ) ( low = '04' ) ( low = '05' ) ( low = '06' ) ( low = '07' ) ).
lr_kunnr = VALUE #( FOR ls_kna1 IN lt_kna1 ( sign = 'I' option = 'EQ' low = ls_kna1-kunnr ) ).
SELECT 'I' AS sign, 'EQ' AS option, matnr AS low, matnr AS high INTO TABLE @DATA(lr_matnr) FROM mara.