Application Development 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: 

Help required on 'FOR ALL ENTRIES IN'

Former Member
0 Kudos

I am using this query:

SELECT vguid qausp

INTO TABLE tb_qualif

FROM vlcadddata

FOR ALL ENTRIES IN tb_distmode1

WHERE vguid = tb_distmode1-vguid

AND aqual = 'ASPT'.

Now if the internal table contains no data tb_distmode1 then the query is giving wrong result. In fact it is ignoring the part 'FOR ALL ENTRIES IN tb_distmode1'.

Ideally my requirement is not to fetch any data if the table is empty. So can anyone suggest any suitable way so that I can get the desired result without using IF...ENDIF.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

This is because when the table which is used in for all entries is empty, all the database records are selected.

Solution :

Before the select query check if the table tb_distmode1 has any entries . Only then make the select query to execute.


describe table tb_distmode1 lines sy-tfill.

if sy-tfill GE 1.

SELECT vguid qausp
INTO TABLE tb_qualif
FROM vlcadddata
FOR ALL ENTRIES IN tb_distmode1
WHERE vguid = tb_distmode1-vguid
AND aqual = 'ASPT'.
endif.

I dont think there is any other way to achive your requirement.

regards,

Advait.

Edited by: Advait Gode on Oct 8, 2008 3:17 PM

9 REPLIES 9

Former Member
0 Kudos

This is because when the table which is used in for all entries is empty, all the database records are selected.

Solution :

Before the select query check if the table tb_distmode1 has any entries . Only then make the select query to execute.


describe table tb_distmode1 lines sy-tfill.

if sy-tfill GE 1.

SELECT vguid qausp
INTO TABLE tb_qualif
FROM vlcadddata
FOR ALL ENTRIES IN tb_distmode1
WHERE vguid = tb_distmode1-vguid
AND aqual = 'ASPT'.
endif.

I dont think there is any other way to achive your requirement.

regards,

Advait.

Edited by: Advait Gode on Oct 8, 2008 3:17 PM

JozsefSzikszai
Active Contributor
0 Kudos

just check if the internal table is not empty:

IF tb_distmode1[] IS NOT INITIAL.
SELECT ...
ENDIF.

Former Member
0 Kudos

Hi

Write code like this

if tb_distmode1[] is not initial.

SELECT vguid qausp

INTO TABLE tb_qualif

FROM vlcadddata

FOR ALL ENTRIES IN tb_distmode1

WHERE vguid = tb_distmode1-vguid

AND aqual = 'ASPT'.

endif.

Former Member
0 Kudos

Hi,

Modify the select query as stated below.

if tb_distmode1 is not initial.

SELECT vguid qausp

INTO TABLE tb_qualif

FROM vlcadddata

FOR ALL ENTRIES IN tb_distmode1

WHERE vguid = tb_distmode1-vguid

AND aqual = 'ASPT'.

endif.

thanks & regards

Kishore M

Former Member
0 Kudos

Hi,

Use 'IF NOT ITAB IS INITIAL' before using for all entries.

this is mandatory.

Regards,

Sudheer Kumar

Former Member
0 Kudos

Hi,

Yes if the internal tab in empty all the records are fetched ignoring the for all entries.

So before you select you check the intial of the internal tab.

If itab is not initial.

select.........

endif.

Rhea.

Former Member
0 Kudos

Hi

you have to check if the first internal table is empty or not before using the for all entries its mandatory condition.

if itab is not initial.

select stmt...

endif.

regards

Former Member
0 Kudos

You can also use the CHECK statement.


CHECK tb_distmode1[] is not initial. 
SELECT vguid qausp
INTO TABLE tb_qualif
FROM vlcadddata
FOR ALL ENTRIES IN tb_distmode1
WHERE vguid = tb_distmode1-vguid
AND aqual = 'ASPT'.

But please note that if the table is initial, then the entire code after the CHECK statement will not be executed

regards,

Advait.

Edited by: Advait Gode on Oct 8, 2008 3:45 PM

Former Member
0 Kudos

This could run infinitely also if no recs match.