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 table

Former Member
0 Likes
1,115

i have to read a internal table with two key values for the same field.

itab contains the following records:

<f1> <f2> <f3>

val1 x x

val2 x x

val3 x x

for <f1> = val1 or val2 i want to read itab.

read table <itab>into <wa> with key <f1> =val1 or val2. this stmt doesnt work..so how can i do it?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,084

Hi,

read will get u only one record at a time.

if u want to check whether the record is existing or not with both the case do like below.


read table itab with key <f1> = 'VAL1'.
if sy-subrc <> 0.
  read table itab with key <f1> = 'VAL2'.
    if sy-subrc = 0.
    "ur logic
    endif.
else.
*ur logic
endif.

rgds,

bharat.

11 REPLIES 11
Read only

Former Member
0 Likes
1,084

hi

u cannot read the record in that way.

loop the internal table.

use if -endif condition to check the same.

regards,

madhu

Read only

Former Member
0 Likes
1,084

i have to read a internal table with two key values for the same field.

itab contains the following records:

<f1> <f2> <f3>

val1 x x

val2 x x

val3 x x

for <f1> = val1 or val2 i want to read itab.

read table <itab>into <wa> with key <f1> =val1 or val2. this stmt doesnt work..so how can i do it?

u r code only excetues but small modification is needed i.e.

read table <itab>into <wa> with key <f1> =val1 or <f1> =val2.

its enough..

reward if useful

Read only

Former Member
0 Likes
1,084

Hi

Try like this.

read table <itab>into <wa> with key <f1> = val1

or <f1> = val2.

Regards

Haritha.

Read only

Former Member
0 Likes
1,084

Read the internal table twice ...

read table itab into wa with key f1 = val1.

if sy-subrc <> 0.

read table itab into wa with key f1 = val2.

endif.

Read only

Former Member
0 Likes
1,084

Hi rakhi,

U can try this way

read table <itab>into <wa> with key (f1 =val1 or f1=val2).

reward if helpful

raam

Read only

0 Likes
1,084

i have already tried these stmts ..bt these dont works read table

<itab>into <wa> with key <f1> = val1 or <f1> = val2.

read table <itab>into <wa> with key ( <f1> = val1 or <f1> = val2).

Read only

Former Member
0 Likes
1,085

Hi,

read will get u only one record at a time.

if u want to check whether the record is existing or not with both the case do like below.


read table itab with key <f1> = 'VAL1'.
if sy-subrc <> 0.
  read table itab with key <f1> = 'VAL2'.
    if sy-subrc = 0.
    "ur logic
    endif.
else.
*ur logic
endif.

rgds,

bharat.

Read only

Former Member
0 Likes
1,084

hi you cannot use OR in read table.

to perform what you want you can do like tis.

read table <itab>into <wa> with key <f1> .

if sy-subrc <> 0.

read table <itab>into <wa> with key <f1> val2.

endif.

reward if useful.

Read only

0 Likes
1,084

thanks all SOLVED

Read only

0 Likes
1,084

How did u wrote

defenitely it should be or what i have given previously.. if it is wrong please mention how did u wrote

Read only

0 Likes
1,084

read table <itab>into <wa> with key <f1> =val1 or <f1> =val2. does not work

i have used two read stmts ie.

read table <itab>into <wa> with key <f1> =val1.

read table <itab>into <wa> with key <f1> =val2 .

Edited by: rakhi bose on Apr 24, 2008 12:37 PM