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: 

link between bkpf and bseg

Former Member
0 Kudos
4,656

hi experts

i have the following scenario.

Except belnr, is there any unique key to link bkpf and bseg.

Thanks in advance.

Regards

Rajaram

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,173

Hi,

<b>bukrs,belnr,gjahr</b> thease fileds are common for BKPF and BSEG.

Try something like this:

data: begin of tbl_bkpf occurs 0,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

gjahr like bkpf-gjahr,

end of tbl_bkpf.

data: begin of tbl_bseg occurs 0,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

gjahr like bkpf-gjahr,

end of tbl_bseg.

select bukrs belnr gjahr

into table tbl_bkpf

from bkpf

where belnr in s_belnr. "Insert parameters here

check sy-subrc eq 0.

select belnr

into table tbl_bseg

from bseg

for all entries in table tbl_bkpf

where bukrs = tbl_bkpf-bukrs and

belnr = tbl_bkpf-belnr and

gjahr = tbl_bkpf-gjahr.

sort tbl_bseg by bukrs belnr gjahr.

loop at tbl_bkpf.

read table tbl_bseg with key bukrs = tbl_bkpf-bukrs

belnr = tbl_bkpf-belnr

gjahr = tbl_bkpf-gjahr

binary search.

if sy-subrc ne 0.

delete tbl_bkpf.

endif.

endloop.

This method hits the DB twice only, and using the BINARY SEARCH is a very efficient way to search a SORTED Internal Table.

Regards

5 REPLIES 5

Former Member
0 Kudos
1,173

hi,

BKPF- header table.

BSEG - item table.

for one BELNR in BKPF there will be multiple entries in BSEG.

<u><b>Keys</b></u>

<i><b>bukrs

belnr

gjahr </b></i>

<u>Note:</u>

It is recommended that

first select entries from only one table

(say, BKPF),

After that, using the internal table,

FOR ALL ENTRIES, and BSEG table,

select the relevant entries from BSEG table.

Performance wise, this will be very fast.

Rgds

Reshma

Message was edited by:

Reshma Alumadathil

Former Member
0 Kudos
1,173

Hi,

No.

Jogdand M B

Former Member
0 Kudos
1,173

BUKRS

GJAHR are even common fields for these tables

Regards,

Santosh

Former Member
0 Kudos
1,173

Hi ,

I think there is no other unique key connection between BKPF and BSEG.

Thanks,

Ravi Kumar

Former Member
0 Kudos
1,174

Hi,

<b>bukrs,belnr,gjahr</b> thease fileds are common for BKPF and BSEG.

Try something like this:

data: begin of tbl_bkpf occurs 0,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

gjahr like bkpf-gjahr,

end of tbl_bkpf.

data: begin of tbl_bseg occurs 0,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

gjahr like bkpf-gjahr,

end of tbl_bseg.

select bukrs belnr gjahr

into table tbl_bkpf

from bkpf

where belnr in s_belnr. "Insert parameters here

check sy-subrc eq 0.

select belnr

into table tbl_bseg

from bseg

for all entries in table tbl_bkpf

where bukrs = tbl_bkpf-bukrs and

belnr = tbl_bkpf-belnr and

gjahr = tbl_bkpf-gjahr.

sort tbl_bseg by bukrs belnr gjahr.

loop at tbl_bkpf.

read table tbl_bseg with key bukrs = tbl_bkpf-bukrs

belnr = tbl_bkpf-belnr

gjahr = tbl_bkpf-gjahr

binary search.

if sy-subrc ne 0.

delete tbl_bkpf.

endif.

endloop.

This method hits the DB twice only, and using the BINARY SEARCH is a very efficient way to search a SORTED Internal Table.

Regards