IF [ HP Transact Reference Manual ] MPE/iX 5.0 Documentation
HP Transact Reference Manual
IF
Performs a specified action based on a conditional test.
Syntax
IF condition-clause THEN statement [ELSE statement];
IF specifies tests to be performed on test-variables . IF introduces a
condition-clause, which contains one or more conditions, each made up of
a test-variable, a relational-operator, and one or more values. Multiple
conditions are joined by AND or OR. If the condition clause is true, then
the specified statement is performed. You can provide an alternate
statement to be performed if the condition is not true by including the
ELSE clause. If you do not include an ELSE clause and the condition is
not true, control passes to the statement following the IF statement.
NOTE Do not terminate the statement preceding the ELSE clause with a
semicolon (;).
Statement Parts
condition- One or more conditions, connected by AND or OR, where
clause
AND A logical conjunction. The condition clause is
true if all of the conditions are true; it is
false if one of the conditions is false.
OR A logical inclusive OR. The condition clause is
true if any of the conditions is true; it is
false if all of the conditions are false.
Each condition contains a test-variable, relational-operator,
and one or more values in the following format:
test-variable relational-operator value [,value]...
test- Can be one or more of the following:
variable
(item-name The value in the data register
[(sub- that corresponds to item-name.
script)]) The item-name can be subscripted
if an array item is being
referenced. (See "Array
Subscripting" in Chapter 3.)
[arithmetic An arithmetic expression
expression] containing item names and/or
constants. The expression is
evaluated before the comparison is
made.
_________________________________
NOTE An arithmetic-expression
must be enclosed in square
brackets ([ ]).
_________________________________
EXCLA- Current status of the automatic
MATION null response to a prompt set by a
user responding with an
exclamation point (!) to a
prompt. (See "Data Entry Control
Characters" in Chapter 5.) If the
null response is set, the
EXCLAMATION test variable is a
positive integer. If it is not
set, it is zero. The default is
0.
FIELD Current status of FIELD command
identifier. If a user qualifies a
command with FIELD, the FIELD test
variable is a positive integer.
Otherwise, it is a negative
integer. The default is <0.
INPUT The last value input in response
to the INPUT prompt.
PRINT Current status of PRINT or TPRINT
command qualifier. The PRINT test
variable is an integer greater
than zero and less than 10. If a
command is qualified with TPRINT,
PRINT is an integer greater than
10. If neither qualifier is used,
PRINT is a negative integer. The
default is <0.
REPEAT Current status of REPEAT command
qualifier. If a user qualifies a
command with REPEAT, the REPEAT
test variable is a positive
integer. Otherwise, REPEAT is a
negative integer. The default is
<0.
SORT Current status of SORT command
qualifier. If a user qualifies a
command with SORT, the value of
the SORT test variable is a
positive integer. Otherwise SORT
is a negative integer. The
default is <0.
STATUS The 32-bit integer value of the
status register set by the last
data set or file operation, data
entry prompt, or external
procedure call.
relational Specifies the relation between the test-variable
operator and the value. It can be one of the following:
= equal to
<> not equal to
< less than
<= less than or equal
to
> greater than
>= greater than or
equal to
value The value against which the test-variable is
compared. The value can be an arithmetic
expression that will be evaluated before the
comparison is made.
The allowed value depends on the test variable,
as shown in the comparison below. Alphanumeric
strings must be enclosed in quotation marks.
If the test- The value must be:
variable
is:
item name Then value must be an alphanumeric
string, a numeric value, an
arithmetic expression, a reference
to a variable as in (item-name),
or a class condition as described
below.
[arithmetic A numeric value, an arithmetic
expression] expression, or an expression, or a
reference to a variable as in
(item-name).
INPUT An alphanumeric string.
EXCLA- A positive or negative integer or
MATION expression.
FIELD
PRINT
REPEAT
SORT
STATUS A 32-bit integer number or
expression.
If more than one value is given, then:
* The relational-operator can be only "="
or "<>".
* When the relational operator is "=", the
action is taken if the test-variable is
equal to value1 OR value2 OR...valuen.
In other words, a comma in a series of
values is interpreted as an OR.
* When the relational operator is "<>", the
action is taken if the test-variable is
not equal to value1 AND value2 AND...
valuen. In other words, a comma in a
series of values is interpreted as an AND
when the operator is "<>".
When the test variable is an item-name, the
value can be one of the following class
conditionals, which are used to determine
whether a string is all numeric or alphabetic.
The operator can only be "=" or "<>".
NUMERIC This class condition includes
the ASCII characters 0 through 9
and a single operational leading
sign. Leading and trailing
blanks around both the number
and sign are ignored. Decimal
points are not allowed in
NUMERIC data. This class test
is only valid when the item has
the type X, U, 9, or Z, or when
the item is in the input
register.
ALPHABETIC This class condition includes
all ASCII native language
alphabetic characters (upper and
lowercase) and space. This
class test is only valid for
items of type X or U or when the
item is in the input register.
ALPHABETIC- This class condition includes
LOWER all ASCII lowercase native
language alphabetic characters
and space. This class test is
only valid for items of type X
or U or when the item is in the
input register.
ALPHABETIC- This class condition includes
UPPER all ASCII uppercase native
language alphabetic characters
and space. This class test is
only valid for items of type X
or U or when the item is in the
input register.
statement Any simple or compound Transact statement; a
compound statement is one or more statements
bracketed by a DO/DOEND pair.
Order of Evaluation
When complex conditions are included, the operator precedence is:
* Arithmetic expressions are evaluated.
* Truth values are established for simple relational conditions.
* Truth values are established for simple class conditions.
* Multiple value conditions are evaluated.
* Truth values are established for complex AND conditions.
* Truth values are established for complex OR conditions.
Parentheses can be used to control the order of precedence when
conditional clauses are being evaluated. In multiple value conditions,
evaluation terminates as soon as a truth value is determined.
Examples
This statement causes a program branch to the "PROCEED" label if "YES" or
"Y" was input in response to the INPUT prompt. If INPUT contains any
other value, control passes to the next statement.
IF INPUT = "YES", "Y" THEN
GO TO PROCEED;
This statement causes a program branch to the "TOO-HIGH" label if the
data register value for the item-name COUNT is greater than 3.
IF (COUNT) > 3 THEN
GO TO TOO-HIGH;
This statement causes an exit from the current command sequence if the
status register value does not equal 0.
IF STATUS <> 0 THEN END;
The statements within the first DO/DOEND pair execute if the value in the
input register is "Y". Otherwise, if the value for A equals the value
for B, the statements at the label SAME-PART are executed. The value for
D is moved to the space reserved for A if:
* INPUT does not equal "Y", and
* A equals B, and
* A equals C, and
* D is less than 50.
The statements at label MORE-INFO are executed if:
* INPUT does not equal "Y", and
* A does not equal B.
IF INPUT = "Y" THEN
DO
DISPLAY "PART NUMBER IS": PART-NO;
PERFORM ADD-INFO;
DOEND
ELSE IF (A) = (B) THEN
DO
DISPLAY "DUPLICATE ENTRY";
PERFORM SAME-PART;
IF (A) = (C) THEN
IF (D) < 50 THEN
MOVE (A) = (D);
DOEND
ELSE PERFORM MORE-INFO;
The next example gives the user a choice between two activities. The
second ELSE construct checks to see that the user did one of the two
specified activities. If he did not, a message is displayed, and control
returns to the label OPTION at the third line, so that the user is
prompted again.
SYSTEM IFS;
DEFINE(ITEM) FIELD I(2);
OPTION:
PROMPT FIELD;
IF (FIELD) = 1 THEN
DO
DISPLAY "FIELD = 1";
DOEND
ELSE
DO
IF (FIELD) = 2 THEN
DO
DISPLAY "FIELD = 2";
DOEND
ELSE
DO
DISPLAY "YOU MUST ENTER 1 OR 2";
GO TO OPTION;
DOEND;
DOEND;
END;
The next examples demonstrate how to use complex conditionals.
IF (LAST-NAME) = "SMITH" AND (FIRST-NAME) = "JACK" THEN ...
IF (ACCT-BALANCE) < 0 OR (LOAN-AMOUNT) >= (LOAN-MAX) THEN ...
IF (RENTAL-OFFICE) = "098","978","656" AND
(CUST-NO-PREFIX) = (PREFERRED-PREFIX) OR
(CUST-NAME) = "ABCINC" THEN ...
WHILE (BALANCE) < 0 AND STATUS = 0
DO
GET(CHAIN) CUST-DETAIL,STATUS;
LET (BALANCE) = (BALANCE) + (AMOUNT);
DOEND;
REPEAT
DO
LET (TOTAL-OVERDUE) = (TOTAL-OVERDUE) + (AMT-OVERDUE);
FIND(SERIAL) CUST-INVOICE,STATUS;
DOEND
UNTIL (TOTAL-OVERDUE) > 999999.99 OR
(TOTAL-OVERDUE) > (MIN-OVERDUE) AND
(CUST-CODE) = "NEW";
The next examples demonstrate the use of the relational operator "<>"
with multiple values.
IF (STATE) <> "OR","CA","CO","VA" THEN ...
WHILE (PART-NO-PREFIX) <> (PROTOTYPE),(DEVELOPMENT)
GET(CHAIN) PART-DETAIL,STATUS;
The next examples demonstrate the use of class conditionals.
IF INPUT = ALPHABETIC THEN ... ELSE ...;
DATA (PART-NUMBER);
IF (PART-NUMBER) <> NUMERIC THEN ...;
The next example demonstrates the use of multiple expressions in
test-variables or in values.
IF (AREA) = [(LENGTH)*(WIDTH)],[(BASE)*(HEIGHT)*.5],
[(3.1416)*(RADIUS)**2] THEN ...;
REPEAT
FIND(SERIAL) STK-ON-HAND,STATUS
UNTIL ((WEIGHT) > [(KILO-PER-METER) * (METERS)] AND
(METERS) > (MIN-LENGTH) OR
(PRICE) > [(UNIT-PRICE) * (KILO-PER-METER) * (METERS)]);
IF [(DELAY) * (DFACTOR)] = [(COUNT) * 3] THEN ...;
MPE/iX 5.0 Documentation