Creating Expressions

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.


Top of page

x
Arithmetic Expressions

Reference:

An arithmetic expression is:



Example: Using Arithmetic Expressions

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);


x
Reference: Guidelines for Using Arithmetic Expressions

Keep the following in mind as you create arithmetic expressions:



x
Alphanumeric Expressions

How to:

An alphanumeric expression is:



x
Syntax: How to Concatenate Alphanumeric Variables and Literals
 
variablename = {alphaexp1|'literal'} concatenation 
{alphaexp2|'literal'} [...]

where:

variablename

Is the name of the variable assigned to the result of the concatenation.

alphaexp1, alphaexp2

Are local or global variable that forms part of the concatenation.

literal

Is a literal that forms part of the concatenation. It must be enclosed in single quotation marks.

concatenation

Is one of the following symbols:

||

Indicates strong concatenation, which suppresses trailing blanks.

|

Indicates weak concatenation, which preserves individual field lengths, including trailing blanks.



Example: Concatenating Alphanumeric Variables and Literals
-SET &NAME = &LASTNAME || ',' || &FIRST_INIT;

If &LASTNAME is equal to Doe and &FIRST_INIT is equal to J, &NAME is set to:

Doe,J


x
Syntax: How to Use Date Functions

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:

datefield

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).

begin

Is the start date.

end

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);

Top of page

x
Logical Expressions

Reference:

A logical expression contains logical and relational operators and is evaluated to a value that is true or false.



Example: Forming a Logical Expression

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:

operator1

Is one of the following: EQ, NE, OMITS, or CONTAINS.

expression

Is either an arithmetic, alphanumeric, or logical expression.

operator2

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.



x
Reference: Guidelines for Alphanumeric and Logical Expressions

Keep the following in mind:


Top of page

x
Compound Expressions

A compound expression has the following form:

-IF expression THEN expression ELSE expression;

The following restrictions apply:



Example: Using Compound Expressions

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