Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Surprising results on BSEG

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

Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question