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 statement

Former Member
0 Likes
792

Hi all,

is there any way to use read table like this?

read table t_mara with key matnr = t_mara1-matnr

spart in ( 'aa' ,'bb').

i need to compare with these two values . if one of the value satisfies sy-subrc should be equal to '0'. just like select statement with OR condition.

8 REPLIES 8
Read only

Former Member
0 Likes
770

Hi,

you cannot use READ TABLE for multiple values..

Instead you can use LOOP AT ..EXIT..ENDLOOP.

Ex..

LOOP AT T_MARA WHERE MATNR = 'TEST'

AND ( SPART = 'AA' OR SPART = 'BB' ).

EXIT.

ENDLOOP.

IF SY-SUBRC = 0.

write: / 'Found'.

ELSE.

write: / 'NOT Found'.

Endif.

Thanks,

Naren

Read only

Former Member
0 Likes
770

I don't think you can use a read statement that way, and looping at a database table is obsolete. But you can use a select statement. This should work:

SELECT * FROM t_mara INTO w_mara

WHERE ( spara = 'aa' OR spara = 'bb' )

AND matnr = t_mara1-matnr.

    • put your processing code here

ENDSELECT.

I hope this helps.

- April King

Read only

Former Member
0 Likes
770

It has to be a loop.

LOOP AT itab WHERE matnr = t_mara1-matnr
                OR spart = 'AA' 
                OR spart = 'BB'.
ENDLOOP

.

Read only

0 Likes
770

I think he meant..

LOOP AT itab WHERE matnr = t_mara1-matnr

and ( spart = 'AA' or spart = 'BB' ).

ENDLOOP.

You can also use two READs & check if either of the subrc is 0 with aflag.. I think, the loop is better..

~Suresh

Read only

0 Likes
770

You are correct, I was thinking of the database table MARA, not realizing he meant an itab with name T_MARA.

Read only

0 Likes
770

Even though I thought that it is an AND instead of an OR, her statement 'even if one of them is satisfied' made me tilt towards OR.

But you may be right using AND.

Read only

Former Member
0 Likes
770

Hi Priya,

We can do the coding as below:

DATA: spfli_tab TYPE SORTED TABLE OF spfli.

SELECT *

FROM spfli

INTO TABLE spfli_tab

WHERE carrid = 'LH'.

READ TABLE spfli_tab

WITH TABLE KEY carrid = 'LH' connid = '2402'.

Similarly I feel we can write your Read Stmt like this:

Read table t_mara with table key matnr = t_mara1-matnr

spart = 'aa'

spart = 'bb'.

Please let me know if any issues.

Regards,

Daniel

Read only

Former Member
0 Likes
770

Hey Priya,

Sorry !

Read table t_mara with table key matnr = t_mara1-matnr

spart = 'aa' or

spart = 'bb'. Will give an error.

We cannot use spart twice.

Regards,

Daniel

I