Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jun 25, 2010 at 01: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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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