‎2007 Aug 21 2:53 PM
Hi,
I have the code below, is there a more efficient way of doing this so it runs faster?
IF NOT xaccit[] IS INITIAL AND NOT cvbrp[] IS INITIAL.
LOOP AT xaccit.
LOOP AT cvbrp.
IF xaccit-posnr_sd = cvbrp-posnr AND NOT xaccit-hkont IS INITIAL.
xaccit-xref1 = cvbrp-zzlblni.
SELECT SINGLE * FROM essr INTO wa_essr WHERE lblni EQ
cvbrp-zzlblni.
IF sy-subrc = 0. "Record match
CONCATENATE wa_essr-lzbis6(2) '.' wa_essr-lzbis4(2)
'.' wa_essr-lzbis(4) INTO week_ending.
xaccit-xref2 = week_ending.
ENDIF.
MODIFY xaccit.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
Don't know if I can do the same thing in a modify statement? or is there a much more clever way of doing it?
‎2007 Aug 21 3:02 PM
Hello
IF NOT xaccit[] IS INITIAL AND NOT cvbrp[] IS INITIAL.
LOOP AT xaccit
<b>where xaccit-hkont IS not INITIAL.</b>
LOOP AT cvbrp
<b>where cvbrp-posnr = xaccit-posnr_sd</b>
xaccit-xref1 = cvbrp-zzlblni.
SELECT SINGLE * FROM essr INTO wa_essr WHERE lblni EQ
cvbrp-zzlblni.
IF sy-subrc = 0. "Record match
CONCATENATE wa_essr-lzbis6(2) '.' wa_essr-lzbis4(2)
'.' wa_essr-lzbis(4) INTO week_ending.
xaccit-xref2 = week_ending.
ENDIF.
MODIFY xaccit.
ENDLOOP.
ENDLOOP.
ENDIF.
‎2007 Aug 21 3:02 PM
Hello
IF NOT xaccit[] IS INITIAL AND NOT cvbrp[] IS INITIAL.
LOOP AT xaccit
<b>where xaccit-hkont IS not INITIAL.</b>
LOOP AT cvbrp
<b>where cvbrp-posnr = xaccit-posnr_sd</b>
xaccit-xref1 = cvbrp-zzlblni.
SELECT SINGLE * FROM essr INTO wa_essr WHERE lblni EQ
cvbrp-zzlblni.
IF sy-subrc = 0. "Record match
CONCATENATE wa_essr-lzbis6(2) '.' wa_essr-lzbis4(2)
'.' wa_essr-lzbis(4) INTO week_ending.
xaccit-xref2 = week_ending.
ENDIF.
MODIFY xaccit.
ENDLOOP.
ENDLOOP.
ENDIF.
‎2007 Aug 22 9:09 AM
please be aware that the optimzation does only help if the tables are sorted tables!
With standard tables the performance will not change at all!
For standard tables you must sort the tables, use read binary search with key for the condition, store the tabix and
loop cvrrp from tabix
<b> if ( cvbrp-posnr ne xaccit-posnr )
exit.
endif.</b>
...
endloop.
So better use sorted tables, the are much simpler to use.
Siegfried
‎2007 Aug 23 12:29 PM
Hii
Try this for Better performance...This will reduce the No of Iterations of Nested loops Tremendously....
DATA : V_tABIX TYPE SY-TABIX.
IF NOT xaccit[] IS INITIAL AND NOT cvbrp[] IS INITIAL.
sort cvbrp by posnr.
LOOP AT xaccit WHERE XACCIT-HKONT IS INITIAL.
READ TABLE CVBRP WITH KEY POSNR = xaccit-posnr_sd
TRANSPORTING NO FIELDS BINARY SEARCH.
IF SY-SUBRC = 0.
V_TABIX = SY-TABIX.
LOOP AT cvbrp FROM V_TABIX.
IF cvbrp-posnr ne xaccit-posnr_sd .
EXIT.
ENDIF.
xaccit-xref1 = cvbrp-zzlblni.
SELECT SINGLE * FROM essr INTO wa_essr WHERE lblni EQ
cvbrp-zzlblni.
IF sy-subrc = 0. "Record match
CONCATENATE wa_essr-lzbis6(2) '.' wa_essr-lzbis4(2)
'.' wa_essr-lzbis(4) INTO week_ending.
xaccit-xref2 = week_ending.
ENDIF.
MODIFY xaccit .
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
<b>Reward if Helpful</b>
‎2007 Aug 24 8:43 AM
Hi,
In your code first you have to be concentrate on performance issues,
1 dont use loop with in loop.
2 dont use select statement with in loop.
So you check the following code which it overcome the issues.
IF NOT cvbrp[] IS INITIAL.
SELECT *
FROM essr
INTO TABLE tbl_essr
FOR ALL ENTRIES IN cvbrp
WHERE lblni EQ cvbrp-zzlblni.
IF sy-subrc = 0.
SORT tbl_essr BY lblni.
ENDIF.
ENDIF.
SORT cvbrp BY posnr.
IF NOT xaccit[] IS INITIAL AND NOT cvbrp[] IS INITIAL.
LOOP AT xaccit NOT hkont IS INITIAL.
CLEAR cvbrp.
READ TABLE cvbrp WITH KEY posnr = xaccit-posnr_sd
BINARY SEARCH.
IF sy-subrc = 0.
xaccit-xref1 = cvbrp-zzlblni.
CLEAR tbl_essr.
READ TABLE tbl_essr WITH KEY lblni = cvbrp-zzlblni
BINARY SEARCH.
IF sy-subrc = 0.
CONCATENATE tbl_essr-lzbis6(2) '.' tbl_essr-lzbis4(2)
'.' tbl_essr-lzbis(4) INTO week_ending.
xaccit-xref2 = week_ending.
ENDIF.
<b>MODIFY xaccit TRANSPORTING xref1 xref2</b>.
ENDIF.
CLEAR xaccit.
ENDLOOP.
ENDIF.
Hope this code is usefull for you if yes reward with points.
Regards,
Vijay