Wednesday - last edited Wednesday
Do you know if the below LOOP AT will be optimized and fast?
CLASS ltc_test DEFINITION
FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
METHODS test FOR TESTING.
TYPES ty_itab TYPE SORTED TABLE OF i WITH NON-UNIQUE KEY table_line.
CLASS-DATA itab TYPE ty_itab.
CLASS-METHODS class_setup.
ENDCLASS.
CLASS ltc_test IMPLEMENTATION.
METHOD class_setup.
DATA(integer_generator) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
min = 1
max = 1000000 ).
itab = VALUE #( FOR i = 1 WHILE i <= 1000000
( integer_generator->get_next( ) ) ).
ENDMETHOD.
METHOD test.
DO 20 TIMES.
LOOP AT itab TRANSPORTING NO FIELDS
WHERE table_line BETWEEN 250000 AND 300000.
ENDLOOP.
ENDDO.
ENDMETHOD.
ENDCLASS.
Thanks
Sandra
Request clarification before answering.
The optimization of LOOP AT has been improved in ABAP 7.58 to support BETWEEN, >, >=, <, <=.
EDIT May 11th, 2025, concerning ABAP 7.58:
Before ABAP 7.58, the optimization used to work only with = and AND, so BETWEEN was not optimized.
References of WHERE optimization in ABAP Keyword Documentation:
EDIT: for information, I did a performance measurement on two systems, average on several runs:
To make sure that the "CPU" speed is the same on both systems, I could verify that the average speed is the same for the below adaptation (WHERE with "=" should run identically in both ABAP systems), which is around 1.3 seconds:
DO 1000000 TIMES.
LOOP AT itab TRANSPORTING NO FIELDS
WHERE table_line = 250000.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
(deleted)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
18 | |
10 | |
8 | |
7 | |
4 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.