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

select ... for all entries problem

Former Member
0 Likes
609

Hi,

I'm making select statements to BKPF and BSEG, but I can't do an inner join between this two table because BSEG it's a cluster table so I have to do a SELECT... FOR ALL ENTRIES, but in SE16 I make the same query that I have writen in my program as shown below,

SELECT BUKRS BELNR GJAHR BUDAT MONAT

FROM BKPF INTO CORRESPONDING FIELDS OF TABLE it_bkpf

WHERE BUKRS = 'XXX'

AND GJAHR = '2005'

AND BELNR = '0000000250'. "just for proof

AND MONAT = '10'

The above query returns me 1 row in program and in SE16 and then I make the next query for BSEG to do the join

SELECT BUKRS BELNR GJAHR BSCHL SHKZG WRBTR HKONT

FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs

and gjahr = it_bkpf-gjahr

and belnr = it_bkpf-belnr.

this query returns 897 rows and in SE16 this same query returns 901 rows

Why SELECT...FOR ALL ENTRIES brings me less rows affected by the query in SE16

Thanks for your help!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
501

Hi,

The reason you are getting the less data is you haven't selected all the key fields from the table.

Change your query to include BUZEI in the selection from BSEG as below

SELECT BUKRS BELNR GJAHR BUZEI BSCHL SHKZG WRBTR HKONT

FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs

and gjahr = it_bkpf-gjahr

and belnr = it_bkpf-belnr.

Regards,

Atish

3 REPLIES 3
Read only

Former Member
0 Likes
502

Hi,

The reason you are getting the less data is you haven't selected all the key fields from the table.

Change your query to include BUZEI in the selection from BSEG as below

SELECT BUKRS BELNR GJAHR BUZEI BSCHL SHKZG WRBTR HKONT

FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs

and gjahr = it_bkpf-gjahr

and belnr = it_bkpf-belnr.

Regards,

Atish

Read only

0 Likes
501

Hi,

Please use the following code for selcting the exact number of rows.

IF it_bkpf[] IS NOT INITIAL.

SELECT *

FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs

and gjahr = it_bkpf-gjahr

and belnr = it_bkpf-belnr.

ENDIF.

Instead of * ,you can specify the exact fields required along with all the key fields as selection fields.Also it is must to check the condition it_bkpf[] IS NOT INITIAL before using the statement FOR ALL ENTRIES IN it_bkpf.Suppose if this condition is not used and if it_bkpf is initial,it will fetch all entries from the table.

Reward if helpful.

Regards,

Aravind

Read only

Former Member
0 Likes
501

Thanks a lot!!

I added BUZEI to the select statement and that solved the problem.

Your answers were very helpful!!

Thanks!!