The COBOL-85 Tutorial, Chapter 10

Generating reports in COBOL.

Copyright © 1998-2017

Kim Kjærsulf.


This chapter (TOC)

report writer control system.
Report Descriptor.
Vertical positioning.
Data manipulation.
SOURCE.
SUM.
VALUE.
Report sub-divisions.
RWCS in a procedure division.
INITIATE.
GENERATE.
TERMINATE.
SUPPRESS.
USE BEFORE REPORTING.
PAGE-COUNTER.
LINE-COUNTER.
Example.
Exercises

report writer control system.

[This chapter] [TOC] [Tutorial]


Report writer comprises a set of facilities in the COBOL language for generating printed reports.

The great majority of the instructions normally used when creating reports are now covered by the RWCS (report writer control system). This means that the programmer no longer has to think about factors such as data transfer, the creation of print lines, lines and page numeration, headers and footers, and setting up breaks and break totals -RWCS takes care of all of these factors which are mainly contained in the report section of the DATA DIVISION.


Report Descriptor.

[This chapter] [TOC] [Tutorial]


An RD entry (which is the equivalent of an FD-entry for files) is to be created for every report a program is to produce. After every RD it is necessary to specify one or more 01 levels, each of which describes an element (one or more lines) in the report. Every such element will always be printed as a group on the same page.


Vertical positioning.

[This chapter] [TOC] [Tutorial]


Report Writer permits each element to be comprised of several lines; LINE NUMBER is used to specify where they are to appear on the page and NEXT GROUP determines the size of the space before the next block of lines is printed.


Horizontal positioning.

[This chapter] [TOC] [Tutorial]


Use COLUMN NUMBER to specify where on a line the relevant data elements are to be written.


Data manipulation.

[This chapter] [TOC] [Tutorial]


Data added to a report element are controlled using SOURCE, SUM and VALUE.

Report sub-divisions.

[This chapter] [TOC] [Tutorial]


The physical and logical sub-divisions of a report determine what the report as a whole is to contain on a page.
Physical sub-division
PAGE is used to specify page size, the size of headers and footers, and the space provided for detail lines. RWCS uses LINE NUMBER and NEXT GROUP to place these elements and, where necessary, to change to a new page with automatic printing of headers and footers.
Logical subdivision
The report's detail groups (DETAIL) can be merged into some control groups. Each control group can begin with a CONTROL HEADING and end with a CONTROL FOOTING. A data name can be assigned to these groups which triggers a break when the value is changed.



RWCS in a procedure division.

[This chapter] [TOC] [Tutorial]


The following instructions can be used in procedure divisions:
INITIATE.
GENERATE.
TERMINATE.
SUPPRESS.
USE BEFORE REPORTING.
PAGE-COUNTER.
LINE-COUNTER.


INITIATE.

[This chapter] [TOC] [Tutorial]


INITIATE is used to initiate RWCS' internal variables; this statement must also be the first. Note that the associated file must also be opened explicitly using an OPEN statement.


GENERATE.

[This chapter] [TOC] [Tutorial]


GENERATE can be used in two situations:
a) with a data name

The specified DETAIL group is formatted and printed at the same time as the other printing procedures are taking place.
b) with a report name

This form produces a report summary only, i.e. detail lines are suppressed and only the totals are printed.


TERMINATE.

[This chapter] [TOC] [Tutorial]


TERMINATE is used to force a termination of a report. All break totals and an page (where relevant) are printed. The report file can then either be closed using a CLOSE statement or a new report can be added.


SUPPRESS.

[This chapter] [TOC] [Tutorial]


SUPPRESS is used for the rare exceptions in which a report group is not to be printed.


USE BEFORE REPORTING.

[This chapter] [TOC] [Tutorial]


USE BEFORE REPORTING specifies the statements that are called automatically before RWCS creates the report groups. In this type of program section it is possible to change the values in the SOURCE fields.


PAGE-COUNTER.

[This chapter] [TOC] [Tutorial]


PAGE-COUNTER and LINE-COUNTER are two registers automatically created when using RWCS. It is not possible to enter the values in these fields, but they can be specified as SOURCE fields.


Example.

[This chapter] [TOC] [Tutorial]


Here is an example showing how the various report elements interact; RWCS sections are nested:

      *  ------  Introduction to exercise 5.
       identification division.
      *  ------  program identification.
       program-id.    exer5.
       author.        kik.

       environment division.
      *  ------  program environment.
       configuration section.
       special-names.
            console is crt
            decimal-point is comma.
       input-output section.
       file-control.
           select isamfile assign "INDXDATA"
               organization is indexed
               access is sequential
               record key is key in isam-record
                     with duplicates
               status is file-error.
         +------------------------------------+
         ¦ select rep-file assign "REPORT"    ¦
         ¦     organization is sequential     ¦
         ¦     access is sequential           ¦
         ¦     status is file-error.          ¦
         +------------------------------------+
       data division.
      *  ------  description of files.
       file section.
       fd  isamfile.
       01  isam-record.
           03  key.
               05  custno      pic 9999.
               05  tr-code     pic 99.
           03  movement    pic 9(6)v99.
           03  balance     pic 9(6)v99.
     +----------------------------+
     ¦ fd  rep-file               ¦
     ¦     report is report.      ¦
     +----------------------------+
      *  ------  variable declarations
       working-storage section.
       01  file-error       pic 99.
      
       01  eof-code         pic 9 value 0.
           88  eof                value 1.
    +------------------------------------------+
    ¦  report section.                         ¦
    ¦  rd  report                              ¦
    ¦      control is custno in isam-record    ¦
    ¦      page limit is 66 lines              ¦
    ¦         first detail 5                   ¦
    ¦         last detail 60.                  ¦
    +------------------------------------------+
    +----------------------------------------------------------+
¦  01  page header                                         ¦
¦      line number is 2                                    ¦
¦      type is page heading.                               ¦
¦                                                          ¦
¦      05  Header pic x(20) value "Header"                 ¦
¦                    column number is 5.                   ¦
¦      NB : FILLER cannot be used here                     ¦
¦  01  customer-header                                     ¦
¦      line number is plus 2                               ¦
¦      next group is plus 2                                ¦
¦      type is control heading custno in isam-record.      ¦
¦      05  custno      pic 9999       column 1             ¦
¦                      source is custno in isam-record.    ¦
¦  01  customer-footer                                     ¦
¦      line number is plus 1                               ¦
¦      next group is plus 1                                ¦
¦      type is control footing custno in isam-record.      ¦
¦                                                          ¦
¦      05  foot-string pic x(20) value all "-"             ¦
¦                                     column 11.           ¦
¦      05  foot-text   pic x(10)      column 1             ¦
¦                                     line number is plus 1¦
¦                                     value "Total".       ¦
¦      05  cus-move  pic -----9v.99 column 11              ¦
¦                    sum movement on detail-line.          ¦
¦      05  cus-blance  pic -----9v.99 column 22            ¦
¦                     sum balance in detail-line           ¦   ¦                                                          ¦
¦                                                          ¦
¦  01  detail-line                                         ¦
¦      line number is plus 1                               ¦
¦      type is detail.                                     ¦
¦                                                          ¦
¦     05  tr-code     pic 99         column 7              ¦
¦                   source is tr-code in isam-record.      ¦
¦     05  movement  pic -----9v.99 column 11               ¦
¦                   source is movement in isam-record.     ¦
¦     05  balance   pic -----9v.99 column 22               ¦
¦                   source is balance in isam-record.      ¦
+----------------------------------------------------------+


       procedure division.                                      
      *  ------  Trap for IO-errors                              
       declaratives.                                            
      *
       isam-errors section.
           use after error procedure on isamfile.
       isam-error.
           display "Error when accessing isam data : "
                  line 24 position 1.
           display file-error line 24.
           stop run.
       isam-error-out.
           exit.
       end declaratives.
      *

      *  ------  executable instructions.

       main section.
           perform open-file.
           perform read-record.
           perform process
               until eof.
           perform close-file.
           stop run.

      *
      *
       open-file.
           open input isamfile.
    +-----------------------------------+
    ¦      open output rep-file.        ¦
    ¦      initiate report.             ¦
    +-----------------------------------+
      *
       read-post.
           read isamfile next
               at end move 1 to eof-code.
      *
       process.
    +-----------------------------------+ 
    ¦      generate detail-line.        ¦
    +-----------------------------------+
           perform read-post.
      *
       close-file.
    +-----------------------------------+
    ¦      terminate report.            ¦
    ¦      close rep-file.              ¦
    +-----------------------------------+
           close isamfile.


Exercise 1.

[This chapter] [TOC] [Tutorial]


The purpose of this exercise is to train the following points:

Design a program with which you can:

Description of the report:

The report shows all records in the file. There is to be a total for each of the following:

Report name: "REPORT"

Report layout :


Front page:
The text "Customer records per transaction code" is to be written in the middle of the font page, which is to contain nothing else.
Header:
The text from the front page plus current date, all of which is to be underlined.
Footer:
A page number on every page in the bottom right-hand corner.
Customer header:
The records for each customer should be introduced with:
The text "Customer number:" and the data .
Detail line per record:
Each record is to be display the following:
Transaction code 	Movement	Balance
Customer footer:
A total for each of the above three transaction codes.
Report total:
Totals for each of the transaction codes.


Model answer for this exercise.

Exercise 2.

[This chapter] [TOC] [Tutorial]


The purpose of this exercise is to train the following points:


Extend the program designed in exercise 1 of this chapter so that it starts by asking for a customer number interval to be covered by the printout. If no customers are to be found in a given interval this information is to be displayed in a message on the screen.


Copyright © 1998-2017

Kim Kjærsulf


Last Updated october 3, 2003
For more information contact: Kim Kjærsulf