|
|
RANGE statement - Example ABAP code to demonstrate the RANGE command
The 'type range of' statement is very useful when writing ABAP programs allowing you to restrict the retrieval of data
when performing a database select statement. It basically replicates the restriction abilities of the report select-option.
Below are a few examples of the various ways of populating and using a range table.
*Code to demonstrate populating and using range tables
*&-------------------------------------------------------------*
*& Report ZRANGESTATEMENT
*&
*&-------------------------------------------------------------*
REPORT ZRANGESTATEMENT.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
data: r_ebeln type range of ekko-ebeln, "range table
wa_ebeln like line of r_ebeln. "work area for range table
**********************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
************************************************
**** populate range table to receive all entries
refresh r_ebeln.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
from ekpo
into table it_ekko
where ebeln in r_ebeln.
****
***************************************************
**** populate range table to receive specific value
wa_ebeln-sign = 'I'. "I = include, E = exclude
wa_ebeln-option = 'EQ'. "EQ, BT, NE ....
wa_ebeln-low = '12345678'.
*wa_ebeln-high = "not needed unless using the BT option
append wa_ebeln to r_ebeln.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
from ekpo
into table it_ekko
where ebeln in r_ebeln.
****
***********************************************************
**** populate range table to receive entries within a range
wa_ebeln-sign = 'I'. "I = include, E = exclude
wa_ebeln-option = 'BT'. "EQ, BT, NE ....
wa_ebeln-low = '11111111'.
wa_ebeln-high = '99999999'.
append wa_ebeln to r_ebeln.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
from ekpo
into table it_ekko
where ebeln in r_ebeln.
****
|