Hi All,
I am facing a big performance issue in a abap program which produce the cash flow details our group of company. This is the logic I used to develop the report. (It is a SAP Script)
- First I am getting the closed customer payment records from the table BSAD ( eg: - Type 'DZ')
- Then I am getting the corresponding invoices from the BSAD using the same BELNR ( eg :- Type <> 'DZ')
- Then checking the GL Entry (BSIS) for the corresponding records which select in the second stage.
- In a Z table I am keeping the account list by grouping separate section ( Eg: - Customer receipts, fixed assets...etc).
I have done the same thing to get the open item details also.
Report is correct and running perfectly, but my issue is it's taking long time to process. Because of this I made this report to run as a background job. But still it is taking such a long time. ( For Eg: - If 1000 records selected from the first stage, it will take about more than one hour to process, which is not good enough to run in a live environment)
Pls advice me how to improve the performance of this.
Here is a code sample how to see how I have make the logic
SELECT SUM( dmbtr ) AS dmbtr belnr kunnr hkont shkzg xblnr budat blart bldat INTO CORRESPONDING FIELDS OF TABLE it_voucher3 FROM bsad WHERE bukrs = p_bukrs AND gjahr = p_gjahr AND augdt IN s_bldat AND blart = 'DZ' * AND blart = 'DZ' and shkzg = 'S' GROUP BY kunnr belnr hkont shkzg xblnr budat blart bldat. SORT it_voucher3 BY kunnr. LOOP AT it_voucher3 INTO wa_voucher3. * Select the invoices SELECT SUM( dmbtr ) AS dmbtr belnr kunnr hkont shkzg xblnr budat blart bldat INTO CORRESPONDING FIELDS OF TABLE it_voucher1 FROM bsad WHERE bukrs = p_bukrs AND gjahr = p_gjahr AND augdt IN s_bldat AND blart <> 'DZ' AND augbl = wa_voucher3-belnr AND kunnr = wa_voucher3-kunnr GROUP BY belnr kunnr hkont shkzg xblnr budat blart bldat. LOOP AT it_voucher1 INTO wa_voucher1. * Find the corresponding entry in the GL open SELECT SINGLE dmbtr FROM bsis INTO w_Rcptamt WHERE * hkont = '0010003900' AND hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE = 'XX001' ) AND bukrs = p_bukrs AND gjahr = p_gjahr AND belnr = wa_voucher1-belnr. IF sy-subrc <> 0. * If the corresponding entry not found in GL open, look in the GL Closed SELECT SINGLE dmbtr FROM bsas INTO w_Rcptamt WHERE hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE = 'XX001' ) AND bukrs = p_bukrs AND gjahr = p_gjahr AND belnr = wa_voucher1-belnr. IF sy-subrc = 0. w_Netamt = w_Netamt + w_Rcptamt. continue. ENDIF. ELSE. w_Netamt = w_Netamt + w_Rcptamt. continue. ENDIF. ************************************************************************ * Interest Income SELECT SINGLE dmbtr FROM bsis INTO w_IntIncomeAmt WHERE hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE = 'XX002' ) AND bukrs = p_bukrs AND gjahr = p_gjahr AND belnr = wa_voucher1-belnr. IF sy-subrc <> 0. * If the corresponding entry not found in GL open, look in the GL Closed SELECT SINGLE dmbtr FROM bsas INTO w_IntIncomeAmt WHERE hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE = 'XX002' ) AND bukrs = p_bukrs AND gjahr = p_gjahr AND belnr = wa_voucher1-belnr. IF sy-subrc = 0. w_IntIncome = w_IntIncome + w_IntIncomeAmt. continue. ENDIF. ELSE. w_IntIncome = w_IntIncome + w_IntIncomeAmt. continue. ENDIF. ************************************************************************