3.15 IF...THEN

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:

Command Format

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.

Examples

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