Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

selecting from BKPF and BSEG

Former Member
0 Kudos
2,007

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

8 REPLIES 8
Read only

Former Member
0 Kudos
399

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.

Read only

jayanthi_jayaraman
Active Contributor
0 Kudos
399

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.

Read only

0 Kudos
399

Seema..

Best things is not to use BSEG always.

instead u can use GLT0, BSID,BSAK

Actually we shud not use BSEG.

Regards

Sheshadri

Read only

Former Member
0 Kudos
399

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.

Read only

Former Member
0 Kudos
399

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

Read only

0 Kudos
399

I am selecting PO documents.

Read only

0 Kudos
399

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

Read only

Former Member
0 Kudos
399

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