‎2009 Nov 12 6:27 AM
Hi ,
I got to know that Parellel cursor is better that Nested loop. But before that i want to know how WHERE condition is executed in LOOP ENDLOOP. i.e.,
LOOP it_vbak assigning <VBAK> .
LOOP it_VBAP assigning <VBAP> where VBELN eq <vbak>-vbeln.
ENDLOOP.
ENDLOOP.
In the above case does it search from 1 row of it_VBAP table for every record eq vbak vbeln, or how it search the records.
-Rajiv
‎2009 Nov 12 7:09 AM
There is one case where the whole internal table will not be read, you must declare the internal table with a SORTED TYPE using the same keys in the same sequence than in the WHERE CLAUSE.
DATA: it_vbap TYPE SORTED TABLE OF vbap WITH NON-UNIQUE KEY vbeln.
* Or
DATA: it_vbap TYPE SORTED TABLE OF vbap WITH UNIQUE KEY vbeln posnr.Use F1 on LOOP statement on WHERE logexp addition :
When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required.
If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. This optimization requires that the WHERE condition be specified in the form
WHERE k1 = v1 AND k2 = v2 AND ... AND kn = vn
where the components k1, ..., kn are in the same sequence as the beginning of the table key.
If you don't want to use a SORTED TABLE type, SORT the table and begin the LOOP with the index from a READ TABLE BINARY SEARCH, exit the LOOP when the key changes.
SORT it_vbap BY vbeln posnr.
" ...
LOOP it_vbak ASSIGNING <vbak> .
" ...
READ TABLE it_vbap TRANSPORTING NO FIELDS BINARY SEARCH
where vbeln eq <vbak>-vbeln.
IF sy-subrc = 0 .
lv_tabix = sy-tabix.
LOOP it_vbap ASSIGNING <vbap> FROM lv_tabix.
IF <vbap>-vbeln NE <vbak>-vbeln. EXIT. ENDIF.
" ...
ENDLOOP.
ENDIF.
ENDLOOP.Regards,
Raymond
‎2009 Nov 12 6:38 AM
It searches from first row of the record all the time. I don't think it will use evern BINARY SEARCH.
‎2009 Nov 12 6:59 AM
‎2009 Nov 12 7:02 AM
Use following program so that system will not check it_vbap from first record
LOOP it_vbak assigning <VBAK> .
read table it_vbap assigning <vbap> where VBELN eq <vbak>-vbeln.
if sy-subrc = 0 .
lv_tabix = sy-tabix.
LOOP it_VBAP assigning <VBAP> where VBELN eq <vbak>-vbeln from lv_tabix.
ENDLOOP.
ENDLOOP.
‎2009 Nov 12 7:16 AM
Hi Ashwin,
In ur logic suppose 1000 entries are there in VBAP itab we are searching from that Index to last, suppose in for a condition only 2 records may come, then that time it searches from the Index to last, so it may also be unncessary. They what will be the logic
‎2009 Nov 12 7:43 AM
you can put one condition in loop vbap as take one variable vbeln and pass the vbeln each time of the loop itration adn compare the vbeln with next iteration. if it is not equal at 3 rd record write EXIT command.
loop at vbap where vbeln = vbak-vbeln index l_index.
l_vbeln = vbak-vbeln.
l1_vbeln = vbap-vbeln.
if l_vbeln ne l1_vbeln.
exit.
endif.
endloop.
May be this is useful for improve the performace also
‎2009 Nov 12 7:09 AM
There is one case where the whole internal table will not be read, you must declare the internal table with a SORTED TYPE using the same keys in the same sequence than in the WHERE CLAUSE.
DATA: it_vbap TYPE SORTED TABLE OF vbap WITH NON-UNIQUE KEY vbeln.
* Or
DATA: it_vbap TYPE SORTED TABLE OF vbap WITH UNIQUE KEY vbeln posnr.Use F1 on LOOP statement on WHERE logexp addition :
When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required.
If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. This optimization requires that the WHERE condition be specified in the form
WHERE k1 = v1 AND k2 = v2 AND ... AND kn = vn
where the components k1, ..., kn are in the same sequence as the beginning of the table key.
If you don't want to use a SORTED TABLE type, SORT the table and begin the LOOP with the index from a READ TABLE BINARY SEARCH, exit the LOOP when the key changes.
SORT it_vbap BY vbeln posnr.
" ...
LOOP it_vbak ASSIGNING <vbak> .
" ...
READ TABLE it_vbap TRANSPORTING NO FIELDS BINARY SEARCH
where vbeln eq <vbak>-vbeln.
IF sy-subrc = 0 .
lv_tabix = sy-tabix.
LOOP it_vbap ASSIGNING <vbap> FROM lv_tabix.
IF <vbap>-vbeln NE <vbak>-vbeln. EXIT. ENDIF.
" ...
ENDLOOP.
ENDIF.
ENDLOOP.Regards,
Raymond
‎2009 Nov 12 7:41 AM
Hope, following program will solve your concern
sort it_vbap by vbeln.
LOOP it_vbak assigning <VBAK> .
read table it_vbap assigning <vbap> where VBELN eq <vbak>-vbeln binary search.
if sy-subrc = 0 .
lv_tabix = sy-tabix.
LOOP it_VBAP assigning <VBAP> where VBELN eq <vbak>-vbeln from lv_tabix.
if <vbap>-vbeln NE <vbak>-vbeln .
EXIT.
endif.
ENDLOOP.
ENDLOOP.