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,126

Hi,

I waned to use read table as follows :

read table ITAB with key kschl = 'JOCM' kschl = 'JOC1'

kschl = 'JET1'.

But its not possible.

Any alternative??

reagrds,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,100

Hi,

You can use LOOP AT ..EXIT..ENDLOOP..



LOOP AT ITAB WHERE kschl = 'JOCM' OR kschl = 'JOC1' OR
                                    kschl = 'JET1'.

  EXIT.

ENDLOOP.

IF SY-SUBRC = 0.
** Record found.

ELSE.

** record not found..  
ENDIF.

Thanks,

Naren

11 REPLIES 11
Read only

Former Member
0 Likes
1,101

Hi,

You can use LOOP AT ..EXIT..ENDLOOP..



LOOP AT ITAB WHERE kschl = 'JOCM' OR kschl = 'JOC1' OR
                                    kschl = 'JET1'.

  EXIT.

ENDLOOP.

IF SY-SUBRC = 0.
** Record found.

ELSE.

** record not found..  
ENDIF.

Thanks,

Naren

Read only

Former Member
0 Likes
1,100

loop at itab where kschl = 'JOCM' OR

kschl = 'JOC1' OR

kschl = 'JET1'.

endloop.

Read only

Former Member
0 Likes
1,100

hi sachin,

try like this,

read table ITAB with key kschl = 'JOCM' 'JOC1' 'JET1'.

regards,

seshu.

Read only

Former Member
0 Likes
1,100

Hi,

We can not use the Read table with more than 1 equality for a Field, instead of this you can use the LOOP statment, if the loop success then use the exit statment to exit from the loop to aviod more loopings.

Regards

Sudheer

Read only

gopi_narendra
Active Contributor
0 Likes
1,100
loop at itab.
if itab-kschl = 'JOCM' or
   itab-kschl = 'JOC1' or
   itab-kschl = 'JET1'.
,,,,,,,,,,,,,,,,,,,,,,,,<write ur code here based on the validation>
endif.
endloop.

Regards

Gopi

Read only

Former Member
0 Likes
1,100

hi,

Use Loop statment ...

i.e,

LOOP AT ITAB WHERE KSCHL = 'JOCM' OR 
                                    KSCHL = 'JOC1'  OR
                                    KSCHL = 'JET1'.
 
 
ENDLOOP.

Read only

S0025444845
Active Participant
0 Likes
1,100

hi,

You can use

loop at itab into wa_itab where kschl in( 'JOCM' , 'JOC1' , 'JET1' ).

regards,

sudha

Read only

Former Member
0 Likes
1,100

LOOP AT ITAB  .
if   ITAB-kschl = 'JOCM' OR  ITAB -kschl = 'JOC1' OR   ITAB-kschl = 'JET1'.
Endif .
 
ENDLOOP

Girish

Read only

Former Member
0 Likes
1,100

hi,

try like this

read table ITAB with key kschl = 'JOCM' [and/or] kschl = 'JOC1'

[and/or] kschl = 'JET1'.

or

loop at itab where kschl = 'JOCM' [or] kschl = 'JOC1'

[or] kschl = 'JET1'.

if sy-subrc eq 0.

write:/10 itab-kschl.

endif.

endloop.

if helpful reward some points.

with regards,

suresh.

Read only

former_member186741
Active Contributor
0 Likes
1,100

read table ITAB with key kschl = 'JOCM'.

if sy-subrc <> 0.

read table ITAB with key kschl = 'JOC1'.

if sy-subrc <> 0.

read table ITAB with key kschl = 'JET1'.

endif.

endif.

Read only

Former Member
0 Likes
1,100

Hi,

You cannot use 3 or more values for a single field in a read statement. Looping at the table can be some times very expensive if the size of the table is very large. One more alternative is..

read table ITAB with key kschl = 'JOCM'.
if sy-subrc <> 0.
  read table ITAB with key kschl = 'JOC1'.
  if sy-subrc <> 0.
    read table ITAB with key kschl = 'JET1'.
  endif.
endif.

Using Binary search in this case will be very helpful.

Regards,

Richa