In this section: |
Dialogue Manager reads information from an external file and writes information to it. This section describes the command -WRITE. For information on -READ, see Supplying Values for Variables.
An expression consists of variables and literals (numeric or alphanumeric constants) that are combined arithmetically, logically, or in some other way to create a new value.
This section describes how to create:
Dialogue Manager has few restrictions on creating expressions. However, keep in mind that an expression cannot exceed 40 lines or 16 -IF...THEN...ELSE commands.
Reference: |
An arithmetic expression is:
Operator |
Meaning |
---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
** |
Exponentiation |
An example is:
&DELIVER_AMT / &OPENING_AMT
(&RATIO - 1) ** 2
Following are three arithmetic expressions used in the command -SET:
-SET &COUNT = 1; -SET &NEWVAL = (&RATIO - 1) ** 2; -SET &RATIO = (&DELIVER_AMT * 100) / (&OPENING_AMT);
Keep the following in mind as you create arithmetic expressions:
Arithmetic operations are performed before logical operations, in the following order:
Operator |
Meaning |
---|---|
** |
Exponentiation |
/ * |
Division and multiplication |
+ - |
Addition and subtraction |
How to: |
An alphanumeric expression is:
variablename = {alphaexp1|'literal'} concatenation {alphaexp2|'literal'} [...]
where:
Is the name of the variable assigned to the result of the concatenation.
Are local or global variable that forms part of the concatenation.
Is a literal that forms part of the concatenation. It must be enclosed in single quotation marks.
Is one of the following symbols:
|| |
Indicates strong concatenation, which suppresses trailing blanks. |
| |
Indicates weak concatenation, which preserves individual field lengths, including trailing blanks. |
-SET &NAME = &LASTNAME || ',' || &FIRST_INIT;
If &LASTNAME is equal to Doe and &FIRST_INIT is equal to J, &NAME is set to:
Doe,J
System-supplied date functions enable you to calculate the number of days between start and end dates, including leap years. The date format must be either alphanumeric or integer.
datefield (begin, end) -SET &LOSRV = YMD(&HIRE_DATE,040101);
where:
Is one of the following:
YMD is the number of days between two dates stored as year-month-day (for example, 850522).
MDY is the number of days between two dates stored as month-day-year (for example, 052285).
DMY is the number of days between two dates stored as day-month-year (for example, 220585).
Is the start date.
Is the end date.
In the following example, &LOSRV is set to the number of days between &HIRE_DATE and the literal 040101:
-SET &LOSRV = YMD(&HIRE_DATE,040101);
Reference: |
A logical expression contains logical and relational operators and is evaluated to a value that is true or false.
This example shows various elements that are used to form a logical expression. The abbreviation exp stands for expression.
{arithmetic exp|alphanumeric exp} operator1 {numeric lit|alphanumeric lit} OR... expressionoperator2expression logical exp {AND|OR} logical exp NOT logical exp
where:
Is one of the following: EQ, NE, OMITS, or CONTAINS.
Is either an arithmetic, alphanumeric, or logical expression.
Is one of the following: EQ, NE, LE, LT, GE, or GT.
The following table defines valid operators (EQ, NE, and so on) used in this example.
Operator | Description |
---|---|
EQ | Tests for a value equal to another value. |
NE | Tests for a value not equal to another value. |
OMITS | Tests for a value that does not contain a matching character string. |
CONTAINS | Tests for a value that does contain a matching character string. |
LE | Tests for a value less than or equal to another value. |
LT | Tests for a value less than another value. |
GE | Tests for a value greater than or equal to another value. |
GT | Tests for a value greater than another value. |
AND | Returns a value of true if both of its operands are true. |
OR | Returns a value of true if either of its operands is true. |
NOT | Returns a value of true if the operand is false. |
Keep the following in mind:
-IF &NAME EQ 'JOHN DOE' GOTO QUIT;
To produce a single quotation mark within a literal, place two single quotation marks where you want one to appear:
-IF &NAME EQ 'JOHN O''HARA' GOTO QUIT;
EQ NE LE LT GE GT NOT CONTAINS OMITS
AND
OR
-IF &STATE EQ 'NY' OR 'NJ' OR 'WA' GOTO QUIT;
In this case, OR and EQ are evaluated at the same level.
-IF &STATE EQ 'NY' AND &COUNTRY EQ 'US' OR 'UK' THEN...
is evaluated as:
IF &STATE EQ 'NY' IF &COUNTRY EQ 'US'...
Dialogue Manager then evaluates the phrase OR UK and indicates that it is a syntax error.
To write the command correctly, add parentheses:
-IF ((&STATE EQ 'NY') AND (&COUNTRY EQ 'US' OR 'UK')) THEN...
A compound expression has the following form:
-IF expression THEN expression ELSE expression;
The following restrictions apply:
If the following example is executed without an input parameter list, the client application receives the message NONE. If it executes with the parameter BANK='FIRST NATIONAL', the client application receives the message FIRST NATIONAL.
-DEFAULTS &BANK = ' ' -SET &BANK = IF &BANK EQ ' ' THEN 'NONE' -ELSE &BANK; -TYPE &BANK
The next example uses a compound expression to define a truth condition (1 is true and 0 is false).
-DEFAULTS &CURR_SAL = 900,&DEPARTMENT=MIS -SET &MYTEST = (&CURR_SAL GE 1000) OR (&DEPARTMENT EQ MIS); -IF &MYTEST EQ 1 THEN GOTO YES ELSE GOTO NO; -YES -TYPE YES -EXIT -NO -TYPE NO
When this code is executed, the client application receives the message YES.
iWay Software |