Create Range tables using ABAP new syntax

Create Range tables using ABAP new syntax


Range Table Structure

Field

Values

SIGN

‘I’  = Include
‘E’ = Exclude

OPTION

‘EQ’ = Equal
‘BT’  = Between
‘GT’  = Greater than

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' ) ).

Example 2: To create a range table using entries of another internal table 

Assume an internal table LT_KNA1 with customer (KUNNR) entries. Now the range table for customers can be created like below.

lr_kunnr = VALUE #( FOR ls_kna1 IN lt_kna1
                          ( sign   = 'I'      
                            option = 'EQ'
                            low    = ls_kna1-kunnr ) ).

Example 3: To create a range table from the select query

SELECT 'I'    AS sign, 
       'EQ'   AS option, 
        matnr AS low, 
        matnr AS high 
INTO TABLE @DATA(lr_matnr) 
FROM mara.

In the old syntax to achieve the above we have to get records from MARA table first and then loop over the internal table to fill sign, option, low fields and append to another internal table.

Post a Comment

Previous Post Next Post