2007 Jul 31 7:58 AM
hi experts
i have the following scenario.
Except belnr, is there any unique key to link bkpf and bseg.
Thanks in advance.
Regards
Rajaram
2007 Jul 31 8:04 AM
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
2007 Jul 31 8:00 AM
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
2007 Jul 31 8:01 AM
2007 Jul 31 8:02 AM
BUKRS
GJAHR are even common fields for these tables
Regards,
Santosh
2007 Jul 31 8:03 AM
Hi ,
I think there is no other unique key connection between BKPF and BSEG.
Thanks,
Ravi Kumar
2007 Jul 31 8:04 AM
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