Format Expressions

A format expression formats variables for output. It specifies the size of the field in which data is displayed or printed, the justification (left, right, or text), the number of digits to the right of the decimal point to display, and so on. Format expressions work like the FMT function. The syntax is:

variable format

format is a valid string expression that evaluates to:

[ width ] [ background ] justification [ edit ] [ mask ]

Either width or mask can specify the size of the display field.

background specifies the character used to pad the field (Space is the default padding character).

You must specify justification as left, right, or text (text left-justifies output, but breaks lines on spaces when possible).

edit specifies how to format numeric data for output, including such things as the number of digits to display to the right of the decimal point, the descaling factor, whether to round or truncate data, and how to indicate positive and negative currency, handle leading zeros, and so on.

mask is a pattern that specifies how to output data.

If a format expression is applied to the null value, the result is the same as formatting an empty string. This is because the null value has no printable representation.

You can use the STATUS function to determine the result of the format operation. The STATUS function returns the following after a format operation:

0
The format operation is successful.
1
The variable is invalid.
2
The format expression is invalid.

In NLS mode, the FMT function formats an expression in characters; the FMTDP function formats it in display positions. The effect of the format mask can be different if the data contains double-width or multibyte characters.