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

Former Member
0 Likes
1,930

Hi All,

An Internal table has no records. When i use Select for all entries for this internal table, what is the result i get?

Thanks,

Chakradhar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,847

And the voting so far is:

ZERO entries: 5

EVERYTHING in Table: 4

So if we were going by popular vote, Zero would be the answer.

SAP Documentation says:

If the internal table itab is empty, the whole WHERE statement is ignored and<b> all lines in the database</b> are put in the resulting set.

So looks like those who voted for ZERO miss out this time.

Sorry

Andrew

Hi All,

An Internal table has no records. When i use Select for all entries for this internal table, what is the result i get?

Thanks,

Chakradhar

14 REPLIES 14
Read only

Former Member
0 Likes
1,847

0

Read only

Former Member
0 Likes
1,847

hi,

u will get nothing.

rgds

Read only

Former Member
0 Likes
1,847

Hi

in the case of for all entries if for that selectin if there is no data availabale then it will display all the records available in that table

to avoid this sitvation

write like this

<b>select * from mara into table itab1 where condition

if not itab1[] is initial.

select * from marc into table itab2 for all entries in itab1 where condition</b>

in the above condition it will show 0 records

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Read only

Former Member
0 Likes
1,847

Hi Chakradhar,

You will get all records from the table.

If IT_VBAK has no record and you are using this table for selecting data from VBAP for all entries of IT_VBAK. It will fetch all records from VBAP

so best practice is use

If not it_vbak[] is inital.

--> write your for all entries select statement here

endif.

<b><REMOVED BY MODERATOR></b>

Thanks

Vishwanath Purohit

Message was edited by:

Alvaro Tejada Galindo

Read only

Former Member
0 Likes
1,847

i think nothing will come

u have to place not initial condition

Read only

Former Member
0 Likes
1,847

HI CHAKRA,

u wont get any output.

because for all entries will give u value according to the entries in your first table.

when u dont have any value in your first table for all entries cannot compare with any table.

that is the only reason we check for the INITIAL condition from second table.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Read only

Former Member
0 Likes
1,847

hi,

If it happen so, then u will get all entries from DB Table which obviously wrong.

so first check if it[] is not initial.

Message was edited by:

Dhwani shah

Read only

0 Likes
1,847

<b>Don't ever make a select for all entries in itab if you haven't checked your itab before !!!</b>

Otherwise you'll fetch all the entries, I'll let you imagine the result in a Productive system.

So, the winner is.

If not itab[] is initial.
select * from mara
            into corresponding fields of tabel itab_mara
            for all entries in table itab
            where matnr = itab-matnr.
endif.

Read only

Former Member
0 Likes
1,847

hi,

actually all entries compares the entries with which u are going to select and creates the entries .

if no entries are there then it will show only 0.

Read only

Former Member
0 Likes
1,848

And the voting so far is:

ZERO entries: 5

EVERYTHING in Table: 4

So if we were going by popular vote, Zero would be the answer.

SAP Documentation says:

If the internal table itab is empty, the whole WHERE statement is ignored and<b> all lines in the database</b> are put in the resulting set.

So looks like those who voted for ZERO miss out this time.

Sorry

Andrew

Read only

0 Likes
1,847

You get what you pay for.

Rob

Read only

0 Likes
1,847

IF THE TABLE IS EMPTY YOU'LL GET ALL REGISTRIES....

Read only

0 Likes
1,847

Hi Nacho! No need to shout -:)

Greetings,

Blag.

Read only

0 Likes
1,847

Hi,

the FOR ALL ENTRIES CLAUSE is very well documented. Type SELECT and press F1 in ABAP editor.

"If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set."

This is what some people here already said. But it is important because some guys believe that with an empty FOR ALL ENTRIES table any additional conditions (i.e. AND MTART = 'Z700') would be checked.

This is not the case (shout!).

Another pitfall (cost me a day or more!) is if you select only the fields you need for processing, you might not get all records. I tried to calculate an open item sum using for all entries and wondered why the result was not alwys correct.

Another note in the help:

"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. "

Not easy to understand. But it means that the resulting table has no duplicate entries. In my case, I collected customer no. and amount from BSEG. All items with identical customer number and open amount apperared only once.

The solution is that you have to select all key fields of the table you select from. If you use INTO CORRESPONDING FIELDS OF TABLE you do not need the fields in the resulting area, you will get all records anyway.

Regards,

Clemens