Printing and Writing Data

The specific commands used for printing or writing data are given in the Commands and logic sections. Much of how that data will look, such as in a report, is defined in the data division.

The following code is taken from a full program given in the Sample code section should illustrate how a printed report is defined in the data division. If writing to a file it would be virtually identical (see Sample code section for an example of this).

If you wished to print a report in the form of a table then you would first have to assign an identifier name to the printer in the environment division using the select clause.

  • The printout would have the following format: [click here]
  • The printer was assigned to PRINT-FILE (the FD level) with the level 01 called REPORT-OUT
  • There are four groups used to define each main part of the printout: PRINT-HEADERS (for the title and column heads), PRINT-LINE (for the actual data from the records), P-FOOTER (for the totals at the end of the table), and P-BATCH which appears after the main table and lists various totals
  • To define text, fillers are used with a VALUE of what the text is to be, e.g.
    001090       03 COL-HEAD-1 PIC X(31) 
    001100           VALUE ' PART    CUST/   DATE     QUANT'.

    This is the first line of the column header. COL-HEAD-2 giving the next line.
  • Spaces between the titles done by defining a PIC X size that is larger then the text since the extra spaces will be space-filled
  • Spaces between data are acheived by the use of fillers with a VALUE SPACES for the desired PIC X size.
  • Data and strings to be printed are first moved to the appropriate item of the print group and then the entire group is written to REPORT-OUT, which is defined as PIC X(80). For example:
    003220       MOVE PAGE-NO TO P-PAGE-NO  

    Here the page number is moved to the P-TITLE sub-group member (of PRINT-HEADERS) P-PAGE-NO. The following line effectively means:
    (AFTER PAGE instructs the printer to start a new page)
  • It is in the data groups involved in printing (or writing to a file) that data editing (such as zero-supression) is performed
  • By simply changing the ASSIGN PRINT-FILE TO 'PRINTER' to ASSIGN PRINT-FILE TO 'report.txt' would be all that was required to produce the same report in a file called 'report.txt' and add ORGANIZATION IS LINE SEQUENTIAL. Although, the AFTER PAGE and AFTER ... LINES would have no effect