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

PROBLEM WITH FOR ALL ENTRIES

Former Member
0 Likes
2,392

Hi,

i have a problem with for all entries,

in the selection screen i will enter that s_bukrs.

from the bkpf table a document number will be picked and for that document number i have

2 entries in the bseg table. but when i am doing for all entries its picking only one recOrd from the TABLE BSEG. CAN YOU TELL ME WHAT IS THE REASON.

MY LOGIC IS AS BELOW..

SELECT gjahr belnr budat

FROM bkpf

INTO TABLE i_bkpf

WHERE bukrs IN s_bukrs.

IF sy-subrc EQ 0.

SELECT bukrs belnr shkzg dmbtr matnr

INTO TABLE i_bseg

FROM bseg

FOR ALL ENTRIES IN i_bkpf

WHERE bukrs IN s_bukrs AND

belnr EQ i_bkpf-belnr AND

gjahr EQ i_bkpf-gjahr AND

hkont IN s_saknr.

THANKS,

sURESH

11 REPLIES 11
Read only

Sm1tje
Active Contributor
0 Likes
1,472

try to replace:

FOR ALL ENTRIES IN i_bkpf

WHERE bukrs IN s_bukrs AND

belnr EQ i_bkpf-belnr AND

gjahr EQ i_bkpf-gjahr AND

hkont IN s_saknr.

with

FOR ALL ENTRIES IN i_bkpf

WHERE belnr EQ i_bkpf-belnr AND

gjahr EQ i_bkpf-gjahr

BTW: Did you check in table BSEG also for HKONT, maybe problem lies there and not in your coding.

Edited by: Micky Oestreich on May 27, 2008 2:50 PM

Read only

Former Member
0 Likes
1,472

Hello,

Are you filling the select-options s_saknr? If you fill it, will be returned only one entry (depending of the type of FI document, normally the accounts are diferent for each record in BSEG).

Regards,

Read only

0 Likes
1,472

Hi David Pietroniro ,

But the GL account also same in BSEG table. so it should pick right ??

Read only

Former Member
0 Likes
1,472

Hi Suresh,

SELECT bukrs belnr shkzg dmbtr matnr

INTO TABLE i_bseg

FROM bseg

FOR ALL ENTRIES IN i_bkpf

WHERE bukrs IN s_bukrs AND

belnr EQ i_bkpf-belnr AND

gjahr EQ i_bkpf-gjahr AND

hkont IN s_saknr.

I think problem is in where clause because you are again using bukrs IN s_bukrs, when you already have filtered data in i_bkpf according to bukrs, then there is no need for it again. one more thing you have three conditions to be validate apart from bukrs. belnr, gjahr, hkont, there mey be possibility either of the conditions does not match with 2 values data and query is getting failed to extract as you exactly want. Please check first with only:

SELECT bukrs belnr shkzg dmbtr matnr

INTO TABLE i_bseg

FROM bseg

FOR ALL ENTRIES IN i_bkpf

WHERE belnr EQ i_bkpf-belnr.

if you get both the entries or as required. then do changes accordingly.

Rewards if useful.

BR,

Alok

Read only

Former Member
0 Likes
1,472

Hi suresh,

1. First do a minor change (bold)

IF sy-subrc EQ 0.

SELECT bukrs belnr shkzg dmbtr matnr

INTO TABLE i_bseg

FROM bseg

FOR ALL ENTRIES IN i_bkpf

WHERE bukrs EQ i_bkpf-bukrs AND

belnr EQ i_bkpf-belnr AND

gjahr EQ i_bkpf-gjahr AND

hkont IN s_saknr.

2. Check now whether the records are coming OK.

3. If not then for checking purpose,

simply remove the HKONT condition.

regards,

amit m.

Read only

Former Member
0 Likes
1,472

Your problem is that FOR ALL ENTRIES eliminates duplicate entries. Simply add BUZEI to the second select (and add BUKRS to the first one):

SELECT bukrs gjahr belnr budat
  FROM bkpf
  INTO CORRESPONDING FIELDS OF TABLE i_bkpf
  WHERE bukrs IN s_bukrs.

IF sy-subrc EQ 0.
  SELECT bukrs belnr buzei shkzg dmbtr matnr
  INTO CORRESPONDING FIELDS OF TABLE i_bseg
  FROM bseg
  FOR ALL ENTRIES IN i_bkpf
  WHERE bukrs EQ i_bkpf-bukrs AND
  belnr EQ i_bkpf-belnr AND
  gjahr EQ i_bkpf-gjahr AND
  hkont IN s_saknr.
ENDIF.

Rob

Read only

Former Member
0 Likes
1,472

HI,

The simple reason why you are getting one entry instead two entries in BSEG table is might the selected fields have same values in BSEG table. Which means you can retrieve all the key fields even it is not using in your program, becasue the for all entries works like SELECT and Delete adjacent duplicates statements. So the fields which you retrieved has duplicate entries, so one record get delete from your table.

Try to add some more fields (All key fields) in your select query, then your problem will be solved....

Try to change the select like this

Select bukrs belnr GJAHR BUZEI shkzg dmbtr matnr

......

......

Rgds,

Bujji

Edited by: Bujji on May 27, 2008 4:15 PM

Read only

Former Member
0 Likes
1,472

This message was moderated.

Read only

Former Member
0 Likes
1,472

Dear friend,

for all entries feature gets only unique value from the database so you might get single row,

regards

Read only

renato_parise
Participant
0 Likes
1,472

ABAP - Keyword Documentation:

With duplicated rows in the resulting set, the addition FOR ALL ENTRIES has the same effect as if addition DISTINCT were specified in the definition of the selection quantity. Unlike DISTINCT, the rows are not deleted from the database system but are deleted on the application server from the resulting set.

Read only

0 Likes
1,472

Even though this thread is 4 years old, it saved me.

Thanks!