2007 Feb 20 5:03 PM
Hi
I have got a read table statement with a where clause. The thing is that I have do one thing if there is exactly one match and another thing if there is not match.
As I understand the sy-subrc returns 0 if the query was executed correct. Due to this I will get a sy-subrc=0 if there is no match. So how do I check weather there is one or no matches in the read table statement?
Regards
Torben
2007 Feb 20 5:21 PM
To Check if there is exactly one match or no mat at all:
read table itab with key field = <value>.
if sy-subrc = 0.
write:/ 'One match'.
else.
write:/ 'No match'.
endif.
Check for Not even one match/ atleast one match
loop at itab where field = <value>.
exit.
endloop.
if sy-subrc = 0.
write:/ 'Atleast one match'.
else.
write:/ 'No matches at all'.
endif.
Regards,
Ravi
Hi
I have got a read table statement with a where clause. The thing is that I have do one thing if there is exactly one match and another thing if there is not match.
As I understand the sy-subrc returns 0 if the query was executed correct. Due to this I will get a sy-subrc=0 if there is no match. So how do I check weather there is one or no matches in the read table statement?
Regards
Torben
2007 Feb 20 5:06 PM
Hi,
The sy-subrc will be greater than zero if there is no entry for the corresponding match..
Example
-
READ TABLE T_MARA WITH KEY MATNR = '12121'.
IF SY-SUBRC = 0.
WRITE: / 'Entry found for the corresponding material'.
ELSE.
WRITE: / 'Entry NOT found'.
ENDIF.
THanks,
Naren
2007 Feb 20 5:19 PM
Hi,
You can code like this:
READ TABLE T_MARA WITH KEY MATNR = '12121'.
IF SY-SUBRC = 0.
WRITE: / 'One Entry Found'.
ELSEIF SY-SUBRC =1.
WRITE: / '2 ENTRIES FOUND'.
ELSEIF SY-SUBRC =2.
WRITE: / '3 ENTRIES FOUND'.
ELSEIF SY-SUBRC =3.
WRITE: / 'MORE THAN 3 ENTRIES FOUND'.
ELSE
WRITE: / 'NO ENTRIES FOUND'.
ENDIF.
iF HELPS PLS MARK POINTS.
THANKS.
radha.
2007 Feb 20 5:21 PM
To Check if there is exactly one match or no mat at all:
read table itab with key field = <value>.
if sy-subrc = 0.
write:/ 'One match'.
else.
write:/ 'No match'.
endif.
Check for Not even one match/ atleast one match
loop at itab where field = <value>.
exit.
endloop.
if sy-subrc = 0.
write:/ 'Atleast one match'.
else.
write:/ 'No matches at all'.
endif.
Regards,
Ravi
2007 Feb 20 5:42 PM
Try:
DATA: next LIKE sy-tabix,
counter TYPE i,
old_key LIKE itab-f1.
SORT itab BY f1.
READ TABLE itab WITH KEY
f1 = 'whatever'
BINARY SEARCH.
IF sy-subrc <> 0.
WRITE 'No matches'.
ELSE.
next = sy-tabix + 1.
old_key = itab-f1.
READ TABLE itab INDEX next.
IF sy-subrc = 0.
IF itab-f1 = old_key.
WRITE 'More than one match'.
ELSE.
WRITE 'Exactly one match'.
ENDIF.
ELSE.
WRITE 'Exactly one match'.
ENDIF.
ENDIF.
Rob
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |