Professional Documents
Culture Documents
Supported by
Today we’ll try to optimize the code to convert a SELECT into a RANGE
Let’s start with the simplest code, without any optimization attempt:
DATA: lt_kunnr TYPE STANDARD TABLE OF kunnr,
SELECT kunnr
FROM kna1.
wa_kunnr-sign = 'I'.
wa_kunnr-option = 'EQ'.
wa_kunnr-low = <kunnr>.
ENDLOOP.
7 commands
4 variabls
15 lines
FROM kna1.
wa_kunnr-sign = 'I'.
wa_kunnr-option = 'EQ'.
MODIFY r_kunnr FROM wa_kunnr TRANSPORTING sign option WHERE low <> ''.
https://abapinho.com/en/2019/11/o-caminho-mais-curto-para-ir-de-select-a-range/ 1/4
2/7/22, 1:28 PM The simplest route to go from SELECT to RANGE - Abapinho
4 commands
2 variables
10 lines
Meanwhile, with ABAP 7.40, manipulating internal tables became much simpler:
DATA r_kunnr TYPE RANGE OF kunnr.
FROM lfa1.
( low = wa-low ) ).
2 commands
1 variables!
9 lines
But then Sérgio Fraga showed me that SQL also got better and now this can be done:
FROM lfa1.
1 command!
1 variable!
5 lines
Not bad! The only possible improvement would be declaring that variable inline. But I don’t know how it could be done.
Update: Gabriel showed that it is indeed possible to declare the variable inline:
FROM lfa1.
It is crucial that all the 4 fields are explicitly listed (HIGH too) in this order for the inline internal table generated to be
considered as a valid RANGE. Thank you Gabriel!
1 command!
0 variables!
3 lines!
The 7 commands, 4 variables and 15 lines are now reduced down to 1 command and 3 lines. I dare say that now it is finally
impossible to further simplify this.
Categories:
artigos
|
Tags:
7.4, estilo
https://abapinho.com/en/2019/11/o-caminho-mais-curto-para-ir-de-select-a-range/ 2/4
2/7/22, 1:28 PM The simplest route to go from SELECT to RANGE - Abapinho
Powered by Remark42
Categories
https://abapinho.com/en/2019/11/o-caminho-mais-curto-para-ir-de-select-a-range/ 3/4
2/7/22, 1:28 PM The simplest route to go from SELECT to RANGE - Abapinho
Archive
Archive
Projects
abapTimeMachine
abaK
Links
Clean ABAP
ABAP Zombie
SAP Yard
Pedro Lima
Guru99
Search
Search...
Português
https://abapinho.com/en/2019/11/o-caminho-mais-curto-para-ir-de-select-a-range/ 4/4