10.14.9 Print Statement (PRINT)

Syntax

PRINT printitem [, printitem]...;

where printitem can be:

BP continue output on next page

NL continue output on next line

TAB (n) continue output starting at column n

TAB (+n) continue output n columns from current position.

exp print expression exp

ex1 : ex2 [just] print expression ex1 in field length ex2

ex1 : ex2 [just] : ex3 print expression ex1 in field length ex2 with a precision of ex3

ex1 : : ex3 print expression ex1 with a precision of ex3

ex1 USING ex3 print expression ex1 using a format of ex3

just:

LEFT_JUST

RIGHT_JUST

CENTERED

Purpose

The PRINT statement is responsible for generating all of the report output. A report program must execute PRINT statements to generate output.

The BP print item is used to begin output on the next page. This print item generates enough line feeds to begin printing on the next page (see SET PAGELENGTH). If a break point has been set for the bottom of the page, the code is executed at the appropriate point (page bottom). The headings of the next page are not processed until the next print item is printed.

The NL print item is used to begin output at the start of the next report line. The Report Writer will automatically wrap lines that exceed the set page width (see SET PAGEWIDTH).

The TAB print items are used to begin output at a certain column. This is useful to align columns of a report. The form TAB ( n ) is used to begin output in column n. The form TAB (+n) is used to begin output n columns from the current position. If the new column position is less than the current position or is greater than the set page width, one blank is printed.

There are five basic methods to print values:

1) Showing just the significant characters,

2) Showing all significant characters with a minimum field width and optional justification,

3) Showing a maximum number of significant characters with a minimum field width and optional justification,

4) Showing a maximum number of significant characters (no minimum),

5) Using a custom formatting string.

The last five printitems statements correspond to the five methods given above. Each of these methods operates a little differently as described in the following paragraphs.

Method 1 shows all significant characters. (For example, a string that contains 13 characters would require 13 columns to print, a value of 100 would require 3 columns to print, etc.). All values printed are left justified.

Method 2 is like method 1 in that all significant characters are shown. It differs in two ways: one, a minimum field width can be specified; and two, justification can be specified. The minimum field width guarantees that at least ex2 columns will be printed. If there are fewer significant characters, blank fill is done to fill the field. If there are more significant characters, they are still printed. Justification is discussed later.

Method 3 builds on method 2 by limiting the number of characters to be printed. If the value is a STRING or CHAR type value, at most ex3 characters of the value will be printed. If the value is a REAL or MONEY type value, at most ex3 decimal places will be shown (value is rounded after ex3 decimal places). If the value contains fewer than ex3 significant characters, the value is blank/zero filled as appropriate (zero fill used for numbers).

Method 4 builds on method 1 by limiting the number of characters to be printed. It differs from method 3 in that no minimum width is specified. This method is most often used with STRING or CHAR type values when only the first n characters of a string are wanted.

Method 5 allows an arbitrary formatting string to be used to format the value. The "width" of the formatting string is the minimum width for the data value. No justification is allowed for this method. Care must be taken that the formatting string used is appropriate for the type of data being printed. Any formatting errors result in printing an empty string "" (i.e., nothing). This method is the same as method 1 if the value is of STRING or CHAR type.

Justification specifies the alignment of data being printed. Left justification, LEFT_JUST, causes the data to begin printing on the same starting column.

Right justification, RIGHT_JUST, causes the data to end printing on the same ending column. Right justification requires an ending column, or, as in the Report Writer, a starting point and a field width (which defines the ending column).

Center justification, CENTERED, causes the data to be centered on a given column. Like right justification, the Report Writer determines this column from the starting point and the field width.

Because justification requires field widths, it is available only with the methods that specify a minimum width.

Finally, different data types have different default justifications. All number types (REAL, INTEGER, MONEY) use right justification as the default. If justification is not specified for methods 2 and 3, numbers will be right justified for these methods. All other data types use left justification. As a short-cut, using a negative minimum width swaps the default justification for one print item (numbers become left justified, all others become right justified).

Example:

PRINT BP;

PRINT "heading lines", NL, NL;

PRINT TAB (20),

"Centered Headings":40 CENTERED,

NL, NL;

PRINT "evenly", TAB (+5), "spaced", TAB (+5),

"strings", NL;

PRINT "strings", numbers, expression;

PRINT "string":10,

"left justified string":30 LEFT_JUST;

PRINT "truncated string"::5;

PRINT count:5, tot_tr_counts/count:5;

PRINT balance:10, tot_tr_amt/count:10;

PRINT units:10:3, gross_margin:14:4, NL;