SAP Range Table

SAP Range Table represents complex selection criteria, it’s data structures is exactly like select-option but without any UI part and header line. In this blog I will explain how to define range table type in program and in dictionary for global use.

First little bit more about range table. When you define a select-option on selection screen you automatically get range table which is attached with that select option. However, if you want to define range table without having to define select option than you need to either define local or global range type. Also you need some mechanism of defining work area so that you can perform usual operation on range table. Range table have four columns SIGN, OPTION, LOW and HIGH.

Column Data Type Possible Value
SIGN CHAR length 1 I – include
E – exclude
OPTION CHAR length 2 EQ – Equal
NE –Not Equal
GE – Greater Than or Equal
GT – Greater Than
LE – Less Than or Equal
LT – Less Than
CP – Contains Pattern
NP –
LOW Data type of selection field Data value. Can also contain wildcards
HIGH Data type of selection field, same as LOW Data value in case of range criteria. Can also contain wildcards
Defining Local Range Type and Line Type to define Range Table

You can use TYPE RANGE OF keyword to define local range of a data type to use in program. Further based on defined range type you can define line type using keyword TYPE LINE OF. Below is an example.


REPORT  zpwtest8.

*--------------------------------------------------------------------*
* Types and Data Definition
*--------------------------------------------------------------------*

* Define local range type for MARA-MATNR
TYPES : tr_matnr  TYPE RANGE OF mara-matnr .

* Define local line type to access lines of range type
TYPES : ty_matnr  TYPE LINE  OF tr_matnr   .


* Define range table and work area
DATA : workarea_material    TYPE ty_matnr ,
       range_table_material TYPE tr_matnr .

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION .

  DATA : lv_matnr TYPE mara-matnr .

  workarea_material-sign   = 'I'  .
  workarea_material-option = 'CP' .
  workarea_material-low    = 'A*' .
  APPEND workarea_material TO range_table_material .

  SELECT matnr
    INTO lv_matnr
    FROM mara
   WHERE matnr IN range_table_material .
    WRITE : / lv_matnr .
  ENDSELECT .
Defining Global Range Type in Dictionary

Go to transaction SE11 and enter the name of Range Table you would like to create in Data type input and press Create.

SAP Range Table Example

On next popup select Table type.

SAP Range Table Example

Enter short test to describe you object and select menu option Edit->Define as range table type.

SAP Range Table Example

Notice change in screen under Line type Tab. Enter Data Element and Structure Row Type and press save. Once its saved press on create button next to Structure Row Type to create structure.

SAP Range Table Example

System will create structure ZWA_MATNR with component SIGN, OPTION, LOW and HIGH based on data element MATNR.

SAP Range Table Example

Save and activate this structure. Now and go back to table type screen and activate that as well. We just created a Range Type ZTAB_MATNR and corresponding row type ZWA_MATNR.

I am going to adapt the code to use these global object.


REPORT  zpwtest8.

*--------------------------------------------------------------------*
* Types and Data Definition
*--------------------------------------------------------------------*
* Define range table and work area
DATA : workarea_material    TYPE zwa_matnr ,
       range_table_material TYPE ztab_matnr .

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION .

  DATA : lv_matnr TYPE mara-matnr .

  workarea_material-sign   = 'I'  .
  workarea_material-option = 'CP' .
  workarea_material-low    = 'A*' .
  APPEND workarea_material TO range_table_material .

  SELECT matnr
    INTO lv_matnr
    FROM mara
   WHERE matnr IN range_table_material .
    WRITE : / lv_matnr .
  ENDSELECT .

Read more

3 Replies to “SAP Range Table

    1. Add two lines to range table

      workarea_material-sign = ‘I’ .
      workarea_material-option = ‘CP’ .
      workarea_material-low = ‘A*’ .
      APPEND workarea_material TO range_table_material .
      workarea_material-low = ‘B*’ .
      APPEND workarea_material TO range_table_material .

  1. what if I want to use CP for low and high both ,
    i.e. in select option I am giving value in low and high both and need to fetch data between these value

Leave a Reply