Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Read statement in abap

Former Member
0 Likes
1,786

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

7 REPLIES 7
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,076

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.

Read only

Former Member
0 Likes
1,076

Hi,

You cant use "with key" & "index"...together....just check your requirement....and use according to the rule....

Arunima

Read only

Former Member
0 Likes
1,076

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.

Read only

Former Member
0 Likes
1,076

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.

Read only

Former Member
0 Likes
1,076

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

Read only

Former Member
0 Likes
1,076

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.

Read only

Former Member
0 Likes
1,076

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