04-29-2008 4:33 PM
wht happens if v read data using FOR ALL ENTRIES in select statement
04-29-2008 4:44 PM
It's very important to ensure that the FOR ALL ENTRIES table is not empty, or doesn't contains duplicate records. For doing so, use SORT to order the FOR ALL ENTRIES table by the field you desire, and use DELETE ADJACENT DUPLICATES on it.
For example:
SELECT *
FROM mara
INTO TABLE tg_mara
WHERE matnr IN s_matnr.
*** Deleting duplicated records
SORT tg_mara BY matnr.
DELETE ADJACENT DUPLICATES FROM tg_mara
COMPARING matnr.
***If the FOR ALL ENTRIES TABLE is not empty:
IF tg_mara IS NOT INITIAL.
SELECT *
FROM marc
INTO TABLE tg_marc
FOR ALL ENTRIES IN tg_mara
WHERE matnr = tg_mara-matnr.
ENDIF.
Not checking the FOR ALL ENTRIES table, may result on poor performance levels.
Regards,
Brian Gonsales
04-29-2008 4:34 PM
Hi Ankur,
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 SCARR
INTO TABLE t_scarr.
LOOP AT t_SCARR INTO wa_scarr.
SELECT SINGLE *
FROM sflight
INTO wa_sflight
WHERE carrid EQ wa_scarr-carrid.
APPEND wa_sflight TO t_sflight.
ENDLOOP.
Instead of the Above use below code:
SELECT *
FROM SCARR
INTO TABLE t_scarr.
SELECT *
FROM SFLIGHT
INTO TABLE t_sflight
FOR ALL ENTRIES IN scARR
WHERE carrid EQ t_scarr.
this condition, return all entries of the sflight
Refer the Below Links for more Info:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm
Regards,
Sunil
04-29-2008 4:36 PM
04-29-2008 4:44 PM
It's very important to ensure that the FOR ALL ENTRIES table is not empty, or doesn't contains duplicate records. For doing so, use SORT to order the FOR ALL ENTRIES table by the field you desire, and use DELETE ADJACENT DUPLICATES on it.
For example:
SELECT *
FROM mara
INTO TABLE tg_mara
WHERE matnr IN s_matnr.
*** Deleting duplicated records
SORT tg_mara BY matnr.
DELETE ADJACENT DUPLICATES FROM tg_mara
COMPARING matnr.
***If the FOR ALL ENTRIES TABLE is not empty:
IF tg_mara IS NOT INITIAL.
SELECT *
FROM marc
INTO TABLE tg_marc
FOR ALL ENTRIES IN tg_mara
WHERE matnr = tg_mara-matnr.
ENDIF.
Not checking the FOR ALL ENTRIES table, may result on poor performance levels.
Regards,
Brian Gonsales
04-29-2008 4:46 PM
wht happens if v read data using FOR ALL ENTRIES in select statement and one of the internal table is empty ??????????
04-29-2008 5:00 PM
if table from comparison is empty than ALL data from select TABLE is selected into internal table. ALWAYS check if table is filled (at least one ENTRY).
example:
SELECT *
FROM marc
INTO TABLE tg_marc
FOR ALL ENTRIES IN tg_mara
WHERE matnr = tg_mara-matnr.
this internal table tg_mara must be checked first, else all data from MARC is selected in tg_marc.
Edited by: Micky Oestreich on Apr 29, 2008 6:00 PM
04-29-2008 5:29 PM
hi
SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
<cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.