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

If condtion

Former Member
0 Likes
1,383

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
Read only

Former Member
0 Likes
1,354

IF X IN (0,1,2)

endif.

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

10 REPLIES 10
Read only

Former Member
0 Likes
1,355

IF X IN (0,1,2)

endif.

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,354

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

Read only

Former Member
0 Likes
1,354

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.

Read only

Former Member
0 Likes
1,354

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

Read only

Former Member
0 Likes
1,354

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

Read only

0 Likes
1,354

HI thanks for the reply,

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

Read only

Former Member
0 Likes
1,354

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

Read only

former_member386202
Active Contributor
0 Likes
1,354

Hi,

Try this.

IF ( X = 0 ) 0R

( X = 1 ) OR

( X = 2 ).

WRITE :----


.

ENDIF.

Regards,

Prashant

Read only

Former Member
0 Likes
1,354

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.


Read only

Former Member
0 Likes
1,354

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