PRINT Statement (DQL)

Use the PRINT statement to show the information produced from your query in a report-like format.
datacom
Use the PRINT statement to show the information produced from your query in a report-like format. The values of the columns and keys you specify in the PRINT statement appear in columns. Each column has a standard heading which can be specified by you as the name of the column. Names used in a PRINT statement are first evaluated as columns, then as keys if no column is found with the specified name. The PRINT statement allows you to:
  • Present column and key names of a table in a columnar format.
  • Specify alternate heading names to use as column headings.
  • Designate a title to appear at the top of each page of the report.
  • Designate how numeric column values appear in the report.
  • Name a column or key more than once to assure that it appears on each page of a wide report that requires multiple pages to print all the columns.
Dataquery
also allows you to specify in the PRINT statement the accumulation of numeric columns. For those columns which you want to accumulate, enclose the column name in parentheses. The column to be accumulated can be a specific column within a table or a result from a SET statement in the query.
If you specify control breaks in a SORT statement within your query, the columns you want totals on are subtotaled according to the control breaks designated there. You can specify up to ten levels of control break totals in the report. A grand total of the columns to be totaled is provided automatically at PRINT time.
Before
Dataquery
sends the PRINT output to your terminal, it edits the data for errors relating to how it is presented.
  • If the data consists of any hexadecimal values which are not acceptable to the terminal, those values are translated to # characters. This can occur when you print a compound field composed of one or more packed or binary fields.
    The default literal masking character is the pound sign (#), but another symbol can be used at your site. Display Topic Help and choose System Profile to display the symbol used at your site.
  • To cause a compound field to be presented as individual columns, specify YES as the value for GROUP DISPLAY in your user profile.
If
Dataquery
encounters an error in a column being edited before it presents the output, a special error code surrounded by asterisks is reported in place of the column in the report. To access a list of PRINT and DISPLAY error codes, see Messages.
If you have specified control breaks in the SORT statement and accumulation columns in the PRINT statement, totals can be viewed several ways.
A PRINT statement can use the following data types: CHAR NUM, DEC, BIN, FLOAT-PT SHRT, FLOAT-PT LONG, EXT, 1/2 BIN, FUL BIN, DBL CHAR, DBL MIXED, KANJI.
Topics discussed on this page include:
Syntax Diagram
The following syntax shows the most complex version of the PRINT statement.
►►─ PRINT ─┬────────────────────────────────────┬─────────────────────────────►            └─┬─ TITLE1 ─┬─ ' 
report-heading1
 ' ─┘              └─ TITLE ──┘  ►─┬────────────────────────────┬─┬────────┬──────────────────────────────────►    └─ TITLE2 '
report-heading2
' ─┘ └─ FROM ─┘  ►─┬─────────────────────────────┬─┬─────┬─┬─ 
key-name
 ────┬─┬─────┬──────────►    └─ 
table-name
 ─┬────────────┬─┘ └─ ( ─┘ └─ 
column-name
 ─┘ └─ ) ─┘                   └─ (
status
) ─┘  ►─┬─────────────────────────────────┬─┬──────────────────────────┬───────────►◄    └─ '
heading1
 ─┬─────────────┬─ ' ─┘ └─ PICture '
edit-pattern
' ─┘                  └─ /
heading2
 ─┘
To simplify discussion, this document divides the PRINT statement into its important elements and discusses them in the following sections.
Basic Syntax Diagram
Purpose
You can create a PRINT statement without including a title for the report. The basic statement is simpler without it.
Syntax Diagram
The following is the syntax for the basic PRINT statement.
►►─ PRINT ─┬────────┬─┬─────────────────────────────┬─┬─────┬─────────────────►            └─ FROM ─┘ └─ 
table-name
 ─┬────────────┬─┘ └─ ( ─┘                                      └─ (
status
) ─┘  ►─┬─ 
key-name
 ────┬─┬─────┬─┬─────────────────────────────────┬──────────────►    └─ 
column-name
 ─┘ └─ ) ─┘ └─ '
heading1
 ─┬─────────────┬─ ' ─┘                                            └─ /
heading2
 ─┘  ►─┬──────────────────────────┬───────────────────────────────────────────────►◄    └─ PICture '
edit-pattern
' ─┘
Repeat parameters once for each key or column.
Explanation
This section explains each keyword in the basic PRINT format.
  • FROM
    Used for readability only.
  • table-name
    Specifies the
    Datacom Datadictionary
    name of the table where
    Dataquery
    obtains the values of the columns and keys indicated. You only need to include the table name if the column or key in the statement refers to a table which is different than the most recently named table in the query.
  • (status)
    (Optional)
    If authorized, use to specify a
    Datacom Datadictionary
    definition of a table that is being tested by programmers responsible for its maintenance. If the FIND or COUNT statement specifies a TEST status for a table, all subsequent statements in the same query reference the same status and version of the table, unless a different status is specified. The following chart describes each status you can specify.
    The status must be enclosed in parentheses, and there must be no spaces between the table name and the left parenthesis.
  • key-name
    Specifies a key that belongs to the table specified in the PRINT statement or the most recently named table in a previous statement.
  • column-name
    Specifies the name of a column that is either in the table named in the PRINT statement or in the previously named table. A column also can be a result from a previous SET statement in the query. And, a column can be one occurrence within a repeating field. If that is the case, use subscripts to identify which occurrence is to be used. A typical subscript looks like this:
                   SALES-RESULTS (5,2)
    The named column cannot exceed 1700 characters in length.
    If a specified column is numeric, you can designate the accumulation of the values of the column by enclosing the column name within parentheses.
  • PICTURE 'edit-pattern'
    See PICTURE Clause (DQL) for information about PICTURE clauses.
Example
The following sample query contains a basic PRINT statement.
FIND 10 CAI-SLSHST-REC ROWS     WITH SHIP-QTY > 100   RELATED BY SLMN-ID TO CAI-ORDERS-REC PRINT FROM CAI-ORDERS-REC ORD-ID       FROM CAI-SLSHST-REC ITM-ID                           SHIP-QTY                           UNIT-PRICE
When you execute the preceding query,
Dataquery
displays in a columnar format the order number identifying the customer and the corresponding items ordered (which are greater than 100) and the price per item.
Output
 =>   01/02/2010                  CA Dataquery                             PAGE 1 15:29:32                                                                  DETAIL     ORD-ID  ITM-ID      SHIP-QTY  UNIT-PRICE   ------  ----------  --------  ----------    08811  O50006      0000203    00014.75    09811  G10013      0000164    00110.25    04222  O50006      0000934    00014.75                      -------------------------------- LAST PAGE ------------------------------------  <PF1>  HELP         <PF2>  RETURN       <PF3>  TOTALS ONLY     <PF4>  DETAIL  <PF5>  NO TOTALS    <PF6>  STATS        <PF7>  BACKWARD        <PF8>  FORWARD  <PF9> NOT USED      <PF10> NOT USED     <PF11> LEFT            <PF12> RIGHT
Headings Syntax Diagram
You can use the PRINT statement to override standard column headings and to specify a one- or two-line report heading to appear at the top of the report.
Syntax Diagram
The following syntax shows the PRINT statement with keywords that add a report title and column headings.
►►─ PRINT ─┬────────────────────────────────────┬─────────────────────────────►            └─┬─ TITLE1 ─┬─ ' 
report-heading1
 ' ─┘              └─ TITLE ──┘  ►─┬────────────────────────────┬─┬────────┬──────────────────────────────────►    └─ TITLE2 '
report-heading2
' ─┘ └─ FROM ─┘  ►─┬─────────────────────────────┬─┬─────┬─┬─ 
key-name
 ────┬─┬─────┬──────────►    └─ 
table-name
 ─┬────────────┬─┘ └─ ( ─┘ └─ 
column-name
 ─┘ └─ ) ─┘                   └─ (
status
) ─┘  ►─┬─────────────────────────────────┬─┬──────────────────────────┬───────────►◄    └─ '
heading1
 ─┬─────────────┬─ ' ─┘ └─ PICture '
edit-pattern
' ─┘                  └─ /
heading2
 ─┘
The following explains the keywords for headings in the preceding PRINT format.
  • TITLE 'report-heading'
    Specifies the only line of the report heading. The maximum length of the report heading is 55 characters. When using this option, enclose the specified heading in apostrophes (').
  • TITLE1 'report-heading1'
    Specifies the first line of the report heading. The maximum length of the report heading is 55 characters. When using this option, enclose the specified heading in apostrophes (').
  • TITLE2 'report heading2'
    Specifies the second line of the report heading. The maximum length of the report heading is 55 characters. When using this option, enclose the specified heading within apostrophes (').
  • 'heading1/ heading2'
    Assigns an alternate one- or two-line column heading name for the preceding column or key. A heading name can be up to 32 characters, including blanks, and must appear within apostrophes ('). If you do not specify a heading name,
    Dataquery
    prints an alternate heading which it finds in
    Datacom Datadictionary
    , if your site management selected that choice as a system option; otherwise,
    Dataquery
    prints the
    Datacom Datadictionary
    name of the column or key. A column heading can be two lines long, with each line separated by a heading separator character. See the System Profile Topic Help to determine which character is used at your site as a heading separator.
  • PICTURE 'edit-pattern'
    See PICTURE Clause (DQL) for information about PICTURE clauses.
Example
An example illustrating these options follows:
FIND 10 CAI-SLSHST-REC ROWS     WITH SHIP-QTY > 100   RELATED BY SLMN-ID TO CAI-ORDERS-REC PRINT FROM CAI-ORDERS-REC ORD-ID 'ORDER\NUMBER'       FROM CAI-SLSHST-REC ITM-ID 'ITEM\NUMBER'                           SHIP-QTY 'QUANTITY\ORDERED'                           UNIT-PRICE 'PRICE PER ITEM'            TITLE1 'LARGE ORDERS'
The title for your report is LARGE ORDERS. The report contains the order number identifying the customer, and the items ordered, how many were ordered and the cost per item.
Output
The output for the preceding query appears below.
 =>   01/01/2010                  CA Dataquery                             PAGE 1 15:30:19                        LARGE ORDERS                              DETAIL       ORDER NUMBER  ITEM NUMBER  QUANTITY ORDERED  PRICE PER ITEM   ------------  -----------  ----------------  --------------          08811  O50006               0000203        00014.75                        -------------------------------- LAST PAGE ------------------------------------  <PF1>  HELP         <PF2>  RETURN       <PF3>  TOTALS ONLY     <PF4>  DETAIL  <PF5>  NO TOTALS    <PF6>  STATS        <PF7>  BACKWARD        <PF8>  FORWARD  <PF9> NOT USED      <PF10> NOT USED     <PF11> LEFT            <PF12> RIGHT
Totals Syntax Diagram
The PRINT statement can be used to accumulate subtotals and totals for specified numeric columns, including floating-point columns.
You can use the basic PRINT syntax to accumulate totals. The column or columns to be accumulated must be enclosed in parentheses.
Syntax Diagram
The following syntax diagram shows how to add parentheses to key or column names in the PRINT statement to cause totaling at control breaks (if any) and at the end of the report.
►►─ PRINT ─┬────────┬─┬─────────────────────────────┬─┬─────┬─────────────────►            └─ FROM ─┘ └─ 
table-name
 ─┬────────────┬─┘ └─ ( ─┘                                      └─ (
status
) ─┘  ►─┬─ 
key-name
 ────┬─┬─────┬─┬─────────────────────────────────┬──────────────►    └─ 
column-name
 ─┘ └─ ) ─┘ └─ '
heading1
 ─┬─────────────┬─ ' ─┘                                            └─ /
heading2
 ─┘  ►─┬──────────────────────────┬───────────────────────────────────────────────►◄    └─ PICture '
edit-pattern
' ─┘
Accumulating Subtotals
You can accumulate subtotals of a temporary result in the same way you accumulate subtotals of a database column.
Select one or more control break columns by enclosing their names in parentheses in a SORT statement and then enclose column names in the PRINT statement in parentheses where you want to show totals of those columns at control breaks or at the end of the report.
Sample
The following sample query illustrates the use of the PRINT statement to accumulate subtotals for results from a SET statement in the query.
FIND 10 CAI-SLSHST-REC ROWS     WITH SHIP-QTY > 100   RELATED BY SLMN-ID TO CAI-ORDERS-REC SET NET-COST (8.2) = CAI-SLSHST-REC SHIP-QTY * UNIT-PRICE SET DISCOUNT (5.2) = NET-COST * DISC-PCT SORT CAI-ORDERS-REC BY (ORD-ID) AND      CAI-SLSHST-REC BY ITM-ID PRINT FROM CAI-ORDERS-REC ORD-ID       FROM CAI-SLSHST-REC ITM-ID                           SHIP-QTY                           UNIT-PRICE                           (NET-COST)                           DISCOUNT
The preceding query specifies that NET-COST is to be accumulated by enclosing that computed column in parentheses in the PRINT statement. In the SORT statement, ORD-ID is enclosed in parentheses to indicate that it is a control break column. A subtotal for NET-COST will be shown each time the value in the ORD-ID column changes.
Output
Following is the output after executing the preceding query.
 =>   01/02/2010                  CA Dataquery                             PAGE 1 15:31:50                                                                  DETAIL     ORD-ID  ITM-ID      SHIP-QTY  UNIT-PRICE       NET-COST   DISCOUNT   ------  ----------  --------  ----------  -------------  ---------    08811  O50006      0000203    00014.75    00002994.25   00010.00           G00222      0000100    00100.00    00010000.00   00000.00           910011      0001000    00100.00    00100000.00   00020.00     TOTAL ORD-ID 08811                                            * 00112994.25   * GRAND TOTAL                                            * 00112994.25      -------------------------------- LAST PAGE ---------------------------------  <PF1>  HELP         <PF2>  RETURN       <PF3>  TOTALS ONLY     <PF4>  DETAIL  <PF5>  NO TOTALS    <PF6>  STATS        <PF7>  BACKWARD        <PF8>  FORWARD  <PF9> NOT USED      <PF10> NOT USED     <PF11> LEFT            <PF12> RIGHT
In the preceding output screen the values contained in ORD-ID appear only once in the ORD-ID column. This is a result of setting the SUPPRESS DUPLICATE COLUMNS option to YES in your User Profile.
Subtotals are designated by TOTAL, followed by the specific control break column (ORD-ID) and the current value contained in the column. The SUBTOTAL value is preceded by an asterisk. The total is designated by * GRAND TOTAL. An asterisk also precedes the accumulated value.
Omitting Control Break Column Total
The control break columns only control what groups of data get totaled on the report. They do not control which columns get totaled. That specification occurs in the PRINT statement when you enclose a column name in parentheses.
You do not need to include the control break column in the PRINT statement to display the totals for accumulated columns. In the following query, the control break column ORD-ID is not included in the PRINT statement.
FIND 10 CAI-SLSHST-REC ROWS     WITH SHIP-QTY > 100   RELATED BY SLMN-ID TO CAI-ORDERS-REC SET NET-COST (8.2) = CAI-SLSHST-REC SHIP-QTY * UNIT-PRICE SET DISCOUNT (5.2) = NET-COST * DISC-PCT SORT CAI-ORDERS-REC BY (ORD-ID) AND      CAI-SLSHST-REC BY SHIP-QTY PRINT FROM CAI-SLSHST-REC ITM-ID                           SHIP-QTY                           UNIT-PRICE                           (NET-COST)                           DISCOUNT
Output
Following is the output when the control break column is not included in the PRINT statement.
 =>   01/02/2010                  CA Dataquery                             PAGE 1 15:32:34                                                                  DETAIL     ITM-ID      SHIP-QTY  UNIT-PRICE       NET-COST   DISCOUNT   ----------  --------  ----------  -------------  ---------   O50006      0000203    00014.75    00002994.25   00010.00     TOTAL ORD-ID 08811                                    * 00002994.25   * GRAND TOTAL                                    * 00002994.25              -------------------------------- LAST PAGE ------------------------------------  <PF1>  HELP         <PF2>  RETURN       <PF3>  TOTALS ONLY     <PF4>  DETAIL  <PF5>  NO TOTALS    <PF6>  STATS        <PF7>  BACKWARD        <PF8>  FORWARD  <PF9> NOT USED      <PF10> NOT USED     <PF11> LEFT            <PF12> RIGHT
In the preceding sample screens the subtotal lines provide the name of the control break column and the information in the column. This allows you to identify the order number and the accumulated subtotal for that order.
Specifying Multiple Control Breaks
If you specify more than one control break column in the SORT statement, your output will include a PRINT column subtotal for each specified control break column. The following query illustrates the use of multiple control breaks to obtain multiple subtotals.
FIND ALL CAI-SLSHST-REC ROWS     WITH SHIP-QTY > 100   RELATED BY SLMN-ID TO CAI-ORDERS-REC SET NET-COST (8.2) = CAI-SLSHST-REC SHIP-QTY * UNIT-PRICE SET DISCOUNT (5.2) = NET-COST * DISC-PCT SORT CAI-ORDERS-REC BY (ORD-ID) AND      CAI-SLSHST-REC BY (ITM-ID) PRINT FROM CAI-ORDERS-REC ORD-ID       FROM CAI-SLSHST-REC ITM-ID                           SHIP-QTY                           UNIT-PRICE                           (NET-COST)                           DISCOUNT
Output
The results of the preceding sample query appear on the following screen.
 => 01/02/2010                  CA Dataquery                             PAGE 1 15:34:44                                                                  DETAIL     ORD-ID  ITM-ID     SHIP-QTY  UNIT-PRICE       NET-COST   DISCOUNT   ------  ---------  --------  ----------  -------------  ---------    08001  O50006      0000203    00014.75    00002994.25   00010.00       TOTAL ITM-ID 05006                                    * 00002994.25    08001  O60011      0000193    00010.00    00001930.00   00010.00     TOTAL ITM-ID 060011                                    * 00001930.OO    08001  O60012      0000100    00020.00    00002000.00   00010.00     TOTAL ITM-ID 060012                                    * 00002000.00 TOTAL ORD-ID 08001                                    * 00006924.25 * GRAND TOTAL                                    * 00006924.25  -------------------------------- LAST PAGE ------------------------------------  <PF1>  HELP         <PF2>  RETURN       <PF3>  TOTALS ONLY     <PF4>  DETAIL  <PF5>  NO TOTALS    <PF6>  STATS        <PF7>  BACKWARD        <PF8>  FORWARD  <PF9> NOT USED      <PF10> NOT USED     <PF11> LEFT            <PF12> RIGHT
Notice in the preceding sample screen that the line identifying the ITM-ID subtotal is indented. The indented line indicates that this is the secondary control break column and the subtotal for this control break is accumulated first. The line designating the ORD-ID subtotal is not indented. The subtotal line for ORD-ID is not indented since this column is the primary control break column. The first column enclosed in parentheses in a SORT statement is always the primary control break column. Both subtotal lines identify the column used for the control break and the value contained in that column at the time the subtotal is accumulated.