Range Tables in ABAP
Learn how to build ABAP range tables directly from an SQL SELECT using FIELDS with CAST, replacing the traditional LOOP approach.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"Old way
DATA: lr_salesorder TYPE RANGE OF vbeln.
SELECT vbeln FROM vbak WHERE kunnr = '0000000272' INTO TABLE @DATA(lt_customers_orders).
"Loop
LOOP AT lt_customers_orders INTO DATA(ls_customer_order).
"....
ENDLOOP.
"For
lr_salesorder = VALUE #( FOR ls_order IN lt_customers_orders (
sign = 'I'
option = 'EQ'
low = ls_order-vbeln ) ).
"New way
SELECT FROM vbak
FIELDS 'I' AS sign,
'EQ' AS option,
vbeln AS low,
CAST( @space AS CHAR( 10 ) ) AS high
WHERE kunnr = '0000000272'
INTO TABLE @DATA(lr_salesorder).
"Logic with lr_saleorder
This post is licensed under CC BY 4.0 by the author.