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

INNER JOIN FOR BSEG

Former Member
0 Likes
11,315

HI experts,

Can v use BSEG and BKPF table in inner join.

thanks.

Khan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,679

since BSEG is a cluster table you can not use inner join . Here you have to use For all entries option

like

tables : bkpf , bseg.

data : ibkpf like bkpf occurs 0 with header line.

data : ibseg like bseg occurs 0 with header line.

select * into table ibkpf from bkpf up to 10 rows.

if not ibkpf[] is initial.

select * from bseg into table ibseg for all entries in ibkpf where

bukrs = ibkpf-bukrs and

belnr = ibkpf-belnr.

endif.

regards

shiba dutta

HI experts,

Can v use BSEG and BKPF table in inner join.

thanks.

Khan

7 REPLIES 7
Read only

prabhu_s2
Active Contributor
0 Likes
4,679

nope. cannot in cluster and pooled tables

Read only

Former Member
0 Likes
4,679

hi,

no u cant use join with BSEG as it is cluster table so u need to first fetch data from it and have to use for all entries.

Reward if useful.

Read only

Former Member
0 Likes
4,680

since BSEG is a cluster table you can not use inner join . Here you have to use For all entries option

like

tables : bkpf , bseg.

data : ibkpf like bkpf occurs 0 with header line.

data : ibseg like bseg occurs 0 with header line.

select * into table ibkpf from bkpf up to 10 rows.

if not ibkpf[] is initial.

select * from bseg into table ibseg for all entries in ibkpf where

bukrs = ibkpf-bukrs and

belnr = ibkpf-belnr.

endif.

regards

shiba dutta

Read only

prabhu_s2
Active Contributor
0 Likes
4,679

rather u can check the views related to bseg and bkpf:

V_VBSEGD

V_VBSEGK

V_VBSEGS

Read only

Former Member
0 Likes
4,679

HI ,

hOW CAN i POPULATE A VIEW AT RUNTIME AND HOW DO I THEN FETCH THE DATA.

MY INPUT FIELDS ON SELECTION SCREEN ARE

P_BUKRS LIKE BSEG-BUKRS.

S_DATE FOR BKPF-BUDAT

S_KUNNR FOR BSEG-KUNNR

plz help.

thaNKS.

KHAN

Read only

Former Member
0 Likes
4,679

Check this BLOG:

<a href="/people/rob.burbank/blog/2007/11/12/quickly-retrieving-fi-document-data-from-bseg">Quickly Retrieving FI document Data from BSEG</a>

Rob

Read only

Former Member
0 Likes
4,679

Hi Khan,

Need to do this way because u can't join cluster and pooled tables...

1. FOR ALL ENTRIES.

2. It is recommended that

first select entries from only one table

(say, BKPF),

3. After that, using the internal table,

FOR ALL ENTRIES, and BSEG table,

select the relevant entries from BSEG table.

4. Performance wise, this will be very fast.

See the Below example and modify ur it according to ur requirement ...



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.
** ur logic here
  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.

Hope it will solve your problem..

<b>Reward points if useful..</b>

Thanks & Regards

ilesh 24x7