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

RANGES

Former Member
0 Likes
836

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.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
820

Hi,


Select single * from mara 
           into mara where
               matnr in r_matnr.
if sy-subrc ne 0.
   "<<<<< Error
endif.

aRs

6 REPLIES 6
Read only

former_member194669
Active Contributor
0 Likes
821

Hi,


Select single * from mara 
           into mara where
               matnr in r_matnr.
if sy-subrc ne 0.
   "<<<<< Error
endif.

aRs

Read only

Former Member
0 Likes
820

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**

Read only

former_member192429
Active Participant
0 Likes
820

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

Read only

Former Member
0 Likes
820

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.

Read only

Former Member
0 Likes
820

DATA: W_MARA TYPE MARA.

SELECT SINGLE * FROM MARA INTO W_MARA WHERE MATNR IN R_MATNR.

IF SY-SUBRC <> 0.

*message.

ENDIF.

Read only

uwe_schieferstein
Active Contributor
0 Likes
820

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