‎2007 Jun 18 10:12 AM
when should we use read table or when should we use for all entries
points for sure
‎2007 Jun 18 10:15 AM
We use Read Table, when its is need to read the single record from the internal table.
We use For all entries, when we want to read the records from the database table.
‎2007 Jun 18 10:14 AM
Hi
Read table ITAb...is used to read a single entry of that internal table under the loop of some other internal table.
For all entries is used to fetch the records from a database table with reference to the for all entries of an internal table
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
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.
Reward points for useful Answers
Regards
Anji
‎2007 Jun 18 10:15 AM
We use Read Table, when its is need to read the single record from the internal table.
We use For all entries, when we want to read the records from the database table.
‎2007 Jun 18 10:16 AM
Hi,
Read table is used to read a single row from the internal table specifying some condition.
e.g. READ TABLE ITAB INDEX 2.
or READ TABLE ITAB WITH KEY MATNR = mat1.
This will get a single row.
However, for all entries is generally used as an alternative of join.
e.g. U want some values from Database table DB1 based upon the values in ITAB1.
Then u write :
SELECT col1 col2 into corresponding fields of table ITAB2 from DB1 for all entries in ITAB1 where DB1-col1 = ITAB1-col1.
Hence READ statement is used to read data from internal tables.
FOR ALL ENTRIES is used to get data from database based on the values in another internal table
Regards,
Himanshu.
‎2007 Jun 18 10:24 AM
Hi,
<u><b>For All Entries:</b></u>
The WHERE clause of the SELECT statement has a special variant that allows you to derive
conditions from the lines and columns of an internal table:
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.
<u><b>Read Table:</b></u>
To read a single line of any table, use the statement:
READ TABLE <itab> <key> <result>.
For the statement to be valid for any kind of table, you must specify the entry using the key and
not the index. You specify the key in the <key> part of the statement. The <result> part can
specify a further processing option for the line that is retrieved.
If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is
not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX
is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate
entries, the first entry is read.
Specifying the Search Key
The search key may be either the table key or another key.
Using the Table Key
To use the table key of <itab> as a search key, enter <key> as follows:
READ TABLE <itab> FROM <wa> <result>.
or as follows
READ TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values
of the key fields are taken from the corresponding components of the work area.
In the second case, you have to supply the values of each key field explicitly. If you do not know
the name of one of the key fields until runtime, you can specify it as the content of a field <ni>
using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the
system converts them.
The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is
independent of the number of table entries.
Using a Different Search Key
To use a key other than the table key as a search key, enter <key> as follows:
READ TABLE <itab> WITH KEY = <f> <result>.
or as follows
READ TABLE <itab> WITH KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, the whole line of the internal table is used as the search key. The contents of
the entire table line are compared with the contents of field <f>. If <f> is not compatible with the
line type of the table, the value is converted into the line type. The search key allows you to find
entries in internal tables that do not have a structured line type, that is, where the line is a single
field or an internal table type.
In the second case, the search key can consist of any of the table fields <k1>...<kn>. If you do not
know the name of one of the components until runtime, you can specify it as the content of a field
<ni> using the form (<ni>) = <fi>. If <ni> is empty when the statement is executed, the search
field is ignored. If the data types of <fi> are not compatible with the components in the internal
table, the system converts them. You can restrict the search to partial fields [Page 196] by
specifying offset and length.
The search is linear for all table types. The runtime is in linear relation to the number of table
lines.
Regards,
Bhaskar
‎2007 Jun 18 10:28 AM
Hi Prashanth,
You have to use the Read Statement on the Internal tables only. You should not use directly READ statement on the database tables.
You should go FOR ALL ENTRIES statement when u select statements on the Database tables. This is basically used for the Performance on the Select queries.
Reward Points if the message is useful.
Thanks.
Hari krishna