Easily use ABAP range tables

Straightforwardly use ranges utilizing the latest syntax

Ranges allow for flexible openSQL selections

About ranges

Ranges are internal tables with the same structure as a selection table. They are very useful for flexible reading of database data in ABAP. Range tables always consist of four columns:

SIGNwhether records should be in- or excluded‘I’ = Include
‘E’ = Exclude
OPTIONthe selection operator‘EQ’ = Equal
‘BT’ = Between
‘GT’ = Greater than
LOWthe lower limit of the interval
HIGHthe higher limit of the interval

Convert internal tables to ranges

Since ABAP 7.40 the FOR operator allows simple conversion from internal table to range table, without the need of directly looping over the table.

DATA(lt_matnr_range) = VALUE rsdsselopt_t(
  FOR ls_input_data IN it_input_data
    ( sign =  if_fsbp_const_range=>sign_include
      option = if_fsbp_const_range=>option_equal
      low = ls_input_data-matnr ) ).

To do the opposite and extract data from a range table, use CORRESPONDING together with MAPPING.

lt_data = CORRESPONDING #( lt_matnr_range MAPPING low = matnr ).

Fill ranges directly from SELECT statements

Gone are the days when it was necessary to first select data and then loop over it to fill a range. With the current syntax ranges can be filled directly in the SELECT statement.

SELECT 'I' AS sign, 
       'EQ' AS option, 
       matnr AS low, 
       matnr AS high
  INTO TABLE @DATA(lt_matnr_range)
  FROM mara.
Download a PDF printout of this article
Laurens Deprost
Laurens Deprost
SAP Consultant