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

error in the code with multiple where conditions

Former Member
0 Likes
1,391

Hi all,

select single * from marC where matnr = '1234' AND

WERKS = 'ABC' AND

WERKS = 'XYZ' .

even though the material exist in both the plant it returns a sy-subrc eq to 4.

Though it supposed to return sy-subrc eq 0.

Thanks

Suchitra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,372

select single * from marC where matnr = '1234' AND

WERKS in ( 'ABC', 'XYZ').

Try This

The select U have written always return sy-subrc 4 because u where checking whether plant is both ABC and XYZ which is always false . hence the select query was failing

16 REPLIES 16
Read only

Former Member
0 Likes
1,373

select single * from marC where matnr = '1234' AND

WERKS in ( 'ABC', 'XYZ').

Try This

The select U have written always return sy-subrc 4 because u where checking whether plant is both ABC and XYZ which is always false . hence the select query was failing

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,372

Try this.

select single * from marC where matnr = '1234'
        AND ( WERKS = 'ABC' or WERKS = 'XYZ'  ).

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,372

Hi

Use the <b>CONVERSION_EXIT_ALPHA_INPUT or OUTPUT </b> for the material field and pass the material no, because it has to be 18 char.

select single * from marC where matnr = <b>'000000000000001234' AND

WERKS in ( 'ABC', 'XYZ').</b>

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
1,372

use ranges :

tables : marc.

range p_werks for marc-werks.

start-of-selection.

r_werks-low = '1234'.

r_werks-option = 'EQ'.

r_werks-sign = 'I'.

append r_werks.

r_werks-low = '1235'.

r_werks-option = 'EQ'.

r_werks-sign = 'I'.

append r_werks.

select single * from marC

where matnr = '1234' AND

WERKS in p_werks.

Read only

Former Member
0 Likes
1,372

Hi ALL,

I WANT TO CHECK WHETHER THE MATERIAL IS PRESENT IN BOTH THE PLANTS THEN ONLY IT SHOULD A SY-SUBRC EQ 0

EVEN THOUGH IT EXISTS IN ONE PLANT IT SHOULD RETURN A SY-SUBRC NE 0.

select single * from marC where matnr = '1234' AND

WERKS = ('ABC' , 'XYZ' ).

WHEN I DO THIS EVEN THOUGH IT EXIST IN ONE PLANT IT RETURNS A SY-SUBRC EQ 0.

WHICH IS WRONG

lET ME KNOW HOW TO ACHIEVE THIS

THANKS

Read only

0 Likes
1,372

Hi

In that case use like this and see, still it gives error or not.

select single * from marC where matnr = '000000000000001234'

AND ( WERKS = 'ABC' and WERKS = 'XYZ' ).

Reward points if useful

Regards

Anji

Read only

0 Likes
1,372

select single * from marC

where matnr = '1234' AND

( WERKS = 'ABC' and WERKS = 'XYZ' ).

Read only

0 Likes
1,369

Hi,

With the syntax you provided it gives a sy-subrc eq 4 even though it exists in both the plants

Thanks

Read only

0 Likes
1,369

select single * from marC

where matnr = '000000000000001234' AND

( WERKS = 'ABC' and WERKS = 'XYZ' ).

try this one.

Read only

0 Likes
1,369

Hi ,

I DID TRIED THIS ONE .

EVEN THOUGH THE MATERIAL EXISTS IN BOTH THE PLANTS IT RETURNS A SY-SUBRC EQ 4

LET ME KNOW

THANKS

Read only

0 Likes
1,369

You cannot use one SELECT SINGLE. intstead try with two ie

select single * from marC 
where matnr = '1234' AND
WERKS = 'ABC'. 
if sy-subrc eq 0.
select single * from marC 
where matnr = '1234' AND
      WERKS = 'XYZ' . 
if sy-subrc eq 0.
* record found
else.
*error.
endif.
endif.

~Suresh

Read only

0 Likes
1,369

Hi Suresh ,

In your case even though it exists in one plant the sy-subrc is equal to 0 right.

I want the sy-subrc to be 0 only when it exist in both the palnts

Thanks

Read only

0 Likes
1,369

pl see my edited post above with two select singles.

~Suresh

Read only

0 Likes
1,369

do not use select single and it will get one record from database.

use select * from marc and try now.

Read only

0 Likes
1,369

try like this and you will get exact results :

tables : marc .

data wa_marc like marc occurs 0 with header line.

parameters : p_matnr like marc-matnr.

*ranges : r_werks for marc-werks.

start-of-selection.

*r_werks-low = '1000'.

*r_werks-sign = 'I'.

*r_werks-option = 'EQ'.

*append r_werks.

*

*r_werks-low = '1100'.

*r_werks-sign = 'I'.

*r_werks-option = 'EQ'.

*append r_werks.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = p_matnr

IMPORTING

OUTPUT = p_matnr

.

select * from marc into table wa_marc

where matnr = p_matnr

and ( werks = '1000' and werks = '1100' ).

if sy-subrc eq 0.

write:/ 'Plant is okay'.

endif.

Reward Points if it is helpful

Thanks

Seshu

Read only

0 Likes
1,369

Hi ALL,

THANKS FOR YOUR REPLIES.

i THOUGH OF DOING THIS WITHOUT CREATING ANY INTERNAL TABLES AND WITH A SINGLE STATEMENT.

I guess it doesn't seem to work that way

I went multiple select statements

I awarded points to all

Thanks AGAIN