Application Development 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: 

Selecting BKPF and BSEG

Former Member
0 Kudos

Hello!

I need to make a simple report program that will display all journal entries based on Posting Date Range.

So for example, user will enter 2006.01.03, I will select document nos. from BKPF based on posting date, then select each line item from BSEG. Then I will print them on the screen.

So I now have two loops, one bye selecting each line item per document from BSEG then by printing them..

As we know, these are a lot of records! Haha.

So when I select even just a week, it takes so long..

How can I optimize this?

Thanks!

3 REPLIES 3

amit_khare
Active Contributor
0 Kudos

Since you are using BSEG (Cluster Table) its hard to get good performance.

Still try to pass all key fields in SELECT statement and also in the same order as they are appearing in the table.

Try to resctrict the number of esxtracted records as far as possible.

Regards,

Amit

Reward all helpful replies.

ThomasZloch
Active Contributor
0 Kudos

Hi Ricardo,

I had to do this access many times and here is what worked best for me:

1) select BUKRS, BELNR, GJAHR plus other fields you need on the list from BKPF into an internal table (header), selecting by BUKRS, BUDAT as per user selection and BSTAT = SPACE (I assume you want those "real" docs only, not parked ones etc.). This will use index BKPF~2.

2) select BUKRS, BELNR, GJAHR plus other needed fields from BSEG FOR ALL ENTRIES in that header table (comparing BUKRS, BELNR, GJAHR ) into another internal table (items)

3) loop at the items table and read the corresponding header table entry (by BUKRS, BELNR and GJAHR), inside that loop write your list or fill yet another table for ALV output

Make sure you're using sorted internal tables without header lines and access them by field symbols or "reference into". Select only those fields necessary for output. If the internal tables grow too large then restrict the posting posting date selection range.

Cheers

Thomas

Former Member
0 Kudos

Hi,

Hey why are u using directly BSEG and BKPF. Instead u can use BS* tables. like BSIS, BSIK, etc here u will get all info. DONT go for BKPF and BSEG directly unless it is mentioned mandatory. anyway i m giving procedure to get records from BKPF and BSEG

BKPF and BSEG are cluster table so u can not use JOINs on these tables as usual data will be too high, here are few guidlines that will help to impver the performance.

logic will like this:

select f1 f2 from bkpf into table itab_bkpf where <contn>.


if itab_bkpf is not inital.

select f1 f2 from bseg  into table itab_bseg
for all entries in itab_bkpf
where vbel = itab_bkpf-vbeln and posnr ==......

loop at itab_bseg.
read itab_bkpf with key vbeln = itab_bseg.... BINARY SEARCH.
if sy-subrc = 0.
"process here
endif.
endloop. 

do not use loop inside loop to read table, instead use read stmt with BINARY SEARCH. this will improve performance...

Jogdand M B

Message was edited by:

Jogdand M B