‎2008 Nov 13 6:11 AM
Hello Experts,
Can I use both index and key addition in READ statment like
Read table itab from index i with key id = 'XYZ'.
Actually I am using that but the read statement is not following both the addition.Is there any other way out in which I can do that.I dont want to use LOOP...ENDLOOP
‎2008 Nov 13 6:15 AM
Index fetch with read can be done...but i guess it reads only one index at a time.
read table itab index 1 into wa transporting all fields.
instead go for
LOOP AT itab INTO wa TO 6.
-
ENDLOOP.
LOOP AT itab INTO wa from 1 TO 6.
-
ENDLOOP.
‎2008 Nov 13 6:16 AM
Hi,
You cant use "with key" & "index"...together....just check your requirement....and use according to the rule....
Arunima
‎2008 Nov 13 6:17 AM
You can simply loop at internal table as follows :
LOOP AT IT_TAB WHERE KEY = 'XYZ'.
ENDLOOP.
This cade allows you to loop across table with key records that you want.
Then you can modisy the records in table one by one.
‎2008 Nov 13 6:18 AM
Hi Priya,
You can use READ Statement either with KEY or From INDEX only...
You can use both in a single READ Statement but depending on your requirement..
Regards,
Ravi Kiran.
‎2008 Nov 13 6:26 AM
I don't think you can use both at the same time...
suppose you have an internal table of the below format....
material plant zone
M1 P1 N
M2 P2 S
M3 P3 E
M4 P4 W
suppose you want a record with key material = M2 and also index = 4.
they are 2 different records...and there is no 1 particular record that satisfies the condition...
if you want both the records use a loop with where condition and both seperated by OR.
then you can get both the records.
Read statement can give only 1 row....
i think the above is the problem you are facing.
Regards,
Srinivas
‎2008 Nov 13 6:29 AM
Hi *priya singh *.
You are not able to use index and with key parley in read statement. you should use LOOP..END LOOP only..
See following...
I think in your requirement you want i th record which is satisfied id = 'XYZ'.
use following code...
loop at itab into wa where id = 'XYZ'.
if sy-index eq = i.
" Assign/take values here
EXIT. " --> Immediately exit the loop after satisfied your condition
exit.
endloop.Regards,
Mahi.
‎2008 Nov 13 6:30 AM
read table it [into wa] [index i | with key keyexp [binary search] ] [comparing cmpexp] [transporting texp].
either we can use index or with key we cannot use both