Application Development 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: 

If condtion

Former Member
0 Kudos

Hi ,

Can i use if like this.

IF X = 0 0R X = 1 OR X = 2.

WRITE :----


.

ENDIF.

if iam using like this it is using only the first condition , is there any way to compare x with all the 3 values

1 ACCEPTED SOLUTION

Former Member
0 Kudos

IF X IN (0,1,2)

endif.

10 REPLIES 10

Former Member
0 Kudos

IF X IN (0,1,2)

endif.

hymavathi_oruganti
Active Contributor
0 Kudos

THE STATEMENT SHOULD be like below:

DATA: X TYPE I.

<b>IF X = 3 OR X = 1 OR X = 2.</b>

WRITE ....

ENDIF.

Note: spaces are important in X = VALUE

Former Member
0 Kudos

Hi your condition will be true of x contains any of 0 or 1 or 2. then the write will execute. It will check all 3 values..

data:

w_i type i.

w_i = 0.

if w_i = 0 or w_i = 1 or w_i = 2.

write: w_i.

endif.

w_i = 1.

if w_i = 0 or w_i = 1 or w_i = 2.

write: w_i.

endif.

w_i = 2.

if w_i = 0 or w_i = 1 or w_i = 2.

write: w_i.

endif.

What is your requirement.

former_member387317
Active Contributor
0 Kudos

as i said in earlier thread... u can use it..

IF X = 0 0R X = 1 OR X = 2. <b>ITS NOT CORRECT... U TYPED 0 INSTEAD OF O </b>

IF X = 0 OR X = 1 OR X = 2. <b>CORRECT ONE...</b>

YOU CAN USE OR OPERATOR FOR THIS PURPOSE...

Reward points for all useful answers...

THANKS & REGARDS

ilesh 24x7

Former Member
0 Kudos

Hi Karthick,

You can use the following:

1. IF X IN ( 0 , 1 , 2 ).

write :

endif.

2. if ( x = 0 or x = 1 or x = 2 )

write :

endif.

Careful in the spaces.

Reward if useful.

Regards,

Chitra

0 Kudos

HI thanks for the reply,

if my condition satisfies i need come out of the if loop hw

Former Member
0 Kudos

THIS IS YOURS STATEMENT

<b>IF X = 0 0R X = 1 OR X = 2.</b>

THIS IS MINE

<b>IF X = 0 OR X = 1 OR X = 2.</b>

YOU HAVE A DIFFERENCE IN THESE, CORRECT THE LINE YOUR CODE RUN PERFECTLY.

REWARD IF USEFUL.

AMIT SINGLA

former_member386202
Active Contributor
0 Kudos

Hi,

Try this.

IF ( X = 0 ) 0R

( X = 1 ) OR

( X = 2 ).

WRITE :----


.

ENDIF.

Regards,

Prashant

former_member223537
Active Contributor
0 Kudos

Hi,

Write the IF ELSE statment in such a way that once the condition is satisfied it comes out..


IF time < '120000'. 
  WRITE: / time, 'AM' .  " Here once this step is executed, control comes out of if condition
ELSEIF time > '120000' AND 
       time < '240000'. 
  time = time - 12 * 3600. 
  WRITE: / time, 'PM' .  " Here also .. it will come out of IF condition
ELSE. 
  WRITE / 'High Noon'. 
ENDIF. 


LOOP AT ITAB.

if itab-qty = 0.
EXIT. " Use EXIT statement to come out of loop
endif.

if itab-qty = 1.
CONTINUE. " Use CONTINUE statement to skip this record & goto next record
endif.


ENDLOOP.


former_member387317
Active Contributor
0 Kudos

Use EXIT to come out of IF loop..

if val1 = '100' OR val1= '200' OR val1 = '300'.

<b>EXIT.</b>

else.

CONTINUE.

endif.

Cheers

ilesh 24x7