SAP Range Table

 

Range Table:

When defining 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 defining select option than need to either define local or global range type. Also 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.

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
BT - Between
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
The keyword TYPE RANGE OF keyword to define local range of a data type.Based on defined range type you can define line type using keyword TYPE LINE OF. 

REPORT zvb_range.

*Local range type for VBAK-VBELN
TYPES:tr_vbeln TYPE RANGE OF vbak-vbeln.
*Local line type to access lines of range type
TYPES:ty_vbeln type LINE OF tr_vbeln.
*work area and internal table for range
DATA:rwa_vbeln  TYPE ty_vbeln,
     irt_vbeln TYPE TABLE OF ty_vbeln.

DATA:it_vbeln TYPE TABLE OF vbak-vbeln.

START-OF-SELECTION.
  rwa_vbeln-sign 'I'.
  rwa_vbeln-option 'BT'.
  rwa_vbeln-low '0000000001'.
  rwa_vbeln-high '0000000004'.
  APPEND rwa_vbeln TO irt_vbeln.

  SELECT vbeln
    FROM vbak
    INTO TABLE it_vbeln
  WHERE vbeln IN irt_vbeln.

sort it_vbeln.

  LOOP AT it_vbeln INTO DATA(lr_vbeln).
    WRITE:/ lr_vbeln.
  ENDLOOP.

 

Defining Global Range Type in Dictionary
  •  Goto T-code 'SE11'.
  • Select radio button 'Data Type'.
  • Enter Table type name and click on create.
 
  •  Select radio button table type and press enter.

 

  • Enter short description.
  • Click on 'Edit' Menu item.
  • Click on 'Define as ranges table type'.


  • Enter dataelement.
  • Enter Structured Row Type.
  • Click on 'Save'.
  • Click on create.
  • Enter Short description and replace the LOW and HIGH with the data element.
  • Click on 'BACK'.
  • Save,check and activate.


 Now use this table type to declare ranges for VBELN.

REPORT zvb_range.

*work area and internal table for range
DATA:rwa_vbeln TYPE zst_vbeln,
     irt_vbeln TYPE ztt_vbeln.

DATA:it_vbeln TYPE TABLE OF vbak-vbeln.

START-OF-SELECTION.
  rwa_vbeln-sign 'I'.
  rwa_vbeln-option 'BT'.
  rwa_vbeln-low '0000000001'.
  rwa_vbeln-high '0000000004'.
  APPEND rwa_vbeln TO irt_vbeln.

  SELECT vbeln
    FROM vbak
    INTO TABLE it_vbeln
  WHERE vbeln IN irt_vbeln.

  SORT it_vbeln.

  LOOP AT it_vbeln INTO DATA(lr_vbeln).
    WRITE:/ lr_vbeln.
  ENDLOOP.
 

 

Comments

Popular posts from this blog

CDS Views: Table Functions with Example

Passing Dynamic Variables to SO10 TEXT

Adobe Form/PDF Form Introduction