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 .....ENDIF

Former Member
0 Likes
1,557

Hi,

I want 2 check da condition of some variable for 2 values....in If ...ENDIF.

eg.... how to write da code for

if ...a = 1 or a = 6.

.....

....

....

endif.

7 REPLIES 7
Read only

varma_narayana
Active Contributor
0 Likes
1,351

Hi I

In this case it is better to use CASE .. ENDCASE.

Eg.

CASE VAR.

WHEN 1.

<STATEMENTS>.

WHEN 2.

<STATEMENTS>.

ENDCASE.

Any how the syntax for IF .. ENDIF.

IF A = 1.

<STATEMENTS>.

ELSEIF A = 2.

<STATEMENTS>.

ENDIF.

Reward if it is useful..

Read only

Former Member
0 Likes
1,351

what you have written is the code.

if a = 1 or a = 2.

endif.

Same thing achieved by a case statament would be:

case a.

when 1 or 2.

processing...

when others.

endcase.

Read only

Former Member
0 Likes
1,351

Hi,

If A = 1 or A = 6. " This will work if the A value is 1 or 6.

Endif.

Regards

Sudheer

Read only

Former Member
0 Likes
1,351

Hi,

U can use 'or' and 'and' if u want to put the condition for both.

IF logexp.

Effect

Used for case distinction.

Depending on whether the logical expression logexp is true or not, this statement triggers the execution of various sections of code enclosed by IF and ENDIF.

There are three different types:

IF logexp.

processing1

ENDIF.

If the logical expression is true, processing1 is executed. Otherwise, the program resumes immediately after ENDIF.

IF logexp.

processing1

ELSE.

processing2

ENDIF.

If the logical expression is true, processing1 is executed. Otherwise, processing2 is executed (see ELSE).

IF logexp1.

processing1

ELSEIF logexp2.

processing2

ELSEIF ...

...

ELSE.

processingN

ENDIF.

If the logexp1 is false, logexp2 is evaluated and so on. You can use any number of ELSEIF statements. If an ELSE statement exists, it always appears after all the ELSEIF statements.

Notes

All IF statements must be concluded in the same processing block by ENDIF.

IF statements can be nested as many times as you like.

The IF statement does not directly affect the selection. For this purpose, you should use the CHECK statement.

regards,

pritha

Read only

alex_m
Active Contributor
0 Likes
1,351

IF a = 1 or a=6.

Write your logic.

endif.

If multiple if endif, prefer CASE -ENDCASE instead of IF.

Read only

Former Member
0 Likes
1,351

Hi Alexander

IF logexp.

processing1

ENDIF.

<b>If the logical expression is true, processing1 is executed. Otherwise, the program resumes immediately after ENDIF</b>

IF logexp.

processing1

ELSE.

processing2

ENDIF.

If the logical expression is true, processing1 is executed. Otherwise, processing2 is executed

IF logexp1.

processing1

ELSEIF logexp2.

processing2

ELSEIF ...

...

ELSE.

processingN

ENDIF.

If the logexp1 is false, logexp2 is evaluated and so on. You can use any number of ELSEIF statements. If an ELSE statement exists, it always appears after all the ELSEIF statements.

<b>Notes</b>

1)All IF statements must be concluded in the same processing block by ENDIF.

2)IF statements can be nested as many times as you like.

3)The IF statement does not directly affect the selection. For this purpose, you should use the CHECK statement.

<i><b>check this sample code</b></i>

IF ITAB5-KSCHL = 'NAVS' OR ITAB5-KSCHL = 'NAVM'.

            ITAB1-KBETR = ITAB5-KBETR.

             modify  ITAB1 transporting KBETR
             where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP .


           ELSEIF ITAB5-KSCHL = 'FRA1' OR ITAB5-KSCHL = 'FRC1' OR
                ITAB5-KSCHL = 'FRB1'.

                   ITAB1-KWERT = ITAB5-KWERT .

                   modify  ITAB1 transporting KWERT
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
endif.

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
1,351

Hi,

IF A = 1.

WRITE:/ 'A contains the value one'.

ELSEIF A = 6.

WRITE:/ 'A contains the value six'.

ENDIF.

Regards,

hari krishna