IF and THEN (do statement to test conditions)
Syntax
IF expression THEN statement | BEGIN
where
- IF-THEN statement is all on one line.
- expression consists of variables, whole numbers, or character strings connected by operators (see Expressions-and-operators).
- THEN is required and can be followed by a PRL statement or a BEGIN clause terminated by an END statement with a semicolon (;) suffix.
- statement can be any of the following PRL statements: BEGIN, GOTO, END, SET, or EXEC. An example follows:
IF V1 = V2 THEN SET V3 = V4
- BEGIN indicates that a series of PRL statements follow the IF-THEN condition. More than one statement can be nested within the IF condition when a true condition results from the test. The end of the statements is signaled by an END statement followed by a semicolon (END;):
IF V1 = V2 THEN BEGIN
statement
statement
END;
statement
statement
END;
The semicolon (;) suffix distinguishes this END statement from an END that terminates PRL execution.
END without a semicolon (;) suffix terminates PRL execution as follows:
IF V1 > V2 THEN END
The entire report generation sequence can be coded in an IF statement. For example, to produce a report that outlines, among other things, the 20 busiest CPU users in your system, keep a variable called COUNT and increment it just before REPORT. Follow this with a conditional statement that terminates the job when 20 are reported.
Example
SET TITLE = 'HIGHEST 20 USERS OF CPU TIME - &ZDATE'
SELECT TYPE 6E RECORDS FROM CMRDETL
WHERE &CMRDATE = &ZDATE
USING T6ETRID -
CMRDATE -
CMRTIME -
T6EUSER -
T6ETMID -
T6ERESP -
T6ECPUR
ORDER BY T6ECPUR IN DESCENDING SEQUENCE
SET &COUNT = &COUNT + 1
IF COUNT > 20 THEN END
REPORT
END
SELECT TYPE 6E RECORDS FROM CMRDETL
WHERE &CMRDATE = &ZDATE
USING T6ETRID -
CMRDATE -
CMRTIME -
T6EUSER -
T6ETMID -
T6ERESP -
T6ECPUR
ORDER BY T6ECPUR IN DESCENDING SEQUENCE
SET &COUNT = &COUNT + 1
IF COUNT > 20 THEN END
REPORT
END
Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*