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

using the IN statement

Former Member
0 Likes
1,140

Can soembody send soem sample code using an IN statement? I am using it but get errors. Proble is the editor is in German and I don't know what it is saying!

IF COMM_STRUCTURE-COSTELMNT IN ('84300005','84300006').

RESULT = 'PM_LABOR'.

elseif COMM_STRUCTURE-COSTELMNT IN (61100950).

RESULT = 'PM_NON_STOCK'.

endif.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,110

Hi,

For IF statement you cannot use fixed values..Instead create a ranges..and use it in your IN..

Example..

RANGES: R_MATNR FOR MARA-MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = 'EQ'.

R_MATNR-LOW = 'ABCD'.

APPEND R_MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = 'EQ'.

R_MATNR-LOW = 'ABCDADSF'.

APPEND R_MATNR.

IF MARA-MATNR IN R_MATNR.

WRITE: / 'TRUE'.

ELSE.

WRITE: / 'FALSE'.

ENDIF.

Thanks

Naren

10 REPLIES 10
Read only

Former Member
0 Likes
1,111

Hi,

For IF statement you cannot use fixed values..Instead create a ranges..and use it in your IN..

Example..

RANGES: R_MATNR FOR MARA-MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = 'EQ'.

R_MATNR-LOW = 'ABCD'.

APPEND R_MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = 'EQ'.

R_MATNR-LOW = 'ABCDADSF'.

APPEND R_MATNR.

IF MARA-MATNR IN R_MATNR.

WRITE: / 'TRUE'.

ELSE.

WRITE: / 'FALSE'.

ENDIF.

Thanks

Naren

Read only

0 Likes
1,110

The sample code I am looing at uses it. I thought it was due to missing spaces. I can't really use a range becuase in some cases it isn't a range of values so i quess I could use the equal to

Read only

Former Member
0 Likes
1,110
IF COMM_STRUCTURE-COSTELMNT IN ( '84300005' , '84300006' ).
RESULT = 'PM_LABOR'.
elseif COMM_STRUCTURE-COSTELMNT IN ( '61100950' ).
RESULT = 'PM_NON_STOCK'.
endif. 

Make sure you have space after and before ().

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
1,110

I did that and now it says

E:Comma without preceding colon (after IF ?).

Read only

0 Likes
1,110

Looks like the problem is with the statement before / after the IF statement.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
1,110

Try this.




IF   ( COMM_STRUCTURE-COSTELMNT = '84300005'
    or COMM_STRUCTURE-COSTELMNT = '84300006' ).
   RESULT = 'PM_LABOR'.
elseif COMM_STRUCTURE-COSTELMNT = '61100950' .
   RESULT = 'PM_NON_STOCK'.
endif. 


Regards,

Rich Heilman

Read only

0 Likes
1,110

WHEN i DO WHAT Narendran suggests it works. I think he is correct and I can't use constants with and IF

Read only

Former Member
0 Likes
1,110

Hi,

For single values also you can use the RANGES..

You have to give EQ in the option..

RANGES: R_MATNR FOR MARA-MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = <b>'EQ'</b>.

R_MATNR-LOW = 'ABCD'.

APPEND R_MATNR.

R_MATNR-SIGN = 'I'.

R_MATNR-OPTION = <b>'EQ'</b>.

R_MATNR-LOW = 'ABCDADSF'.

APPEND R_MATNR

Thanks,

Naren

Read only

Former Member
0 Likes
1,110

Hi,

here is a suggestion for your statement. Instead of using IN Statement you can use this:

if COMM_STRUCTURE-COSTELMNT >= ''84300005' AND COMM_STRUCTURE-COSTELMNT <= '84300006'.

RESULT = 'PM_LABOR'.

elseif COMM_STRUCTURE-COSTELMNT = 61100950.

RESULT = 'PM_NON_STOCK'.

endif.

Is it useful?

Ashven

Read only

Former Member
0 Likes
1,110

Hi,

Please reward points for helpful answers..

Thanks,

Naren