Free-Form Calculation Statement

See Free-Form Statements for information on the columns available for free-form statements.

In a free-form statement, the operation code does not need to begin in any specific position within the available columns. Any extenders must appear immediately after the operation code on the same line, within parentheses. There must be no embedded blanks between the operation code and extenders. Following the operation code and extenders, you specify the Factor 1, Factor 2, and the Result Field operands separated by blanks. If any of these items are not required by the operation, you can leave them out. You can freely use blanks and continuation lines in the remainder of the statement. Each statement must end with a semicolon. The remainder of the record after the semicolon must be blank or contain an end-of-line comment.

For the EVAL or CALLP operation code, you can omit the operation code, if no extenders are needed, and if the variable or prototype does not have the same name as an operation code. For example, the following two statements are equivalent:
 eval pos = %scan (',': name);
 pos = %scan (',': name);

For each record within a free-form calculation block, positions 6 and 7 must be blank.

You can specify compiler directives within a free-format calculation block, with the following restrictions:
  • The compiler directive must be the first item on the line. It cannot continue to the next line.
  • In column-restricted code, the directive can start anywhere from column 7 onward.
  • Compiler directives are not allowed within a statement. The directive must appear on a new line after one statement ends and before the next statement begins.
Free-form operands can be longer than 14 characters. The following are not supported:
  • Continuation of numeric literals
  • Defining field names
  • Resulting indicators. (In most cases where you need to use operation codes with resulting indicators, you can use an equivalent built-in function instead.)

To indicate the start of total calculations, code a fixed-form calculation specification with a control-level specified in positions 7-8. In fully free-form mode, this fixed-form statement must be specified in a copy file. The total calculations can be specified by using free-form calculation syntax. Since the free-form calculation specification does not include a control-level entry, calculations to be performed on specific level breaks should be conditioned by using the statement "IF *INLx;".

  1. Detail calculations
  2. Total calculations start
  3. Conditioning calculations by a specific control-level indicator
    items += 1;                  1 
CL0   Total         TAG          2 
    IF *INL1;                    3 
       EXCEPT orderTotal;
       orders += 1;
       totalItems += items;
       items = 0;
    ENDIF;
Figure 1. Example of Free-Form Calculation Specification
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....

         read  file;              // Get next record
         dow not %eof(file);      // Keep looping while we have
                                  // a record
             if %error;
                 dsply 'The read failed';
                 leave;
             else;
                 chain(n) name database data;
                 time = hours * num_employees
                          + overtime_saved;
                 pos = %scan (',': name);
                 name = %xlate(upper:lower:name);
                 exsr handle_record;
                 read file;
             endif;
         enddo;

      begsr handle_record;
         eval(h) time = time + total_hours_array (empno);
         temp_hours = total_hours - excess_hours;
         record_transaction();
      endsr;

In column-limited source, you can combine free-form and traditional calculation specifications in the same program:

Figure 2. Example that Combines Traditional and Free-Form Calculation Specifications
C                   testb     OPEN_ALL      flags                    10
           if *in10;
            openAllFiles();
           endif;