‎2008 Feb 28 8:13 AM
Dear all
i have one internal table and there are 100 records.
I used read table command to read this table with key condition
when i read there are more than one records selected.
i want to put those records to another itab (same line type)
can you please help me to solve this.
‎2008 Feb 28 8:57 AM
Hi,
READ for any Internal Table
Reads a line of an internal table.
Syntax
READ TABLE <itab> FROM <wa>
|WITH TABLE KEY <k1> = <f1>... <kn> = <fn>
|WITH KEY = <f>
|WITH KEY <k1> = <f1>... <kn> = <fn>
INTO <wa> [COMPARING <f1> <f2>... |ALL FIELDS]
[TRANSPORTING <f1> <f2>... |ALL FIELDS|NO FIELDS]
|ASSIGNING <FS>
|REFERENCE INTO <dref>.
This statement reads either the line of the internal table with the same key as specified in the work area <wa>, the line with the key specified in the TABLE KEY addition, the line that corresponds fully to <f>, or the one corresponding to the freely-defined key in the KEY addition. The contents of the line are either written to the work area <wa>, or the line is assigned to the field symbol <FS>. If you assign the line to a work area, you can compare field contents and specify the fields that you want to transport.
READ for Index Tables
Reads a line of an internal table.
Syntax
READ TABLE <itab> INDEX <idx> INTO <wa>...
| ASSIGNING <FS>
| REFERENCE INTO <dref>.
The line with index 7 is read. The result is specified as with any internal table.
READ for Lists
Reads the contents of a line from a list.
Syntax
READ LINE <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]
|CURRENT LINE
[FIELD VALUE <f1> [INTO <g1>]... <fn> [INTO <gn>]].
Reads either the line <n> on the current or specified list or page, or the last line to have been selected by the user. The addition specifies the fields that you want to read, and the target fields into which they should be placed. The entire line is always placed in the system field SY-LISEL, and the HIDE area is filled for the line.
Regards,
Priya.
‎2008 Feb 28 8:15 AM
hi Nelson,
with READ TABLE you can always read only one record. If you think that more records will match your criteria, you have to use LOOP:
LOOP AT itab INTO wa WHERE ...
APPEND wa TO itab2.
ENDLOOP.
Now you have all matching records in itab2.
hope this helps
ec
‎2008 Feb 28 8:15 AM
hi
in a LOOP AT.....
use Read internal table....
Read table doesn't allow ne operator.
It reads only one record...Either by index or key.
READ TABLE MY_TAB INDEX 1.
READ TABLE MY_TAB WITH KEY CODE = 'ATG'.
these are the results for SY-SUBRC checks after read table
SY-SUBRC = 0:
An entry was read.
SY-TABIX is set to the index of the entry.
SY-SUBRC = 2:
An entry was read.
SY-TABIX is set to the index of the entry. This return code can only occur when you use the COMPARING addition. For further detauls, refer to the COMPARING section of the additions
SY-SUBRC = 4:
No entry was read.
The value of SY-TABIX depends on the table type and whether the BINARY SEARCH addition was specified.
If the table is a SORTED TABLE or a table sorted in ascending order of the type STANDARD TABLE with the BINARY SEARCH addition, SY-TABIX refers to the next-highest index.
Otherwise, SY-TABIX is undefined.
SY-SUBRC = 8:
No entry was read.
This return code only occurs with a SORTED TABLE or a STANDARD TABLE with the BINARY SEARCH addition. SY-TABIX is set to the number of all entries plus 1.
Reading records with keys
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
Reading lines with Index
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm
reward if help.
‎2008 Feb 28 8:17 AM
Hi nelson,
Unfortunately, READ TABLE api does not support this functionality.
To achieve this, you can use LOOP AT keyword where you can specify itab as your target.
I hope this will help.
Edited by: Ramanath Kulkarni on Feb 28, 2008 9:19 AM
‎2008 Feb 28 8:29 AM
Hi,
READ TABLE is meant for reading a row and not rows.....
This statement reads a row from internal table itab. You have to specify the row by either naming values table_key for the table key, a free condition free_key or an index index. The latter choice is possible only for index tables. The output result result determines when and where the row contents are read.
If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
So better use
loop at itab where cond
move-corresponding itab to new_itab
append new_itab.
endloop.
Cheers,
jose.
‎2008 Feb 28 8:31 AM
No need to go for READ . simple use MOVE-CORRESPONDING.
for this you also no need to go for any loop statement.
syntax:
MOVE-CORRESPONDING itab1 to itab2 with key <-->.
‎2008 Feb 28 9:04 AM
‎2008 Feb 28 8:57 AM
Hi,
READ for any Internal Table
Reads a line of an internal table.
Syntax
READ TABLE <itab> FROM <wa>
|WITH TABLE KEY <k1> = <f1>... <kn> = <fn>
|WITH KEY = <f>
|WITH KEY <k1> = <f1>... <kn> = <fn>
INTO <wa> [COMPARING <f1> <f2>... |ALL FIELDS]
[TRANSPORTING <f1> <f2>... |ALL FIELDS|NO FIELDS]
|ASSIGNING <FS>
|REFERENCE INTO <dref>.
This statement reads either the line of the internal table with the same key as specified in the work area <wa>, the line with the key specified in the TABLE KEY addition, the line that corresponds fully to <f>, or the one corresponding to the freely-defined key in the KEY addition. The contents of the line are either written to the work area <wa>, or the line is assigned to the field symbol <FS>. If you assign the line to a work area, you can compare field contents and specify the fields that you want to transport.
READ for Index Tables
Reads a line of an internal table.
Syntax
READ TABLE <itab> INDEX <idx> INTO <wa>...
| ASSIGNING <FS>
| REFERENCE INTO <dref>.
The line with index 7 is read. The result is specified as with any internal table.
READ for Lists
Reads the contents of a line from a list.
Syntax
READ LINE <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]
|CURRENT LINE
[FIELD VALUE <f1> [INTO <g1>]... <fn> [INTO <gn>]].
Reads either the line <n> on the current or specified list or page, or the last line to have been selected by the user. The addition specifies the fields that you want to read, and the target fields into which they should be placed. The entire line is always placed in the system field SY-LISEL, and the HIDE area is filled for the line.
Regards,
Priya.
‎2008 Feb 28 9:07 AM
‎2008 Feb 28 9:15 AM
With Read U'll get only one record at a time ..
So go for Loop ... endloop.
Loop at itab where field1 = <condition>...
itab1 = itab.
append itab1.
clear itab1.
Endloop.
‎2008 Feb 28 9:16 AM
filter the records using where clause and append the same.
Loop at itab1 into wa_itab where <condition>.
apeend wa_itab to itab2.
endloop.
‎2008 Apr 10 9:38 AM
hi,
loop at it into wa .
read table using into wa conditions and set sy-tabix.
append wa from itab.
modify itab.
clear wa.
if sy-tabix >=100.
exit.
end if.
endloop.
loop at it into wa where sy-tabix > 100.
-
endloop.
reward points, if useful.
‎2008 Apr 10 9:59 AM
Hi,
We cant able to fetch more thatn one record by using read statement.
inorder to fetch more than one record you can use if condition in loop or where condition applied to the loop.
loop at itab into w_itab.
if w_itab-field1 = 'xyz' and w_itab-field2 = 'xyz'.
append w_itab to jtab.
endif.
endloop.
Here both itab and jtab must be of same structure.
Otherwise you can use
move-corresponding fields of w_itab to jtab.
I think it is useful for you.
‎2023 May 02 3:19 PM
The thread is rather old, but since I stubled over it while searching for the answer for this very questions, I post here how I solved it.
to copy parts of an internal table to another one the VALUE statement with FOR ... IN can be used:
lt_data_2 = value #( FOR wa in lt_data WHERE ( fieldname = <value> ) ( CORRESPONDING #( wa ) ) ).
The statment copies all entries from itab lt_data to itab lt_data_2 where the field "fieldname" has the content of <value>