cancel
Showing results for 
Search instead for 
Did you mean: 

IF condition in SAP Script

Former Member
0 Kudos

Hello All,

Could you please let me know below IF statement is valid or not in SAP Script.

/:IF val1 = 'X' OR val2='X' OR val3='X' OR

/= val4 = 'X' or val5 = 'X'

/: do this....

/:ELSEIF temp1 = 'Y' AND temp2='Y' AND temp3='Y' AND

/= temp4=Y

/: do this...

/:ENDIF

I appreciate your help. Please let me know.

Thanks,

Sarada

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member

Hello,

Check this:


Conditional Text: IF 

You can use the IF control command to specify that text lines should be printed only when certain conditions are met. If the logical expression contained within the IF command is true, then the text lines enclosed by the IF... ENDIF command pair are printed. Otherwise they are ignored.

Syntax: 

/: IF condition 
: 
: 
/: ENDIF

The logical expression can use the following comparison operators:

= EQ equal to

< LT less than

> GT greater than

<= LE less than or equal to

>= GE greater than or equal to

<> NE not equal to

The following logical operators can be used to combine conditions: 

NOT 
AND 
OR
Evaluation of both the individual logical expressions and of the combinations of expressions is performed strictly from left to right. There are no precedence rules. Bracketed expressions are not supported.

The comparison is always performed on literal values, that is, the symbols are formatted as character strings before they are compared. This is particularly significant in the case of program symbols, because the formatting of these may depend on various parameters. For example, the formatted form of a currency field employs a variable number of decimal places and a variable ‘decimal point’ symbol (a period or a comma) depending on the applicable currency key.

You can extend the IF command with the ELSE command to allow text lines to be specified that you want to print in case the condition is false. If the condition is true, the text lines enclosed by the IF and ELSE commands are formatted; otherwise the text lines enclosed by the ELSE and ENDIF commands are formatted.

Syntax:

/: IF condition 
: 
/: ELSE 
: 
/: ENDIF

The ELSEIF command allows you to specify multiple cases.

Syntax:

/: IF condition
: 
/: ELSEIF condition
: 
/: ELSE 
: 
/: ENDIF

You can use any number of ELSEIF commands within one compound IF.. ENDIF control command. The use of an ELSE command is then optional.



You must not extend a condition over more than one line. Both the IF or ELSEIF command and the attached condition must be completely contained within a single line.
You can nest IF commands. 
You must terminate an IF command with an ENDIF command. If you forget this, there will be no more output following the IF command if the condition is false.
If a syntax error occurs in the interpretation of this command, then the command is not executed. This may have an unexpected effect on the subsequent text output. For example, if the IF statement is incorrect, then all following ELSEIF and ELSE commands will be ignored, since the opening IF command is ‘missing’. This will cause all the text lines attached to the ELSEIF and ELSE commands to be printed.

Regards,

Vasanth

Former Member
0 Kudos

Hi,

/:IF ( val1 = 'X' OR val2='X' OR val3='X' OR

/= val4 = 'X' or val5 = 'X' )

/: do this....

/:ELSEIF ( temp1 = 'Y' AND temp2='Y' AND temp3='Y' AND

/= temp4=Y )

/: do this...

/:ENDIF

Try like this.

Regards,

Sujith

Former Member
0 Kudos

Hi Sarada,

Its not a valid statement because you need to place the condition in one line rather in two lines as /= is not recongnized as control command continuation in SAP SCRIPTS. To extend to line use Shift+F8.

Change to as follows

/:IF val1 = 'X' OR val2='X' OR val3='X' OR val4 = 'X' or val5 = 'X'

/: do this....

/:ELSEIF temp1 = 'Y' AND temp2='Y' AND temp3='Y' AND temp4=Y

/: do this...

/:ENDIF

Thanks,

Vinay

varma_narayana
Active Contributor
0 Kudos

Hi..

You cannot write Commands in Multiple lines.

Instead use CASE COMMAND.

/: CASE 'X'

/: WHEN VAL1 OR VAL2 OR VAL3

/: WHEN OTHERS

/: ENDCASE

<b>Reward if Helpful</b>