2014 Nov 25 1:05 PM
Hi All,
What is the best way to optimize the below code .
SELECT kunnr
bukrs
FROM knb1
INTO TABLE Zcustomerdata
WHERE kunnr IN Zkunnr
AND bukrs IN Zbukrs.
LOOP AT Zcustomerdata INTO lwa_customerdata.
CALL FUNCTION 'BAPI_AR_ACC_GETSTATEMENT'
EXPORTING
companycode = lwa_customerdata-companycode
customer = lwa_customerdata-customer
date_from = lv_bapifrmdt
date_to = sy-datum
IMPORTING
return = lwa_bapireturn
TABLES
lineitems = Zlineitems.
LOOP AT Zlineitems INTO lwa_lineitems WHERE ( doc_type EQ 'DZ' or doc_type EQ 'ZP' )
AND entry_date in so_date and post_key NE '07'." lv_frodat
IF NOT lwa_lineitems-INV_REF IS INITIAL.
IF lwa_lineitems-nxt_doctyp = 'Z'.
*--Looping on the Invoice Document Number
LOOP AT Zlineitems INTO lwa_lineitems2 WHERE ( doc_type IN so_blart AND doc_no = lwa_lineitems-inv_ref) .
-----
---- " Calculations
-----
endloop
endloop
endloop
2014 Nov 25 1:16 PM
Hi Rachel,
Insted of using loop statement use READ Statement with binary search by sorting the primary key fields.
it is condition that you must want to use nested loop then go for parallel cursor concept.
Hope useful,
Regards,
sudheer
2014 Nov 25 1:19 PM
I would suggest you to go with Parallel cursor and Parallel processing technique
2014 Nov 26 7:38 AM
Please check whether this is what u had suggested.
SELECT bukrs kunnr
FROM knb1
INTO corresponding fields TABLE Zcustomerdata
WHERE kunnr IN Zkunnr
AND bukrs IN Zbukrs.
Sort Zcustomerdata by bukrs kunnr.
LOOP AT Zcustomerdata INTO lwa_customerdata.
CALL FUNCTION 'BAPI_AR_ACC_GETSTATEMENT'
EXPORTING
companycode = lwa_customerdata-companycode
customer = lwa_customerdata-customer
date_from = lv_bapifrmdt
date_to = sy-datum
IMPORTING
return = lwa_bapireturn
TABLES
lineitems = Zlineitems.
Sort Zlineitems by bukrs kunnr.
read Zlineitems INTO lwa_lineitems with key kunnr = lwa_customerdata–kunnr
bukrs = lwa_customerdata–bukrs
binary search.
if sy-subrc = 0.
Zindex = sy-tabix.
LOOP AT Zlineitems INTO lwa_lineitems from Zindex
WHERE ( doc_type EQ 'DZ' or doc_type EQ 'ZP' )
AND entry_date in so_date and post_key NE '07'."
IF NOT lwa_lineitems-INV_REF IS INITIAL.
IF lwa_lineitems-nxt_doctyp = 'Z'.
*--Looping on the Invoice Document Number ( DO i need to for the below loop as well ??????)
LOOP AT Zlineitems INTO lwa_lineitems2 WHERE ( doc_type IN so_blart AND doc_no = lwa_lineitems-inv_ref) .
-----
---- " Calculations
-----
endloop
endloop
endloop
2014 Nov 26 8:04 AM
You could try to optimize/parallelize the execution of BAPI using some CALL FUNCTION - STARTING NEW TASK {CALLING meth}|{PERFORMING subr} ON END OF TASK DESTINATION IN GROUP {group|DEFAULT}.
/OR/
Don’t use the BAPI,
Analyze it and read KNC1 and BSID/BSAD tables to get the same result.
Regards,
Raymond