The COPY statement
  ----------------------------------------------------------------------------------------------------------

Advantages of using the COPY statement.

The use of the COPY a statement reduces coding efforts and also assures that all programs
that use the file can use the same data names.
 

----------------------------------------------------------------------------------------------------------

COPY statement format

            COPY member.

All text contained in the member is duplicated in the program
at the point where the COPY appears replacing the COPY statement and the period following it.

----------------------------------------------------------------------------------------------------------
 
To compile a program that contains the COPY statement.
 

----------------------------------------------------------------------------------------------------------
 JCL reference for compile, link and go.

//STEP?? EXEC COB2J,PDS='CCPD##.CSC.COBOL',MEMBER=???????,
// COPYLIB='PDS'
//GO.???????1  DD DSN=????????,DISP=OLD
//GO.???????2  DD SYSOUT=*

----------------------------------------------------------------------------------------------------------
The COPYLIB reference in this JCL points to the //SYSLIB reference in the compile step (COB2)..

//COB2    EXEC PGM=IGYCRCTL,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//SYSIN    DD  DSN=&PDS(&MEMBER),DISP=SHR
//SYSLIB   DD  DSN=&PDS,DISP=SHR
//                DD  DSN=&COPYLIB,DISP=SHR
 

The JCL above is adequate if the member is referenced from your PDS or from the COPYLIB.

----------------------------------------------------------------------------------------------------------

There may be several COPY statements within a program.
If there are more than two sources needed to supply input,
then use a COPY statement that refers to a particular library
 
              COPY member [OF ddname].

Example:

              COPY JUNK OF MYLIB.

Then add the ddname to the compile step with

//STEP?? EXEC COB2J,PDS='CCPD##.CSC.COBOL',MEMBER=???????,
// COPYLIB='PDS'
//COB2.MYLIB   DD DSN=JPETLICK.CSC.COBOL2,DISP=SHR
//GO.???????1  DD DSN=????????,DISP=OLD
//GO.???????2  DD SYSOUT=*

----------------------------------------------------------------------------------------------------------
 COBOL PROGRAM PATTERN --  ONE READ STATEMENT

A READ statement should appear a minimal number of times.

In COBOL 85, it is possible to have the read statement appear once.  This is useful when one file drives the entire process.

Pattern for a single file driving the entire process:

Main:
    Initialize processing (Headings, zero totals, counters, etc)
    MOVE SPACES TO SWITCH.
    PERFORM UNTIL SWITCH = 'EOF'
        READ record-input
           AT END MOVE 'EOF' TO SWITCH
           NOT AT END PERFORM RECORD-PROCESSING
        END-READ
    END-PERFORM
    Format control-break summaries for output
    Write control-break line
    Write report summary line(s)
    Terminate processing

-----------------------------------------------------------------------------------------------
Record Processing with a Control Breaks

----------------------------------------------------------------------------------------------------------

 COBOL PROGRAM PATTERN -- Processing One Control Break field
 

RECORD-PROCESSING:

 IF   FIRST-RECORD-SWITCH = 'YES'
      MOVE 'NO' to FIRST-RECORD-SWITCH
      Initialize all totals, counters, etc
      MOVE CURRENT-REC-CONTROL TO STORED-REC-CONTROL
 END-IF
 

 IF   CURRENT-REC-CONTROL NOT = STORED-REC-CONTROL
      Format control-break summaries for output
      Write control-break line
      Initialize all totals, counters, etc
      MOVE CURRENT-REC-CONTROL TO STORED-REC-CONTROL
 END-IF

*****  All records are processed for totals and printing

 Move input data to output detail line
 Perform calculations for output record
 Add calculated values to totals, update counters, etc
 Write detail-line
 
***** end of record-processing

---------------------------------------------------------------------------------------------------------
Logic involved with Processing Multiple Control Break Fields
 

 ---------------------------------------------------------------------------------------------------------
COBOL PROGRAM PATTERN -- Multiple Control Break (method 1)

RECORD-PROCESSING:
 EVALUATE TRUE
 WHEN FIRST-RECORD-SWITCH = 'YES'
      MOVE 'NO' to FIRST-RECORD-SWITCH
      Initialize all totals, counters, etc
      MOVE CURRENT-MAJOR-CONTROL TO MAJOR-CONTROL
      MOVE CURRENT-MINOR-1-CONTROL TO MINOR-1-CONTROL
      MOVE CURRENT-MINOR-2-CONTROL TO MINOR-2-CONTROL
      etc
 WHEN CURRENT-MAJOR-CONTROL NOT = MAJOR-CONTROL
      PERFORM MAJOR-CONTROL-BREAK
 WHEN CURRENT-MINOR-1-CONTROL NOT = MINOR-1-CONTROL
      PERFORM MINOR-1-CONTROL-BREAK
 WHEN CURRENT-MINOR-2-CONTROL NOT = MINOR-2-CONTROL
      PERFORM MINOR-2-CONTROL-BREAK
 END-EVALUATE

 Move input data to output detail line
 Perform calculations for output record
 Add calculated values to totals, update counters, etc
 Write detail-line.

MAJOR-CONTROL-BREAK.
    PERFORM MINOR-1-CONTROL-BREAK
    Format major-control-break summaries for output
    Write major-control-break line
    Initialize major totals, counters, etc
    MOVE CURRENT-MAJOR-CONTROL TO MAJOR-CONTROL.

MINOR-1-CONTROL-BREAK.
    PERFORM MINOR-2-CONTROL-BREAK
    Format MINOR-1-control-break summaries for output
    Write MINOR-1-control-break line
    Initialize MINOR-1 totals, counters, etc
    MOVE CURRENT-MINOR-1-CONTROL TO MINOR-1-CONTROL.

MINOR-2-CONTROL-BREAK.
    Format MINOR-2-control-break summaries for output
    Write MINOR-2-control-break line
    Initialize MINOR-2 totals, counters, etc
    MOVE CURRENT- MINOR-2-CONTROL TO MINOR-2-CONTROL.

 ---------------------------------------------------------------------------------------------------------
COBOL PROGRAM PATTERN -- Processing Multiple Control Break fields
(method 2)

RECORD-PROCESSING:
 EVALUATE TRUE
 WHEN FIRST-RECORD-SWITCH = 'YES'
      MOVE 'NO' to FIRST-RECORD-SWITCH
      Initialize all totals, counters, etc
      MOVE CURRENT-MAJOR-CONTROL TO MAJOR-CONTROL
      MOVE CURRENT-MINOR-1-CONTROL TO MINOR-1-CONTROL
      MOVE CURRENT-MINOR-2-CONTROL TO MINOR-2-CONTROL
      etc
 WHEN CURRENT-MAJOR-CONTROL NOT = MAJOR-CONTROL
      PERFORM MINOR-2-CONTROL-BREAK
      PERFORM MINOR-1-CONTROL-BREAK
      PERFORM MAJOR-CONTROL-BREAK
 WHEN CURRENT-MINOR-1-CONTROL NOT = MINOR-1-CONTROL
      PERFORM MINOR-2-CONTROL-BREAK
      PERFORM MINOR-1-CONTROL-BREAK
 WHEN CURRENT-MINOR-2-CONTROL NOT = MINOR-2-CONTROL
      PERFORM MINOR-2-CONTROL-BREAK
 END-EVALUATE

     Move input data to output detail line
     Perform calculations for output record
     Add calculated values to totals, update counters, etc
     Write detail-line.

MAJOR-CONTROL-BREAK.
    Format major-control-break summaries for output
    Write major-control-break line
    Initialize major totals, counters, etc
    MOVE CURRENT-MAJOR-CONTROL TO MAJOR-CONTROL.

MINOR-1-CONTROL-BREAK.
    Format MINOR-1-control-break summaries for output
    Write MINOR-1-control-break line
    Initialize MINOR-1 totals, counters, etc
    MOVE CURRENT-MINOR-1-CONTROL TO MINOR-1-CONTROL.

MINOR-2-CONTROL-BREAK.
    Format MINOR-2-control-break summaries for output
    Write MINOR-2-control-break line
    Initialize MINOR-2 totals, counters, etc
    MOVE CURRENT- MINOR-2-CONTROL TO MINOR-2-CONTROL.
---------------------------------------------------------------------------------------------------------