式とは、自由形式の構文を使用してプログラム論理を表す方法です。式を使用すると、固定形式ステートメントより読みやすく、簡潔な方法 でプログラム・ステートメントを作成することができます。
式は、オペランドと演算子の単純なグループです。 たとえば、以下が有効な式です。
A+B*21 STRINGA + STRINGB D = %ELEM(ARRAYNAME) *IN01 OR (BALANCE > LIMIT) SUM + TOTAL(ARRAY:%ELEM(ARRAY)) 'The tax rate is ' + %editc(tax : 'A') + '%.'
式は、次のステートメントでコーディングされる場合があります。
図 164 では、式の使用例をいくつか示しています。
*..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
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.