


Conditions can check the result of a statement or define a constant branching.
In the first case, the condition is introduced by IF $RC followed by one of the comparison operators =, <, > etc. and an integral number. The value inserted for $RC is the return code of an SQL statement or the number of rows rejected during a load run.
A variant of this request form prevents a load run from being interrupted, because an SQL statement produced a negative return code. The statement to be executed is specified after $RC enclosed in parentheses; then follow the comparison operator and operand. In this case, $RC is a function; the condition evaluates the return code of the SQL statement enclosed in parentheses. The statement and the error message, if any, are recorded. These errors, however, are not listed in the summary at the end of the command file.
In case of constant branching, the condition is simply IF TRUE or IF FALSE. Such conditions can be used to exclude statements which are usually executed from particular applications.
It is mandatory that a condition preceded by IF be followed by a THEN branch, which can be followed by an ELSE branch. Each of these branches can contain a single statement or a block of statements. A block of statements is a sequence of statements bracketed by BEGIN and END. Even a complete IF THEN ELSE structure will be accepted as a single statement.
Example:
SHOW TABLE customermaster
*
IF $RC = 0
THEN BEGIN
*
DATAUPDATE TABLE customermaster
KEY cust_no 1-4 INTEGER
SET STATUS 55
INFILE customer.updates
*
DATAEXTRACT * FROM customermaster;
OUTFILE customer.list
END
*
ELSE
BEGIN
*
CREATE TABLE customermaster
( cust_no FIXED (10),
...
STATUS CHAR (1) BYTE)
*
DATALOAD TABLE customermaster
cust_no 1-4 INTEGER
...
INFILE customer.list
*
END
Command files containing control statements can be executed like any other command file. They are usually started with BATCH, but they can also be executed interactively.
The commands NEXT and SKIP take the control flow into account; i.e., only those statements are displayed or skipped which would have been executed with the option NOPROMPT.
If an error is detected in any nesting level during the execution of a statement, LOAD branches to the INPUT mode. The error can then be corrected, but it is also possible to execute any arbitrary command or statement. Commands that continue processing a command file, restart at the corresponding line in the control flow.
The command SCAN (abbreviated sc), on the other hand, fetches the next block of statements to the screen without distinguishing between control and other LOAD statements. None of these statements is automatically executed. The command SCAN can be used to manually skip statements that will not or cannot be executed.
In contrast to SKIP and NEXT, all statements can be reached using SCAN both the THEN part and the ELSE part will be displayed), and there are no side effects (IF $RC (DELETE FROM ..) = 0). NEXT NOPROMPT can be used to execute the rest of the file automatically at any time. When doing so, a restart point appropriate for the control statements should be chosen.
As with SKIP, it is possible to use SCAN to pass the beginning of a word as parameter. In this case, the command file is scanned until the specified (sub) string is recognized in a part of the statement.


