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: 

If empty internal table in select for all entries what is the result?

Former Member
0 Kudos

In select all entries statement , if empty internal table is there then what is the result.

10 REPLIES 10

Former Member
0 Kudos

it will fetch all the data from second table irrespective of for all entrie table where condition

You can only use FOR ALL ENTRIES IN ...WHERE ...in a SELECT statement.

SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT

statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol

itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result

set. If the internal table itab does not contain any entries, the system treats the statement as though there were

no WHERE cond condition, and selects all records (in the current client).

for example:

SELECT * FROM sflight INTO wa_sflight

FOR ALL ENTRIES IN ftab

WHERE CARRID = ftab-carrid AND

CONNID = ftab-connid AND

fldate = '20010228'.

this condition, return all entries of the sflight

Message was edited by:

Raghavendra L

anversha_s
Active Contributor
0 Kudos

hi,

it will fetch all datas from DB

rgds

Anver

Former Member
0 Kudos

<b>All records will be fetched.</b>

To avoid that u have to use

<b>If itab[] is not initial.

select.....for all entries in itab.

endif.

Regs

Manas Ranjan Panda</b>

Message was edited by:

MANAS PANDA

Former Member
0 Kudos
Select field1 field2
          from table1
          into table i_tab
          for all entries in itab2
         where field1 = itab2-field1.

If the internal table used in for all entries is empty, the select will fetch all the records from table1 depending on the other where conditions...

If your program is dependant on itab2, then you might consider stopping the program execution.

if not itab2[] is initial.
   Select field1 field2
          from table1
          into table i_tab
          for all entries in itab2
         where field1 = itab2-field1.
else.
   stop. (or exit).
endif.

0 Kudos

Hi,

This is definitely wrong!

If the internal table used with FOR ALL ENTRIES IN is empty/initial, the whole WHERE CLAUSE is ignored - all data are feched from database.

That means even id you have other conditions in the WHERE CLAUSE, they are ignored as well.

Please: Befor asking such questions, check the SAP online help available in the ABAP editor:

F1 on SELECT

WHERE clause

2. ... FOR ALL ENTRIES IN itab WHERE cond

..."If the internal table itab does not contain any entries, the system treats the statement as though there were no WHERE cond condition, and selects all records (in the current client). "

It is a clear advanted if you can read

Regards,

Clemens

Former Member
0 Kudos

In Select with for all entries , the driver table should not be empty..

Because if it is empty , then the whole idea of For all entries is lost, as the

Select goes for full Table Scan (data base table).

Thats why we put the select with for all entries in IF -ENDIF block,

and in IF we check , that the driver table is not empty:

as

IF NOT ts_driver[] IS INITIAL.

SELECT

FROM

INTO

FOR ALL ENTRIES IN ts_driver

WHERE xyz EQ ts_driver-xyz.

ENDIF.

If not clear do let me know (if clear , give points !).

Cheers

Abhishek

Former Member
0 Kudos

Hi,

In such case where we are using select for all entries and internal table is blank, then our statement will behave like ":SELCT *.....":.It will select all records.

thanks,

Rajesh

former_member480923
Active Contributor
0 Kudos

Hi

Its the same thing as having an empty range in where condition. Select all the records without validation.

Thanks

Anirban M.

Clemenss
Active Contributor
0 Kudos

SAP online Docu:

If the internal table itab does not contain any entries, the system treats the statement as though there were no WHERE cond condition, and selects all records (in the current client).

Regards,

Clemens

0 Kudos

As a matter of interest, even if the internal table has entries, but has no result for the selection, it returns all entries in the table.....Just something I discovered to my regret recently