‎2007 May 01 6:01 PM
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.
‎2007 May 01 6:04 PM
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
‎2007 May 01 6:44 PM
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
‎2007 May 01 6:48 PM
It has to be a loop.
LOOP AT itab WHERE matnr = t_mara1-matnr
OR spart = 'AA'
OR spart = 'BB'.
ENDLOOP.
‎2007 May 01 6:53 PM
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
‎2007 May 01 6:59 PM
You are correct, I was thinking of the database table MARA, not realizing he meant an itab with name T_MARA.
‎2007 May 01 7:05 PM
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.
‎2007 May 01 7:17 PM
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
‎2007 May 01 8:35 PM
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