PRINT

Formats and prints a row of data in a report routine.

Syntax

PRINT
 { 
    expression 
  | COLUMN left-offset
  | PAGENO
  | LINENO
  | num-spaces SPACES
  | [GROUP] COUNT(*) [ WHERE condition ]
  | [GROUP] PERCENT(*) [ WHERE condition]
  | [GROUP] AVG( variable ) [ WHERE condition]
  | [GROUP] SUM( variable ) [ WHERE condition]
  | [GROUP] MIN( variable ) [ WHERE condition]
  | [GROUP] MAX( variable ) [ WHERE condition]
  | char-expression WORDWRAP [ RIGHT MARGIN rm ]
  | FILE "file-name"
 } [,...]
  [ ; ]
  1. expression is any legal language expression.
  2. left-offset is described in COLUMN.
  3. num-spaces is described in SPACES.
  4. char-expression is a string expression or a TEXT variable.
  5. filename is a string expression , or a quoted string, that specifies the name of a text file to include in the output from the report.

Usage

This statement can include character data in the form of an ASCII file, a TEXT variable, or a comma-separated expression list of character expressions in the output of the report. (For TEXT variable or filename, you cannot specify additional output in the same PRINT statement.) You cannot display a BYTE value. Unless its scope of reference is global or the current module, any program variable in expression list must be declared in the DEFINE section.

The PRINT FILE statement reads the contents of the specified filename into the report, beginning at the current character position. This statement permits you to insert a multiple-line character string into the output of a report. If filename stores the value of a TEXT variable, the PRINT FILE file-name statement has the same effect as specifying PRINT text-variable. (But only PRINT variable can include the WORDWRAP operator)

You cannot use PRINT to display a BYTE value. The string "<byte value>" is the only output from PRINT of any object that is not of the TEXT data type.

PRINT statement output begins at the current character position, sometimes called simply the current position. On each page of a report, the initial default character position is the first character position in the first line. This position can be offset horizontally and vertically by margin and header specifications and by executing any of the following statements:

Unless you use the keyword CLIPPED or USING, values are displayed with widths (including any sign) that depend on their declared data types.

Table 1. Default print width for data types
Data type Default Print Width
BYTE N/A
CHAR Length of character data type declaration.
DATE DBDATE dependant, 10 if DBDATE = "MDY4/"
DATETIME From 2 to 25, as implied in the data type declaration.
DECIMAL (2 + p + s), where p is the precision and s is the scale from the data type declaration.
FLOAT 14
INTEGER 11
INTERVAL From 3 to 25, as implied in the data type declaration.
MONEY (2 + c + p + s), where c is the length of the currency defined by DBMONEY and p is the precision and s is the scale from the data type declaration.
NCHAR Length of character data type declaration.
NVARCHAR Length current value in the variable.
SMALLFLOAT 14
SMALLINT 6
STRING Length current value in the variable.
TEXT Length current value in the variable.
VARCHAR Length current value in the variable.
Unless you specify the FILE or WORDWRAP option, each PRINT statement displays output on a single line. For example, this fragment displays output on two lines:
PRINT fname, lname 
PRINT city, ", ", state, " ", zip-code
If you terminate a PRINT statement with a semicolon, however, you suppress the implicit LINEFEED character at the end of the line. The next example has the same effect as the PRINT statements in the previous example:
PRINT fname;
PRINT lname 
PRINT city, ", ", state, " ", zip-code

The expression list of a PRINT statement returns one or more values that can be displayed as printable characters. The expression list can contain report variables , built-in functions and operators. Some of these can appear only in a REPORT program block such as PAGENO, LINENO, PERCENT.

If the expression list applies the USING operator to format a DATE or MONEY value, the format string of the USING operator takes precedence over the DBDATE , DBMONEY , and DBFORMAT environment variables.

Aggregate report functions summarize data from several records in a report. The syntax and effects of aggregates in a report resemble those of SQL aggregate functions but are not identical.

The expression (in parentheses) that SUM(), AVG(), MIN(), or MAX() takes as an argument is typically of a number or INTERVAL data type; ARRAY, BYTE, RECORD, and TEXT are not valid. The SUM(), AVG(), MIN() , and MAX() aggregates ignore input records for which their arguments have null values, but each returns NULL if every record has a null value for the argument.

The GROUP keyword is an optional keyword that causes the aggregate function to include data only for a group of records that have the same value for a variable that you specify in an AFTER GROUP OF control block. An aggregate function can only include the GROUP keyword within an AFTER GROUP OF control block.

The optional WHERE clause allows you to select among records passed to the report, so that only records for which the boolean expression is TRUE are included.

Example

The following example is from the FORMAT section of a report definition that displays both quoted strings and values from rows of the customer table:
FIRST PAGE HEADER
  PRINT COLUMN 30, "CUSTOMER LIST"
  SKIP 2 LINES
  PRINT "Listings for the State of ", thisstate 
SKIP 2 LINES
  PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
        COLUMN 57, "ZIP", COLUMN 65, "PHONE"
  SKIP 1 LINE
PAGE HEADER
  PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
        COLUMN 57, "ZIP", COLUMN 65, "PHONE"
  SKIP 1 LINE
ON EVERY ROW
  PRINT customer_num USING "###&", COLUMN 12, fname CLIPPED,
       1 SPACE, lname CLIPPED, COLUMN 35, city CLIPPED, ", ",
       state, COLUMN 57, zip-code, COLUMN 65, phone