Document Templates : DGL Statements : Output Statements : WRITE Statement

WRITE Statement

Statement Syntax:

WRITE ( [fl,] write_expression , ... ) ;

The WRITE statement to write expression values to any of the following

You may write a numeric or string expression that is evaluated in the template, or a literal piece of text. The WRITE statement can also be used to write information retrieved from the database, such as element names.

Using the WRITE statement to write to a file or to the dialog area is particularly useful if you want to write messages (error messages, run-time messages, etc.). When writing to a file or to the dialog area, you must include the fl identifier. In such cases you must also precede the WRITE statement with an OPEN statement.

The WRITE statement is commonly used to write lines that include text (string literals) together with expression values.

For example: WRITE(’NAME:’, di_name);
results in the following being written in the output segment file NAME: KUKU , where KUKU is a value of di_name.

From the examples you can see that there can be more than one write expression. When there are multiple expressions they are separated by commas.

Lines of pure text are more suitably handled using the Verbatim statement.

Literal strings may include the formatting characters:

\n - new-line
\t - tab

For example, WRITE(’\n’,alpha);
would write the value of alpha at the beginning of the next line in the output segment file.

Optionally, you can specify the minimum number of characters to be written in the output file. You do this by using the following syntax for the write expression:

expression : num

where expression can be either a numeric or a string expression, and num is an integer constant or integer expression that represents the minimum number of characters that expression will occupy. expression and num may involve operands, operations, and function calls.

For Example:

WRITE(act_name: 10, ’,’ , act_synonym);

results in the string value for act_name being written in the output file to a length of at least 10 characters; if the name has less than this number, blanks are added to achieve the specified string length - as in:

COMP , SET

In this example, spaces have been added to “COMP” to give it a length of 10 characters.

The use of num determines the minimum number of characters to be written in the output file, as follows:

For a string, the length of the string is the minimum number of output characters. When specified, and where num is greater than the string length, blanks are padded to the right of the string to achieve a total string length of num.
For an integer, when num is specified, and where num is greater than the number of digits in the integer, blanks are padded to the left of the number to achieve a total output length of num.
For a real number, when num is not specified, the value is output to no more than 8 decimal places. Thereafter, the number is automatically rounded. When specified, and where num is greater than the digits output according to the default above, blanks are padded to the left of the number to achieve a total output length of num. Where num is less than the digits output according to the default above, the decimal portion of the number may be rounded to arrive at a specified output length of num. However, in no case will the integer portion of the real number be truncated.

For Example:

WRITE (’Name:’:8, name, ’\n’, ’Value:’:8, v) ;

Assume that name contains “Xfactor” and v is an integer that equals 5105. This writes the following lines to the output file:

Name: Xfactor
Value: 5105

Note: The WRITE command may not access a list variable directly; if you attempt to write a variable which refers to a list, an error message is displayed. To output a list, use a control flow construct such as a loop - writing one list item at a time.