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: 

For all entries

Former Member
0 Kudos

Hi Again

I discussed this topic earlier but again m getting bit confused so plz don mind and help in getting the funda..

if am using 2 internal tables and am using for all entries statment to retrieve the data but there are no records in the first internal table ..so what will be the result?? ..second internal table is having records..

I guess second internal table will access the database table for all entries

or no records will be returned at all??

Thanks

1 ACCEPTED SOLUTION

abdul_hakim
Active Contributor
0 Kudos

hi rashmi,

if the first internal table doesn't have any entries then your second SELECT statement will fetch all the records from your second table.so you should alwayz check your itab before using it in FOR ALL ENTRIES addition.

DATA: ITAB LIKE TABLE OF MARA,

JTAB LIKE TABLE OF MAKT.

SELECT * FROM MARA INTO TABLE ITAB.

IF NOT ITAB IS INITIAL.

<ur SELECT FOR ALL ENTRIES code>

ENDIF.

8 REPLIES 8

Former Member
0 Kudos

No, it will get all the entries of the second table. Its as good as you don't have a where clause on the first internal table. That is why you need to check for the contents of the first internal table, before firing the all entries.

Regards,

Ravi

Note : Please mark the helpful answers

abdul_hakim
Active Contributor
0 Kudos

hi rashmi,

if the first internal table doesn't have any entries then your second SELECT statement will fetch all the records from your second table.so you should alwayz check your itab before using it in FOR ALL ENTRIES addition.

DATA: ITAB LIKE TABLE OF MARA,

JTAB LIKE TABLE OF MAKT.

SELECT * FROM MARA INTO TABLE ITAB.

IF NOT ITAB IS INITIAL.

<ur SELECT FOR ALL ENTRIES code>

ENDIF.

Former Member
0 Kudos

Hi,

If there first internal table is INITIAL i.e. there are no records in it then the select statement will select all the records form the data base table on which it is fired. So befor using the FOR ALL ENTRIES it is mandatory to check whether the first table is initial or not.

Thanks and Regards,

Bharat Kumar Reddy.V

Former Member
0 Kudos

hi rashmi,

For all entries shud be used bu first checking whether the first table is empty or not.

eg: select * from kna1 into table itab.

if itab is not initial.

select.......

endif.

hope this helps,

priya.

Former Member
0 Kudos

Hi,

The Select Query will fetch all the Entries from 2nd Internal Table,Bcoz there will be no Condition to

Check in where clause so it will fetch all the data

present in the Internal Table on which it is fired.

Former Member
0 Kudos

Hi Rashmi,

Before using for all entries, you should always check if the <b>first internal table</b> is empty or not.

Detailed description :

<b>... FOR ALL ENTRIES IN itab WHERE cond</b>

Effect

Only selects the records that meet the logical condition cond when each replacement symbol itab-f is replaced with the value of component f of the internal table itab for at least one line of the table. 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).

Example

Displaying the occupancy of flights on 28.02.2001:

TYPES: BEGIN OF ftab_type,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

END OF ftab_type.

DATA: ftab TYPE STANDARD TABLE OF ftab_type WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 10,

free TYPE I,

wa_sflight TYPE sflight.

  • Suppose FTAB is filled as follows:

  • CARRID CONNID

  • --------------

  • LH 2415

  • SQ 0026

  • LH 0400

SELECT * FROM sflight INTO wa_sflight

FOR ALL ENTRIES IN ftab

WHERE CARRID = ftab-carrid AND

CONNID = ftab-connid AND

fldate = '20010228'.

free = wa_sflight-seatsocc - wa_sflight-seatsmax.

WRITE: / wa_sflight-carrid, wa_sflight-connid, free.

ENDSELECT.

  • The statement has the same effect as:

SELECT DISTINCT * FROM sflight INTO wa_sflight

WHERE ( carrid = 'LH' AND

connid = '2415' AND

fldate = '20010228' ) OR

( carrid = 'SQ' AND

connid = '0026' AND

fldate = '20010228' ) OR

( carrid = 'LH' AND

connid = '0400' AND

fldate = '20010228' ).

free = wa_sflight-seatsocc - wa_sflight-seatsmax.

WRITE: / wa_sflight-carrid, wa_sflight-connid, free.

ENDSELECT.

Regards,

Kunal.

Message was edited by: Kunal Kumar

Former Member
0 Kudos

Thanks to all

I got point

Former Member
0 Kudos

Example...

select * from marc into table itab.

if not itab[] is initial.

select * from makt into table itab2

where matnr = itab-matnr.

endif.

If 'if not itab[] is initial.' is used, makt results will be fetched only for the matnrs which are there in itab .

if you do not use it , but still u have some results in itab, then it hardly makes any difference.

If you do not use it, and u don't have any results in itab, then all the results are picked up from makt without checking for the where condition on itab.