‎2015 Dec 30 11:04 AM
Hi all, I have checked all the forums but i just have a doubt which i need to clarify. My basic requirement is to optimize the abap code which is written in BW Field Routine. I know that we cannot use Relational operator with Read Statement So, if we replace Read Statement with Loop Statement. Will it be same Performance wise. Because what i feel is it will loop multiple times which again will slow down the performance if we have millions records.
Read table ITAB into WA With KEY
F1 = SF-F1
AND F2 = SF-F2
AND F3 > SF-F3.
(ERROR as it does not accept relational Op) RESULT = XYZ.
****************************************************************************************************************************
LOOP AT ITAB ASSIGNING Field Symbol FS WHERE F1 = SF-F1 AND F2 = SF-F2 AND F3 > SF-F3.
RESULT = XYZ.
ENDLOOP.
Or Do we have any other alternative to replace read statement in a better way?
Message was edited by: Matthew Billingham - fixed formatting (to an extent)
‎2015 Dec 30 12:31 PM
Due to the 'greater than' you have to use the LOOP instead of the READ Statement.
Make sure the ITAB is defined as SORTED or HASHED TABLE.
Maybe it is an Option to first delete all entries from ITAB where F3 <= SF-F3.
Then you can use the READ Statement instead of the LOOP.
You have to verify with SAT-Transaction which Version is the better one for your case.
Make also sure that the ITAB structure only contains fields you really Need in further processing.
Having an ITAB with a wide structure and millions of entries will also slow down Performance.
‎2015 Dec 30 11:18 AM
I don't know about the BW field routine, but the read you are using there is for a standard table.
If you are certain that your table does not have duplicate keys you can define it as a hashed table and read it using the 'WITH TABLE KEY' clause of the READ statement.
Mind you, if you have millions of records you will always have some sort of a delay.....
‎2015 Dec 30 12:31 PM
Due to the 'greater than' you have to use the LOOP instead of the READ Statement.
Make sure the ITAB is defined as SORTED or HASHED TABLE.
Maybe it is an Option to first delete all entries from ITAB where F3 <= SF-F3.
Then you can use the READ Statement instead of the LOOP.
You have to verify with SAT-Transaction which Version is the better one for your case.
Make also sure that the ITAB structure only contains fields you really Need in further processing.
Having an ITAB with a wide structure and millions of entries will also slow down Performance.
‎2015 Dec 30 2:15 PM
‎2015 Dec 30 2:24 PM
‎2015 Dec 30 2:40 PM
You can simply EXIT loop after you find first line which meet WHERE criteria.
LOOP AT itab WHERE a > b.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
"found
ELSE.
"not found
ENDIF.
READ also searches whole table until it finds resulting line.
If you have performance problem with that. Then use different kind of itab as already suggested, set itab key/s....
‎2015 Dec 30 2:56 PM
Since this thread is now attracting incorrect answers, I've decided to lock it. The answer has been given
1. Use a SORTED or HASHED table, with key as defined as F1 F2
2. Put an EXIT before the ENDLOOP
3. Check sy-subrc after the ENDLOOP. If it is non-zero then no record was found