2005 Jun 27 4:48 AM
Hi all,
Can someone help me optimize the performance of this code as i don't know how else to select from BSEG as i cannot use a join coz its a cluster table. I need to find a way to improve the perfomance.Any help would be much appreciated.
SELECT belnr gjahr bukrs budat stblg awkey blart
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE t_bkpf
WHERE belnr IN s_belnr and
gjahr = p_gjahr and
bukrs = p_bukrs.
LOOP AT t_bkpf.
SELECT belnr gjahr buzei ebeln ebelp
wrbtr fipos geber fistl fkber
augbl augdt shkzg
INTO CORRESPONDING FIELDS OF table t_bseg
FROM bseg
WHERE belnr = t_bkpf-belnr
AND gjahr = t_bkpf-gjahr
AND bukrs = t_bkpf-bukrs.
Thanks alot
seema
2005 Jun 27 5:13 AM
Hi Seema,
If the fields declared in the internal table are in the order of the data that is extracted from the database then u can remove 'INTO CORRESPONDING FIELDS OF' because that will eat a lot of database time.
Secondly, You can remove loop at t_bkpf and use the option 'FOR ALL ENTRIES IN ITAB'.
i.e
SELECT belnr gjahr buzei ebeln ebelp
wrbtr fipos geber fistl fkber
augbl augdt shkzg
for all entries in t_bkpf
INTO CORRESPONDING FIELDS OF table t_bseg
FROM bseg
WHERE belnr = t_bkpf-belnr
AND gjahr = t_bkpf-gjahr
AND bukrs = t_bkpf-bukrs.
Hope this helps.
Sharath.
2005 Jun 27 5:34 AM
Hi Seema,
You have to avoid the database retrival inside the loop.You can use for all entries.
This is taken from a link.
Some of the SAP tables are not transparant, but pooled or clustered. Be aware of this !
There are a lot of limitations on how such tables can be accessed. You can not include such
tables in database views and join constructs. The FI-GL table BSEG, which is one of our
biggest PR1 tables, is an example of a clustered table. At the database-level, there is no table
called BSEG, but instead RFBLG is being used for the BSEG data. Most of the fields known
in BSEG are not known in the database table RFBLG, but are compressed in a VARDATA
field of RFBLG. So tests in the WHERE clause of SELECTs agains BSEG are not used by
the database (e.g. lifnr = vendor account number, hkont = G/L account, kostl = cost center).
As a consequence, these tests are done after the facts similar to using the CHECK statement,
and as already said in tip 1, CHECK statements are worse than tests in the WHERE-clause.
Check this link also.
you'll never select table bkpf alone.
alternatives:
1) select with header information from bkpf
2) use secondary index tables
3) use logical data base e.g.: BRF
Hope this helps.If so,reward points.Otherwise, get back.
2005 Jun 27 10:19 AM
Seema..
Best things is not to use BSEG always.
instead u can use GLT0, BSID,BSAK
Actually we shud not use BSEG.
Regards
Sheshadri
2005 Jun 27 10:34 AM
Hi,
Dont use select with in a loop.
Do as below.
SELECT belnr gjahr bukrs budat stblg awkey blart
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE t_bkpf
WHERE belnr IN s_belnr and
gjahr = p_gjahr and
bukrs = p_bukrs.
CHECK NOT t_bkpf[] IS INITIAL.
SELECT belnr gjahr buzei ebeln ebelp
wrbtr fipos geber fistl fkber
augbl augdt shkzg
INTO CORRESPONDING FIELDS OF table t_bseg
FROM bseg
WHERE belnr = t_bkpf-belnr
AND gjahr = t_bkpf-gjahr
AND bukrs = t_bkpf-bukrs.
Loop at t_bkpf into w_bkpf.
MOVE-CORRESPONDING w_bkpf TO w_output.
READ TABLE t_bseg INTO w_bseg
WITH KEY
bukrs = w_bkpf-bukrs
belnr = w_bkpf-belnr
gjahr = w_bkpf-gjahr
koart = 'K'.Do as per ur req.
IF sy-subrc = 0.
w_output-shkzg = w_bseg-shkzg.
w_output-wrbtr = w_bseg-wrbtr.
w_output-lifnr = w_bseg-lifnr.
APPEND w_output TO i_output.
ENDIF.
CLEAR: w_bkpf,
w_bseg.
ENDLOOP.
U can do as below.
This wont give any performance issue.
Hope this helps.
Thanks & Regards,
Judith.
2005 Jun 27 3:20 PM
You are not being selective enough on your select statement on BKPF. If you can limit your selections by document number there, it will go much more quickly. You can get the document number depending on your detailed requirements:
Are you selecting just CO or PC docuements?
Are you selecting by customer/vendor or GL?
Open or cleared items?
If so, you can get the document number from another table before going to BKPF.
Rob
2005 Jun 28 9:18 AM
2005 Jun 28 9:56 AM
Hi,
so if you've the Purchasing Document Number,
you can 1st select table <b>ekbe</b> .
-> with fields gjahr belnr buzei and bukrs (from table ekko) you can use "select single ..." from bkpf / bseg
regards Andreas
2005 Jun 28 3:39 PM
How do you know which POs to select - selections screen or other requirement. If they're from the selection screen, yes go to EKBE and then EKKO or EKPO to get the FI document; however, if you try to select all POs from EKKO, you're going to run into the same problem as before.
Rob