11-10-2006 3:17 PM
Hi SDNs,
when we use FOR ALL ENTRIES in select statement..
Regards,
aravind.
11-10-2006 3:23 PM
Hi
When you can load all hit for a where condition in internal tables.
For example you need to read all open items of all customer inserted in a Z-TABLE:
TABLES: BSID.
PARAMETERS: P_BUKRS LIKE T001-BUKRS.
SELECT-OPTIONS SO_KUNNR FOR BSID-KUNNR.
DATA: ITAB LIKE STANDARD TABLE OF Z<TABLE> WITH HEADER LINE.
SELECT * FROM Z<TABLE> INTO TABLE ITAB WHERE KUNNR IN SO_KUNNR.
SELECT * FROM BSID
FOR ALL ENTRIES IN ITAB
WHERE BUKRS = P_BUKRS
AND KUNNR = ITAB-KUNNR
This code is better for performace than:
SELECT * FROM BSID WHERE BUKRS = P_BUKRS
AND KUNNR IN SO_KUNNR.
SELECT SINGLE * FROM Z<TABLE> WHERE KUNNR = BSID-KUNNR.
CHECK SY-SUBRC = 0.
So it's usually used to improve the performance, but it can depend on the report is build, because you can use a join instead on FOR all ENTRIES.
Max
11-10-2006 3:23 PM
Hi,
If you want to retrieve multiple headers and items of each of the header you can use for all entries.
For example you have two internal tables
T_EKKO - Table for PO header
T_EKPO - Table for PO Items
select * from EKKO into T_EKKO where xxx = xxxx.
Now, we need to get all the items for the selected for the PO HEaders
select * from EKPO
for all entries in T_EKKO
where ebeln = T_EKKO-EBELN.
Make sure you check if T_EKKO is not initial before using FOR ALL ENTRIES.
Regards,
Ravi
Note : Please mark all the helpful answers
11-10-2006 3:25 PM
Check SDN Wiki FAQ, 4th entry.
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abapPerformanceand+Tuning&
Regards,
Rich Heilman
11-10-2006 3:28 PM
Hi,
For all entries use to avoid joining between tables and to avoid loop ..endloop..
Eg. U can select all necessary data from Table1 into itab1. Then using itab1 as a driver table u can select data from table2 into itab2 for all entries in itab1 with where condition . But before using for all entries make sure the driver table has got data.
Cheers.
11-11-2006 8:09 AM
Hi,
U can join 2 tables by using joins but the performance goes down. This can be overcomed by for all entries.
select-options : s_vbeln for likp-vbeln.
select vbeln erdat lfart
from likp
into table it_likp
where vbeln in s_vbeln.
based on s_vbeln the records will be stored in it_likp. eg, say 24 records selected
if not it_likp[] is initial.
select vbeln posnr matnr
from lips
into table it_lips
for all entries in it_likp
where vbeln eq it_likp-vbeln.
endif.
now , since i am using,
for all entries in it_likp
so the vbeln value of these 24 records (which i have selected in it_likp) will be checked in lips and those records will be stored in it_lips.
Drawback is if the records are not there in it_likp then all the records from lips will be fetched into it_lips.
To overcome this draw back we have to compulsory check
if not it_likp[] is initial.
this means if the internal table it_likp is not initial ie, it is containing some records
11-11-2006 9:33 AM
HI,
FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
*----
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
*--------------------
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
*--------------------
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
*--------------------------
LOOP AT t001.
WRITE 😕 t001-bukrs.
ENDLOOP.
Hope this helps!
Regards,
Anver
<i><b>if hlped pls mark points</b></i>
11-11-2006 9:50 AM
Hi aravind,
When ever we want to Combine data from two data base table then we use For all Entries. Similar to that of Inner Joins concept.
the advange of this For all entries is that it checks the condition first and then retrieves the data. But where in inner joins the Data is retrieved first and then the condition is checked.
Bye
Murthy