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 data from BSEG

Former Member
0 Likes
2,012

Hi,

I have selected the data from BKPF depending on the BUKRS & selecton screen dates.

Now I want to select data from BSEG depending on bukrs obtained in the above step & KUNNR which is in another internal T_CUST ... Will the select statement below ensure that the T_BSEG table will have the correct values of the documents no's corresponding to the customers in table T_CUST ??

  • Get BSEG data for all values in BKPF

IF NOT T_BKPF[] IS INITIAL.

SELECT BUKRS

BELNR

GJAHR

BUZEI

BUZID

BSCHL

KOART

SHKZG

DMBTR

KUNNR

INTO TABLE T_BSEG_TEMP

FROM BSEG

FOR ALL ENTRIES IN T_BKPF

WHERE BUKRS = T_BKPF-BUKRS AND

BELNR = T_BKPF-BELNR AND

GJAHR = T_BKPF-GJAHR.

ENDIF.

FORM GET_BSEG_DATA .

  • Get BSEG data for all customers

IF NOT T_CUST[] IS INITIAL.

SELECT BUKRS

BELNR

GJAHR

BUZEI

BUZID

BSCHL

KOART

SHKZG

DMBTR

KUNNR

INTO TABLE T_BSEG

FROM BSEG

FOR ALL ENTRIES IN T_CUST

WHERE KUNNR = T_CUST-KUNNR.

ENDIF.

ENDFORM. " GET_BSEG_DATA

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,457

Hi SB,

It will work perfectly..

do you have any problem with the query..?

regards

satesh

13 REPLIES 13
Read only

Former Member
0 Likes
1,457

Your code is alright.

What is your requirement.

Read only

Former Member
0 Likes
1,457

hI sb

YES, THE SELECT STATEMENT WILL FETCH DATA FOR THE REQUIRED CUSTOMERS.

REGARDS

KISHORE

Read only

Former Member
0 Likes
1,458

Hi SB,

It will work perfectly..

do you have any problem with the query..?

regards

satesh

Read only

0 Likes
1,457

My requirement is to get data from BSEG where bukrs = bkpf-bukrs and belnr= bkpf-belnr & knunnr = t_cust kunnr .. I was not sure about how to write a <b> "single select statement" with "where conditions from two different tables"</b> .... so only I split up the tables as t_bseg & t_bseg_temp and also split up up the where condition ... but then by splitting up the where condition I was not sure whether the right BELNR & BUKRS will be selected just by giving the condition where KUNNR = T_CUST-KUNNR ...

Read only

0 Likes
1,457

Hi SB,

Try to merge the two internal tables (bkpf and t_cust) into the 3rd internal table say t_temp and now you can write the select statement by using the 3rd internal table in FOR-ALL-ENTRIES option where bukrs = t_temp-bukrs and belnr = t_temp-belnr and kunnr = t_temp-kunnr.

Regards,

Phani.

Read only

0 Likes
1,457

Hi SB

MERGE THE TWO INTERNAL TABLE T_BKPF AND T_CUST INTO ANOTHER INTERNAL TABLE THEN USE FOR ALL ENTRIES FOPR THE SELECT STATEMENT.

REGARDS

KISHORE

Read only

0 Likes
1,457

hi SB,

We can Merge two Internal tables with the help of <b>Innerjoins</b> and collect the joined data in to third internal table and then use for all entries for the select statement ... but since BSEG is cluster table inner join shouldn't be used to merge cluster table data

.... So first with the help of one select statement merge the data of two internal tables in to third table and then use for all entries for the third internal table ..

hope this helps,

Regards,

Santosh

Read only

0 Likes
1,457

hi,

your 2nd part is <b>very bad</b> for performance:

FOR ALL ENTRIES IN T_CUST
WHERE KUNNR = T_CUST-KUNNR

better select bsid and bsad

Andreas

Read only

0 Likes
1,457

Hi,

I am getting customer number with the help of account group ... Is there any table where I can get that the customer & account group as primary fields??

Read only

0 Likes
1,457

I am getting customer number with the help of account group and Company code ... Is there any table where I can get that the customer & account group & Company code as primary fields??

Ignore my previous msg.

Read only

0 Likes
1,457

hi SB,

look at KNB1 OR KNB2 TABLES ...

Regards,

Santosh

Read only

0 Likes
1,457

Like Andreas said - BSID and BSAD. Definitely not BSEG.

Rob

Read only

Former Member
0 Likes
1,457

Hi,

The data would be inconsistent, better way is to merge all into one final internal table and handle it appropriately.