The PRINT Statement

The PRINT Statement 1

Statement Format 1

Statement OPTIONS.. 1

REPORT(nbr) 1

BREAK(Field list) 2

FIELDTABLE.. 2

PAGE | SPACE(nbr) 3

SUMMARY.. 3

DATA.. 3

Data Item Options. 4

Report Layouts. 4

Default Report Layout 5

Default Line Layout 5

 

PRINT formats data for a report and prints one or more lines. It is usually used within a PROCESS block.  For example,

PROCESS Customer WHERE Customer.Balance > 1000; [Not interested in small creditors

     PRINT (Customer.Name, Customer.Address, Customer.Balance);

END PROCESS Customer;

 

PRINT is not valid within a program that uses PROGRAM xxx REPORT; Instead, use PLINE, which is a version of the PRINT statement designed to be written within $R-xxxx routines.

Statement Format

PRINT DATA(data list) [REPORT(nbr)] [BREAK(field list) [PAGE | SPACE(nbr)]] [FIELDTABLE] [SUMMARY]; 

 

The data list consists of one or several items separated by commas. Items may be

  • Field references, e.g. Customer.Name
  • Generic references, e.g. Customer.*.  This is equivalent to naming all the fields of the record or group individually.
  • String constants, e.g. 'xxxx'.
  • Numbers and decimal numbers

 

With field references you can give options: -

·         HEADING ‘field heading’

·         PIC ‘picture’

·         SUM

·         COL or RCOL

Statement OPTIONS

REPORT(nbr)

It is possible to define overall report characteristics with a REPORT statement: -

REPORT(1) PAGE(50) WIDTH(120) HEADING('Large Customer Report');

If the PRINT statement has no REPORT option then REPORT(1) is assumed. If there is no REPORT(1) statement, then a report of pagesize 60 (lines per page) and width 132 (characters per line), with heading “Report 1” is assumed.

 

A single program can produce several reports.

BREAK(Field list)

To produce a report with control breaks and subtotals you would normally include a BREAK option within the PROCESS statement: -

PROCESS in1 WHERE in1.Region >= 3 & in1.Region < 6

        ORDER(in1.Region, IN1.District BREAK, in1.Name);

    PRINT (IN1.Region,IN1.District,IN1.Name,IN1.SalesThisMonth SUM) ;

    #521 W BREAK assumed for Region

END PROCESS in1;

This produces a report like this, with subtotals on every change of in1.Region,and  IN1.District and grand totals at the end

     5       10 BLEE,VeraGladys          206.02                 

     5       10 COLBY,MaryAnn            206.02                 

     5       10 EPTHORP,JOHNMIL          206.02                 

     5       10 FRANCK,Florence          206.02                  

     5       10 HARRINGTON,Edwa          206.02                 

     5       10 HORRALL,Mildred          206.02                 

     5       10 INALL,EttieEmil          206.02                 

     5       10                        1,442.14 District Subtotal

 

     5       11 HIPTHORP,Thomas          206.02                 

     5       11                          206.02 District Subtotal

     5                                 7,211.93 Region Subtotal 

                                      19,491.79 Grand Total     

 

If you can guarantee that the input file is already in the correct order you could omit the ORDER option in the PROCESS statement, and write a BREAK option on the PRINT statement.   You could also combine such a BREAK option with PROCESS … ORDER, provided that you omit the BREAK properties within the ORDER option.

This used to be the only way of specifying control breaks and so you’ll see it in some examples, but BREAK within ORDER this is now the preferred method.

 

Here’s an example using PRINT … BREAK: -

PROCESS Customer ORDER (Customer.Region, Customer.District, Customer.Name);

     PRINT (Customer.Name, Customer.Address, Customer.Balance SUM) BREAK (Customer.Region, Customer.District);

END PROCESS Customer;

 

See Default Report Layout below to see the format rules applied by Jazz.

 

The field list named by BREAK must be part or all of the ORDER option of the enclosing PROCESS.  BREAK is not valid if the PRINT is not within a PROCESS loop.  If it is, as here, then valid BREAK field lists would be “Region”, or “Region,District”, or “Region, District, Name”.  At least one of the fields in the print list should have the field option SUM.

FIELDTABLE

With this option, instead of arranging fields across the page PRINT causes each field to be printed on its own line, with format

            Field name/Heading                Length *Value*

for example, from PRINT (in1.*) FIELDTABLE; with In1 defined

DEFINE IN1 VB DATA(

    RDKey GROUP,

        Region DECIMAL(3),

        District DECIMAL(3),

        END GROUP,

    Name (3) CHAR(5),

    SalesThisMonth DECIMAL(7,2),

    SalesYTD DECIMAL(7,2),

    BillingCycle LIKE Types.month,

    DateCommenced CHAR(10))

this printout results: -

*   Field Name   *  LENGTH  VALUE    

IN1.Region        :      4*   9      

IN1.District      :      4*   3      

IN1.Name(1)       :      5*Custo*    

IN1.Name(2)       :      5*merNa*    

IN1.Name(3)       :      5*me2  *    

IN1.SalesThisMonth:     10*    329.82

IN1.SalesYTD      :     10*  1,092.63

IN1.BillingCycle  :     13*001/January

IN1.DateCommenced :     10*2012-10-17*

 

Length is the print length.  CHAR and VARCHAR fields may print over several lines (continuation lines will be labelled   Contd”), and an asterisk is printed following their last character unless this would cause another line.

 

FIELDTABLE is designed for debugging, and for some special situations such as validating a file definition and printing conversion statistics (nbr of records in, out, sums of key values).  You would not use this option for printing every record of a file as it prints a separate line for every field, including every occurrence of every field.

 

You may not use FIELDTABLE with BREAK, PAGE, SPACE or ORDER or any field options (HEADING, SUM, etc).  

PAGE | SPACE(nbr)

With PAGE the PRINT statement will cause a new page.  SPACE(nbr) will cause the next line to be printed after spacing nbr lines, i.e. there will be (nbr – 1) blank lines.  PAGE and SPACE statement options will be ignored if there is a change in any BREAK fields: in this case line spacing is controlled by the control-break logic.

 

These options are usually used with program logic like this: -

            IF CUSTOMER.Code = 1234 THEN;
                        PRINT (‘Specified Customer’) PAGE;

 

Note that this rule is different to the rule for a PLINE statement: -

            PRINT statement: on change of page or control break any PAGE or SPACE option is ignored.

            PLINE statement: PAGE/SPACE options are not ignored, but override automatic control break spacing.

SUMMARY

Summary causes a PRINT statement to print only the Subtotal and Total lines.  Detail lines are omitted.

DATA

DATA is the most important options of the PRINT statement as it defines which fields are to be printed.  You will normally omit the keyword DATA, writing

            PRINT (Item1, Item2, item3) Other-options;

rather than writing

            PRINT DATA(Item1, Item2, item3) Other-options;

 

If DATA is written explicitly, then it does not have to be the first option of the PRINT statement.

Data Item Options

HEADING

Fields are printed in columns, normally using the field name as the column heading. For example, the field “Customer.Balance” will be printed under a column heading of “Balance” if the field requires 7 or fewer characters. If it requires more then the field name is extended with hyphens, and an asterisk marks the field boundaries. For example Customer.Name, requiring 30 characters, will use a column heading of

*------------Name------------*.

 

With Heading you explicitly specify the heading that you want. Headings are specified as character strings, e.g.

            Customer.Address HEADING 'Main Mailing Address'

As with default headings, if necessary this is expanded with *--- and ---*.

PIC

You can specify an explicit layout for data if you do not want to use the defaults provided by Jazz.  For example,

Customer.Balance PIC '$,$$$,$$9.99 CR'

The value that you provide should be a valid COBOL PICTURE clause, and should be appropriate for the data.  Jazz™ provides only limited checking: whereas the default pictures will accommodate the maximum values that the field can hold and won’t put an alphabetic picture with numeric data or vice versa, Jazz™ does not check for these possible errors with explicit PIC clauses.

 

If the field uses the SUM option then the same picture will be used for the totals as for the details, so you should ensure that the PIC value is large enough.

SUM

The field will be totalled, with totals being reported at the end of the report and subtotals being reported on control break.

COL or RCOL

Use these to specify the starting (leftmost) or finishing (rightmost) column of the data item.   If necessary COL and RCOL will cause the line to be split into two.   Use COL for CHAR and VARCHAR items, which are left-aligned, and RCOL for numeric items.

Report Layouts

A PRINT statement such as

PRINT (Customer.Name, Customer.Address, Customer.Balance);

attempts to arrange data to produce a layout that looks good and is clear.

Default Report Layout

The layout rules are: -

 

1.                  At the top of every page a page heading is printed. This has

a.      At the left, “Printed at dd mmm yyyy, hh.mm.ss”.   This is the value of $Today, i.e. the date and time at which this program starts. It will be the same on every page, no matter how long the report takes to print, and it is the date/time at which the program runs, not the date/time at which the printer actually prints the report.

b.      At the right, “Page nbr”. A page number of up to 9999. If the report has more than 9999 pages numbering will restart from 0.

c.      Centred in the space between the date/time and page number, the report heading, which is “Report 1” by default.

2.                  A blank line

3.                  One or more lines of column headings. From the PRINT statement above this would contain “Name”, “Address” and “Balance” arranged so that they appear above the corresponding data. If the column heading is shorter than the data area required, the extra space is filled with “*---” and “---*” so that it is clear where the columns begin and end.

4.                  Another blank line

5.                  Several lines of data from the PRINT statement, giving the values from up to 54* records

6.                  Another blank line

7.                  The heading is repeated as a footing.

 

 *          Assuming a page size of 60 lines per page for this example.

 

Note that there are a minimum of 6 lines per page required for page heading, column heading, and footer.  More may be needed if the PRINT statement produces more than one line, or if control breaks are involved (see below).

Default Line Layout

When you write something like

PRINT (Customer.Name, Customer.Address, Customer.Balance);

Jazz calculates the print layout as follows: -

1.                  Fields require enough space for their maximum value.

a.      for CHAR and VARCHAR fields this is simply their number of characters, i.e. a field defined

            Name VARCHAR(30)

would require 30 characters.

b.      For numbers (other than FLOAT and LONG), there must be enough space to print the maximum value that the number can hold, plus

                                                               i.      a decimal point if relevant

                                                             ii.      commas at thousands, millions, etc. if relevant

                                                            iii.      a leading minus sign if the number is negative,

                                                           iv.      a currency symbol for MONEY fields.

Thus if Customer.Balance were defined as

Balance MONEY(9,2)

then 14 character spaces would be needed to cope with “-$1,234,567.89”

2.                  Column headings are the field names, i.e. Name, Address, and Balance.

a.      If the column heading is shorter than the space required by the data, the heading is extended with “*---” and “---*”. For example

                Name VARCHAR(30)

will have a heading “*------------Name------------*”.

b.      If the heading is longer than the space required by the data, then filler is inserted

                                                               i.      To the left of numeric fields

                                                             ii.      To the right of character fields

c.      Constants (strings and numbers) have no headings.

3.                  A column’s position can be explicitly specified with COL or RCOL: -

a.      COL specifies the left-most position of the column, and is more suitable for CHAR and VARCHAR fields and string constants. COL + column-width must be less than or equal to the report’s WIDTH.

b.      RCOL specifies the left-most position of the column, and is more suitable for numeric fields and constants. RCOL must be less than or equal to the report’s WIDTH, and must be greater than the field’s width.

4.                  In the absence of COL or RCOL item options, one character of filler will be inserted between fields.

5.                  If there is insufficient room on the line to fit the next column, then a second line will be produced. This can happen because the line is already full, or because a COL or RCOL value is to the left of the end of the previous column.

Control Break Identification

PRINT  with SUM will produce subtotal lines for every control break, and a grand total line at the end.  For example: -

PROCESS in1 WHERE in1.Region >= 3 & in1.Region < 6

        ORDER(in1.Region, IN1.District BREAK, in1.Name);

    PRINT (IN1.Region,IN1.District,IN1.Name,IN1.SalesThisMonth SUM) ;

    #521 W BREAK assumed for Region

END PROCESS in1;

This produces a report like this, with subtotals on every change of in1.Region,and  IN1.District and grand totals at the end

     5       10 INALL,EttieEmil          206.02                 

     5       10                        1,442.14 District Subtotal

 

     5       11 HIPTHORP,Thomas          206.02                 

     5       11                          206.02 District Subtotal

     5                                 7,211.93 Region Subtotal 

                                      19,491.79 Grand Total     

Identification text like District Subtotal” is formed from the heading of the control break field and “ Subtotal”.  The field’s heading can be given in its definition with a HEADING property, or else will be formed from its name with hyphens replaced with blanks.  Jazz places this identification text as far to the left as it can.  In this case the longest of the three identification texts is “ District Subtotal” but there is insufficient room to place this under the IN1.Name column (although it looks as if there is plenty of room, IN1.Name is only 15 characters, and the blanks to the left of the total fields might actually have a numeric space.  However if we add three blanks after IN1.Name: -

PRINT (IN1.Region,IN1.District,IN1.Name,'   ',IN1.SalesThisMonth SUM) ;

the identifying text drops in under IN1.Name:-

     5       11 HIPTHORP,Thomas            206.02

     5       11 District Subtotal          206.02

     5          Region Subtotal          7,211.93

                Grand Total             19,491.79

 

We can use COL (or RCOL) to create space where we want this text to go: -

PRINT (IN1.Region COL(20),IN1.District,IN1.Name,IN1.SalesThisMonth SUM) ;

                        5      11 HIPTHORP,Thomas          206.02

 District Subtotal      5      11                          206.02

 Region Subtotal        5                                7,211.93

 Grand Total                                            19,491.79