Introduction

Language Structure

IB Statements

File System

Comet 32 Runtime

Index

Length override

Non-array Fields

The length-override parameter (optional) in a FORMAT statement is the desired formatted length of the format-item, regardless of the defined length of the field. This parameter may be a numeric constant or variable (expressions are not allowed), and may be used in conjunction with all input/output statements.

For example:

Suppose you are working with a 6-digit numeric value. The variable would be defined with a length and precision of 6.0 (i.e., 6 digits to the left of the decimal point, and zero digits to the right of the decimal point), as shown here:

   LENGTH 6.0               ! Define field length and precision
   LOCAL BALANCE.DUE        ! Define field type and variable name
The default format length is 8 bytes (i.e., 6 bytes for the digits, one byte for the decimal point, and one byte for the sign). Thus, if you wrote this field to a file (using the default length), Comet would write 8 bytes.
   1000 FORMAT BALANCE.DUE            ! Define format for I/O commands
   .
   .
   .
   OPEN (1) "DATAFILE"                ! Open data file
   WRITE (1,1000)                     ! Write a record to the file
The data would be written as follows:
   123456.-
where the first 6 bytes are the 6 digits, the 7th byte is a decimal point, and the 8th byte is reserved for the sign (blank if the value is positive, - if the number is negative).

However, you might want to override the default format length. In this example, you could write just the numeric portion of the field, while not writing the decimal point and sign. Thus, you would save 2 bytes of disk space. Here's the FORMAT statement for this example, showing a length override of 6:

   1000 FORMAT BALANCE.DUE,6          ! Define format for I/O commands
   .
   .
   .
   OPEN (1) "DATAFILE"                ! Open data file
   WRITE (1,1000)                     ! Write a record to the file

Array Fields

When an array is specified as the format-item, the length override parameter takes on a slightly different form. It consists of two values, the number of successive items in the array and the length of each array item

The syntax is:

   number-of-successive-array-items * length-of-each-array-item
For example:

Suppose you are working with a string array that contains 20 items, where each value is 30 bytes long. You could define this array as follows:

   LENGTH 30               ! Define field length
   LOCAL NAMES$(20)        ! Define field type, array name and size
The full array would contain 600 bytes (i.e., 20 values times 30 bytes). To include this array in a FORMAT statement, you would list the first element of the array followed by the length override parameter as shown in this example:
   1000 FORMAT NAMES$(1),20*30        ! 20 values * 30 bytes each
   .
   .
   .
   OPEN (1) "DATAFILE"                ! Open data file
   WRITE (1,1000)                     ! Write a record to the file
Also note that you can use this feature to write less than the full array. To continue with the above example, if you wanted to write just the first 5 values of the array, the code would look like this:
   1000 FORMAT NAMES$(1),5*30         ! 5 values * 30 bytes each
   .
   .
   .
   OPEN (1) "DATAFILE"                ! Open data file
   WRITE (1,1000)                     ! Write a record to the file
In this case, the program would write 150 bytes to the file (i.e., 5 values times 30 bytes each).