‎2007 Aug 30 8:29 PM
i Have declared a range R_matnr which gets its values from an internal table.
I want to check if the R_Matnr values are present in the table MARA or not . If they are not present then simply flag an error message. What is the simplest procedure.
‎2007 Aug 30 8:32 PM
Hi,
Select single * from mara
into mara where
matnr in r_matnr.
if sy-subrc ne 0.
"<<<<< Error
endif.
aRs
‎2007 Aug 30 8:32 PM
Hi,
Select single * from mara
into mara where
matnr in r_matnr.
if sy-subrc ne 0.
"<<<<< Error
endif.
aRs
‎2007 Aug 30 8:33 PM
Hi,
SELECT matnr
INTO w_matnr
FROM MARA
UPTO 1 ROWS
WHERE matnr IN r_matnr.
if sy-subrc NE 0.
MESSAGE exxx with 'text.
ENDIF.
Thanks and Best Regards,
Vikas Bittera.
**Reward if useful**
‎2007 Aug 30 8:34 PM
I think just like the select options you can use Ranges in your WHERE condition of query.
Select count(*) from MARA where matnr in r_matnr.
if sy-subrc = 0.
else.
message E000(00) with 'Materials do not exist'.
endif.
-Kriss
‎2007 Aug 30 8:35 PM
Do you want to know if any of them are in MARA or if all of them are in MARA? If you have to know if all of them are in MARA or not, you have to loop as below.
loop at r_matnr.
select single * from mara where matnr = r_matnr-low. <-- assuming you have them as single values, not ranges.
if sy-subrc <> 0.
*-- this is not there.
endif.
endloop.
If you don't care about each one of them but at least one should be there, then you can simply do this
select count( * ) from mara where matnr in r_matnr.
if sy-dbcnt > 0.
*-- At least one is there
endif.
‎2007 Aug 30 8:35 PM
DATA: W_MARA TYPE MARA.
SELECT SINGLE * FROM MARA INTO W_MARA WHERE MATNR IN R_MATNR.
IF SY-SUBRC <> 0.
*message.
ENDIF.
‎2007 Aug 30 8:50 PM
Hello Krish
I assume you want to check whether all material numbers in your range are actually found in MARA.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_SELECT_NOT_EXISTS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_select_not_exists.
DATA:
gd_count TYPE i,
gt_matnr TYPE RANGE OF matnr,
gs_rng LIKE LINE OF gt_matnr.
START-OF-SELECTION.
gs_rng-sign = 'I'.
gs_rng-option = 'EQ'.
gs_rng-low = '000000000000000023'. " exists
APPEND gs_rng TO gt_matnr.
gs_rng-low = '000000000000000039'. " exists not
APPEND gs_rng TO gt_matnr.
gs_rng-low = '000000000000000043'. " exists
APPEND gs_rng TO gt_matnr.
CHECK ( gt_matnr IS NOT INITIAL ).
SORT gt_matnr BY low.
DELETE ADJACENT DUPLICATES FROM gt_matnr
COMPARING low.
SELECT COUNT(*) INTO gd_count FROM mara
WHERE matnr IN gt_matnr. " fills sy-dbcnt
DESCRIBE TABLE gt_matnr. " fills sy-tfill
IF ( sy-tfill NE sy-dbcnt ).
MESSAGE 'Not all materials found in MARA' TYPE 'I'.
ENDIF.
END-OF-SELECTION.Regards
Uwe