Declaratives

This chapter describes Declaratives used in report writer.

1. USE BEFORE REPORTING

USE BEFORE REPORTING automatically executes a section in the Declaratives of the Procedure Division just before the specified report group is generated.

The USE BEFORE REPORTING section can not contain the INITIATE, GENERATE, or TERMINATE statements used in report writer.

  • declarative-section format

    figure rw usebefore
    declarative-section

To code a USE BEFORE REPORTING section, you must check that the group has a 01 level data name in order to refer to the group using the report-group-name.

The USE BEFORE REPORTING section can PERFORM other sections. You can usually do this by coding additional sections in the DECLARATIVES section without the USE statement. You can also PERFORM sections in the mainline PROCEDURE DIVISION.

The following example shows how to code one section to perform when generating one of two report groups.

       ...
       01 A-REPORT TYPE CH FOR A-CODE.
       ...
       01 B-REPORT TYPE CH FOR B-CODE.
       ...
       PROCEDURE DIVISION.
       DECLARATIVES.
       CHANGE-A SECTION.
           USE BEFORE REPORTING A-REPORT.
       CHA-000.
           PERFORM CHANGE-A-B.
       CHANGE-B SECTION.
           USE BEFORE REPORTING B-REPORT.
       CHB-000.
           PERFORM CHANGE-A-B.
       CHANGE-A-B SECTION.
       CAB-000.
           ...
       END DECLARATIVES.
Operation

If one of the report groups has a USE BEFORE REPORTING section, the report writer implicitly performs that section while processing the group.

Assuming that the report has all of the features available, the section is implicitly performed:

  • After checking the control break and creating the CONTROL FOOTING and CONTROL HEADING groups if the group is DETAIL.

  • After calculating the group total so that it can be referenced by the USE BEFORE REPORTING section.

  • Before the page-fit test and creating PAGE FOOTING and PAGE HEADING groups if the group is a body group.

  • Before setting the SOURCE and SUM fields on the lines of the group so that you can change the original fields to display in the group.

You can include a SUPPRESS PRINTING statement or a MOVE 1 TO PRINT-SWITCH in USE BEFORE REPORTING to prevent output for the group at the moment.

The USE BEFORE REPORTING section was used extensively in the ANS-68 and ANS-74 COBOL report writers. With the report writer, much of its functions are now performed by the PRESENT WHEN and PRESENT AFTER clauses. However, they can still be used as follows:

  • Use Declarative section to WRITE additional records to another file.

  • Use the USE BEFORE REPORTING section for a CONTROL HEADING group to read an additional record each time a new CONTROL value is started.

  • Force a CONTROL HEADING group to start on a new page in certain complex situations.

2. DEBUGGING

The Debugging section works in a procedure of an outer-program, not in a procedure of a nested program.

To enable the Debugging section, WITH DEBUGGING MODE must be explicitly specified in Environment Division, Configuration section, or SOURCE-COMPUTER.

  • declarative-section format

    figure declaratives debugging
    Debugging Declarative

All Debugging statements must be written right after the DECLARATIVES header.

The following describes each item in the DEBUGGING declarative.

  • procedure-name-1

    • Must not be declared in the Debugging section.

    • Given procedure-name can be specified in a single USE FOR DEBUGGING sentence only once.

    • All procedure-name can be specified only for procedures of outer-programs.

  • ALL PROCEDURES

    • The ALL PROCEDURES phrase can be specified in a program only once.

    • Specifying ALL PROCEDURES allows debugging only for an entire procedure of an outer-program.

Declaring Debugging Declarative creates a DEBUG-ITEM special register.

01 DEBUG-ITEM.
   02 DEBUG-LINE PICTURE IS X(6).
   02 FILLER PICTURE IS X VALUE SPACE.
   02 DEBUG-NAME PICTURE IS X(30).
   02 FILLER PICTURE IS X VALUE SPACE.
   02 DEBUG-SUB-1 PICTURE IS S9999 SIGN IS LEADING SEPARATE CHARACTER.
   02 FILLER PICTURE IS X VALUE SPACE.
   02 DEBUG-SUB-2 PICTURE IS S9999 SIGN IS LEADING SEPARATE CHARACTER.
   02 FILLER PICTURE IS X VALUE SPACE.
   02 DEBUG-SUB-3 PICTURE IS S9999 SIGN IS LEADING SEPARATE CHARACTER.
   02 FILLER PICTURE IS X VALUE SPACE.
   02 DEBUG-CONTENTS PICTURE IS X(n).