Use IF...THEN to perform an action only under certain conditions.
An example of a conditional statement is
IF MEMBER OF "CLERKS"
In this statement, some action is performed if the user who logged in belongs to the Group object named CLERKS.
The following is a different type of conditional statement:
IF DAY_OF_WEEK="MONDAY"
In this statement, the equal sign (=) indicates the relationship between the variable (DAY_OF_WEEK) and its value (Monday). Note that the value (Monday) is inside quotation marks.
When using IF...THEN statements, be aware of the following syntax rules:
Use AND or OR to include two or more conditionals in an IF...THEN statement.
Values of conditional statements must be enclosed in quotation marks.
Values of conditional statements are compared with the assumption that the values are characters, not numeric values. The value of 21, therefore, would be considered greater than the value of 100 when comparing these two characters. To ensure the system properly calculates numeric values instead of character values, use the VALUE modifier in the IF...THEN statement.
The ELSE statement is optional.
IF, ELSE, and END must be on separate lines. THEN does not need to be on a separate line.
If you include a WRITE command as part of the IF...THEN command, the WRITE command must be on a separate line.
IF...THEN statements can be nested (up to 10 levels in Windows and 100 levels in Linux). However, GOTO should not be used in a nested IF...THEN statement to enter or exit from the body of an IF...THEN statement.
If your IF...THEN statement consists of only one line, you do not need to include END even if that line wraps. If your IF...THEN statement must be on more than one line (for example, if you used ELSE or WRITE, which must be on separate lines), you must include END.
Six relationships are possible between the elements of an IF...THEN statement. Represent these relationships with the following symbols:
IF conditional [AND|OR [conditional]] THEN
commands
[ELSE
command]
[END]
Replace conditional with identifier variables. For information about identifier variables, see Section 3.2, Using Identifier Variables.
Replace commands with any login script commands that you want to be executed if the specified condition is true.
If you place the following command in a login script, the message Status report is due today appears when the user logs in on Monday and Have a nice day! on other days:
IF DAY_OF_WEEK="MONDAY" THEN WRITE "Status report is due today." ELSE WRITE "Have a nice day!" END
The following lines mean “If the hour (on a 24-hour scale) is greater than or equal to 12, then write ‘afternoon'”:
IF VALUE HOUR24>="12" THEN WRITE "afternoon" END
The following command executes the CAPTURE utility on the fourth day of the week (Wednesday):
IF NDAY_OF_WEEK="4" THEN #CAPTURE Q=FAST_Q NB TI=10 NFF END
The following example shows nested IF...THEN statements. Notice that there are two IF statements, so each one must have its own END statement:
IF DAY_OF_WEEK="MONDAY" THEN MAP *6:=VOL1:APPL\WP IF MEMBER OF CLERKS THEN WRITE "Your report is due immediately!" END END
Conditionals can be joined with commas, the word AND, or the word OR to form compound conditionals.
The first line of the following IF...THEN statement is a compound conditional that means “If it is the evening of the first day of the month”:
IF GREETING_TIME="EVENING" AND DAY="01" THEN WRITE "The system will be backed up tonight." END
An IF...THEN statement can include several commands that must be executed if the conditional is true.
The following example shows two commands that are executed on Tuesdays: a WRITE command that displays a message about a staff meeting, and an INCLUDE command that tells the login script to process any commands or messages contained in the file sys:public\update.txt.
IF DAY_OF_WEEK="TUESDAY" THEN WRITE "Staff meeting today at 10 a.m." INCLUDE SYS:PUBLIC\UPDATE.TXT END