Expressions are a way to express program logic using free-form syntax. They can be used to write program statements in a more readable or concise manner than fixed-form statements.
An expression is simply a group of operands and operations. For example, the following are valid expressions:
A+B*21
STRINGA + STRINGB
D = %ELEM(ARRAYNAME)
*IN01 OR (BALANCE > LIMIT)
SUM + TOTAL(ARRAY:%ELEM(ARRAY))
'The tax rate is ' + %editc(tax : 'A') + '%.'
Expressions may be coded in the following statements:
Figure 184 shows several examples of how expressions can be used:
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
* The operations within the DOU group will iterate until the
* logical expression is true. That is, either COUNTER is less
* than MAXITEMS or indicator 03 is on.
/FREE
dou counter < MAXITEMS or *in03;
enddo;
// The operations controlled by the IF operation will occur if
// DUEDATE (a date variable) is an earlier date than
// December 31, 1994.
if DueDate < D'12-31-94';
endif;
// In this numeric expression, COUNTER is assigned the value
// of COUNTER plus 1.
Counter = Counter + 1;
// This numeric expression uses a built-in function to assign the numb
// of elements in the array ARRAY to the variable ARRAYSIZE.
ArraySize = %elem (Array);
// This expression calculates interest and performs half adjusting on
// the result which is placed in the variable INTEREST.
eval(h) Interest = Balance * Rate;
// This character expression builds a sentence from a name and a
// number using concatentation. You can use built-in function
// %CHAR, %EDITC, %EDITW or %EDITFLT to convert the numeric value
// to character data.
// This statement produces 'Id number for John Smith is 231 364'
String = 'Id number for '
+ %trimr (First) + ' ' + %trimr (Last)
+ ' is ' + %editw (IdNum: ' & ');
// This expression adds a duration of 10 days to a date.
DueDate = OriginalDate + %days(10);
// This expression determines the difference in seconds between
// two time values.
Seconds = %diff (CompleteTime: t'09:00:00': *seconds);
// This expression combines a date value and a time value into a
// timestamp value.
TimeStamp = TransactionDate + TransactionTime;
/END-FREE