06-25-2010 1:42 PM
I read that instead of using BSEG, using index tables BSIS & BSA, we can improve performance. We have a old code in our system and I tried to modify using BSIS & BSAS... but my changes are taking more time than the old code.
Old:
loop at TEMPBKPF.
Keep index
tmpidx = sy-tabix.
Transfering Sy-MANDT value.
TEMPBKPF-MANDT = SY-MANDT.
select BUKRS "Company Code
BELNR "Accounting document number
GJAHR "Fiscal year
BUZEI "Number of Line Item Within Accounting
"Document
SHKZG "Debit/credit indicator
DMBTR "Amount in local currency
SGTXT "Item Text
KOSTL "Cost Center
HKONT "General ledger account
PRCTR "Profit Center
into (tempbseg-bukrs,
tempbseg-belnr,
tempbseg-gjahr,
tempbseg-buzei,
tempbseg-shkzg,
tempbseg-dmbtr,
tempbseg-sgtxt,
tempbseg-kostl,
tempbseg-hkont,
tempbseg-prctr)
from BSEG "[Accounting Document Segment]
where BUKRS = tempbkpf-bukrs "Company Code
and GJAHR = tempbkpf-gjahr "Fiscal year
and BELNR = tempbkpf-belnr. "Accounting document Number.
TEMPBSEG-MANDT = SY-MANDT.
append TEMPBSEG.
Updating TEMPBKPF internal table.
endselect.
modify tempbkpf index tmpidx.
endloop.
My Code:
I replaced the loop with FOR ALL ENTRIES & used BSIS & BSAS
access the index tables, for each record in bseg
SELECT bukrs
hkont
gjahr
belnr
buzei
shkzg
dmbtr
sgtxt
kostl
prctr
INTO TABLE i_bsis
FROM bsis
FOR ALL ENTRIES IN i_bkpf[]
WHERE bukrs EQ i_bkpf-bukrs " Company Code
AND gjahr EQ i_bkpf-gjahr " Fiscal year
AND belnr EQ i_bkpf-belnr. " Accounting document Number.
IF sy-subrc EQ 0.
SORT i_bsis.
ENDIF.
SELECT bukrs
hkont
gjahr
belnr
buzei
shkzg
dmbtr
sgtxt
kostl
prctr
INTO TABLE i_bsas
FROM bsas
FOR ALL ENTRIES IN i_bkpf[]
WHERE bukrs EQ i_bkpf-bukrs " Company Code
AND gjahr EQ i_bkpf-gjahr " Fiscal year
AND belnr EQ i_bkpf-belnr. " Accounting document Number.
IF sy-subrc EQ 0.
SORT i_bsas.
ENDIF.
Finally, I will loop through both these itabs and build my final itab.
Any thoughts please.
Thanks,
Kiran
06-25-2010 2:58 PM
I don't know where you read that you should avoid BSEG and use BSIS and BSAS instead, but you should have read instead.
You can also have a look at [Performance - what will kill you and what will leave you with only a flesh wound|/people/rob.burbank/blog/2006/11/16/performance--what-will-kill-you-and-what-will-leave-you-with-only-a-flesh-wound]
A SELECT/ENDSELECT within a loop is something we generally try to avoid, but in your old code, it was using the primary key; in the new code, it is using two SELECTS with at best a secondary index (depending on your release). Then you LOOP through both table to create a final table. But both BSIS and BSAS have the same structure. You could have used the APPENDING option on the second SELECT and avoided some extra work (both programming and execution time).
Finally, depending on what you are trying to do, you will be missing any line items against customers and vendors. BSIS and BSAS have only GL items.
Rob
Edited by: Rob Burbank on Jun 25, 2010 9:59 AM
06-25-2010 2:58 PM
I don't know where you read that you should avoid BSEG and use BSIS and BSAS instead, but you should have read instead.
You can also have a look at [Performance - what will kill you and what will leave you with only a flesh wound|/people/rob.burbank/blog/2006/11/16/performance--what-will-kill-you-and-what-will-leave-you-with-only-a-flesh-wound]
A SELECT/ENDSELECT within a loop is something we generally try to avoid, but in your old code, it was using the primary key; in the new code, it is using two SELECTS with at best a secondary index (depending on your release). Then you LOOP through both table to create a final table. But both BSIS and BSAS have the same structure. You could have used the APPENDING option on the second SELECT and avoided some extra work (both programming and execution time).
Finally, depending on what you are trying to do, you will be missing any line items against customers and vendors. BSIS and BSAS have only GL items.
Rob
Edited by: Rob Burbank on Jun 25, 2010 9:59 AM
06-25-2010 4:38 PM
Thank you Rob.
Adding APPENDING in BSAS select has increased the execution. I commented out the 2nd loop on BSAS also.
Thanks,
Kiran
06-25-2010 4:43 PM
So which is faster (and by how much), the original code or the new code??
There is absolutely nothing wrong with retrieving data from BSEG. Unless I was looking for work to do, I would have left the original code alone. If I had to make a change, I would have converted the original SELECT/ENDSELECT on BSEG into a FOR ALL ENTRIES, but still on BSEG.
Going against BSIS and BSAS may not help and may do damage by not retrieving all data.
It's a risk/remard thing.
And please use code tags to format code.
Rob
Edited by: Rob Burbank on Jun 25, 2010 11:44 AM
Edited by: Rob Burbank on Jun 25, 2010 11:48 AM
06-25-2010 5:30 PM
Making change sto the original code is better. So am not using BSIS & BSAS as am not able to capture the entire primary key.
I have no risk as am capturing only GL data and I verified the data both ways and am getting the same data.
Thanks Rob.
Regards,
Kiran