04-08-2008 3:35 PM
Hi,
I wrote an function module where I access the table BSEG. It works fine so far, but I have a big performance problem. Has anybody an idea how I can improve the performance? I'm quite new to ABAP, so I would really appreciate your help.
select * from bseg
into table itab_bseg
where bukrs = perdat-bukrs
*nur Belege deren Nummer mit 5 beginnt
and belnr like '0005%'
*das Sachkonto selektieren
and hkont = '0000474800'
*Zuordnungsnummer ist mit Reisenummer gefüllt
and zuonr like search_zuonr.
clear itab_bseg_kum.
*Falls zu einer Reise mehrere FI Belege
*diese addieren (kommt vor bei mehreren PSP-Elementen)
loop at itab_bseg into wa_bseg.
move-corresponding wa_bseg to wa_bseg_kum.
collect wa_bseg_kum into itab_bseg_kum.
endloop.
loop at itab_bseg_kum into wa_bseg_kum.
wa_perdiems_head-mandt = wa_ptrv_perio-mandt.
wa_perdiems_head-pernr = wa_ptrv_perio-pernr.
wa_perdiems_head-reinr = wa_ptrv_perio-reinr.
wa_perdiems_head-zuonr = wa_bseg_kum-zuonr.
wa_perdiems_head-belnr = wa_bseg_kum-belnr.
wa_perdiems_head-sgtxt = wa_bseg_kum-sgtxt.
wa_perdiems_head-dmbtr = wa_bseg_kum-wrbtr.
wa_perdiems_head-ename = perdat-ename.
*Währungsschlüssel holen
select waers from bkpf
into wa_perdiems_head-waers
where belnr = wa_bseg_kum-belnr
and gjahr = wa_bseg_kum-gjahr
and bukrs = wa_bseg_kum-bukrs.
endselect.
Thanks in advance,
Martin
04-08-2008 3:43 PM
Hi Martin,
if you look around you will find lots of posts here that deal with similar problems on selecting BKPF and BSEG.
Since you're selecting only one G/L account I suggest you read BSIS and BSAS instead of BSEG.
By the way, hardcoding literals is never a good idea...
Cheers
Thomas
04-08-2008 3:40 PM
Try using the standard index tables of BSEG. They are indexed by a few criteria.
Cleared items:
BSAD Accounting: Secondary Index for Customers (Cleared Items)
BSAK Accounting: Secondary Index for Vendors (Cleared Items)
BSAS Accounting: Secondary Index for G/L Accounts (Cleared Items)
Non-cleared items:
BSID Accounting: Secondary Index for Customers
BSIK Accounting: Secondary Index for Vendors
BSIM Secondary Index, Documents for Material
BSIP Index for Vendor Validation of Double Documents
BSIS Accounting: Secondary Index for G/L Accounts
Regards,
Santosh
04-08-2008 3:43 PM
Hi Martin,
if you look around you will find lots of posts here that deal with similar problems on selecting BKPF and BSEG.
Since you're selecting only one G/L account I suggest you read BSIS and BSAS instead of BSEG.
By the way, hardcoding literals is never a good idea...
Cheers
Thomas
04-08-2008 3:56 PM
One point where you can increase performance is, after the Select Query on BSEG,
for fetching the currency from BKPF,
write a single query,
Data: Begin of itab_bkpf occurs 0,
belnr..,
gjahr..,
bukrs..,
waers..,
Endof itab_bkpf.
If itab_bseg[] is not initial.
Select belnr gjahr bukrs waers from bkpf
into table itab_bkpf
for all entries in itab_bseg_kum
where belnr = itab_bseg_kum-belnr
and gjahr = itab_bseg_kum-gjahr
and bukrs = itab_bseg_kum-bukrs.
Endif.
Sort itab_bseg by BELNR GJAHR BUKRS.
In the Loop if you want to fetch the currency of BKPF,you can try
Loop at itab_bseg_kum into wa_bseg_kum.
<code>...
Read table itab_bkpf into wa_bkpf with key belnr = wa_bseg_kum-belnr
gjahr = wa_bseg_kum-gjahr
bukrs = wa_bseg_kum-bukrs
Binary Search.
<code>...
Endloop.
Here you will be hitting the database only once to fetch all the records of itab_bseg_kum unlike the Select EndSelect statement where you will have to hit the database as many times as the no. of records in the table itab_bseg_kum.
04-10-2008 3:16 PM
Hi,
In cluster tables like bseg is not good select data using not key fields in "Where" conditions.
So it's better to use only key fields "BUKRS", "BELNR" in the select statement and then you can use DELELE statement to others fields.
regards,
Fernando