Skip to content

Commit

Permalink
Generator refactoring in prep for Procedure I/O statement processing
Browse files Browse the repository at this point in the history
  • Loading branch information
davenicolette committed Jan 22, 2021
1 parent d239c51 commit 3aaac49
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 48 deletions.
Binary file added FILECOPY
Binary file not shown.
88 changes: 82 additions & 6 deletions FILECOPYT.CBL
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
05 FILLER PIC X(20).
05 IN-FIELD-2 PIC X(10).
01 OUTPUT-RECORD.
05 OUT-FIELD-1 PIC X(30).
05 OUT-FIELD-2 PIC X(5).
05 OUT-FIELD-1 PIC X(5).
05 OUT-FIELD-2 PIC X(16).
05 OUT-FIELD-3 PIC X(14).
* COPY OUTREC2.
05 FILLER PIC X(10).
05 FILLER PIC X(5).
* ZUTZCWS.CPY
01 FILLER PIC X(16) VALUE '******* COBCHECK'.
01 FILLER PIC X(16) VALUE '******* 0.1.0'.
Expand Down Expand Up @@ -126,8 +126,14 @@
* ZUTZCWS.CPY END
01 FILLER.
05 INPUT-FILE-STATUS PIC XX.
88 INPUT-OK VALUE '00'.
88 END-OF-FILE VALUE '10'.
88 FILE-NOT-FOUND VALUE '35'.
05 OUTPUT-FILE-STATUS PIC XX.
88 OUTPUT-OK VALUE '00'.
05 WS-COUNT PIC S9(5) COMP-3.
05 WS-COUNT-FORMATTED PIC ZZ,ZZ9.
05 WS-ERROR-MESSAGE PIC X(60).
PROCEDURE DIVISION.
PERFORM CC-INITIALIZE
DISPLAY "TESTSUITE:"
Expand Down Expand Up @@ -456,11 +462,81 @@
CC-END.

* ZUTZCPD.CPY END
PERFORM 1000-INITIALIZE
PERFORM 5000-PROCESS
PERFORM 8000-HOUSEKEEPING
GOBACK
.
1000-INITIALIZE.
OPEN INPUT INPUT-FILE
EVALUATE TRUE
WHEN INPUT-OK
CONTINUE
WHEN FILE-NOT-FOUND
MOVE 'Input file not found'
TO WS-ERROR-MESSAGE
WHEN OTHER
STRING "Unexpected input file status on open "
DELIMITED BY SIZE
INPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-EVALUATE

OPEN OUTPUT OUTPUT-FILE
EVALUATE TRUE
WHEN OUTPUT-OK
CONTINUE
WHEN OTHER
STRING "Unexpected output file status on open "
DELIMITED BY SIZE
OUTPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-EVALUATE

MOVE ZERO TO WS-COUNT
.

5000-PROCESS.
READ INPUT-FILE
PERFORM WITH TEST BEFORE
UNTIL END-OF-FILE
PERFORM 5200-PREPARE-OUTPUT-RECORD
PERFORM 5400-WRITE-OUTPUT-RECORD
READ INPUT-FILE
END-PERFORM
.

100-Dont-Just-Stand-There.
move 5 to ws-count
5200-PREPARE-OUTPUT-RECORD.
MOVE SPACES TO OUTPUT-RECORD
MOVE IN-FIELD-1 TO OUT-FIELD-1
MOVE IN-FIELD-2 TO OUT-FIELD-2
MOVE "Good" TO OUT-FIELD-3
.

9999-END.
5400-WRITE-OUTPUT-RECORD.
WRITE OUTPUT-RECORD
IF NOT OUTPUT-OK
STRING "Unexpected output file status on write "
DELIMITED BY SIZE
OUTPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-IF
ADD 1 TO WS-COUNT
.

8000-HOUSEKEEPING.
CLOSE OUTPUT-FILE
CLOSE INPUT-FILE
MOVE WS-COUNT TO WS-COUNT-FORMATTED
DISPLAY "Records processed: " WS-COUNT-FORMATTED
.
9999-ABORT.
DISPLAY WS-ERROR-MESSAGE
GOBACK
.
Binary file modified GREETINGT
Binary file not shown.
Empty file added foobar
Empty file.
86 changes: 81 additions & 5 deletions src/main/cobol/FILECOPY/FILECOPY.CBL
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO INFILE
SELECT INPUT-FILE ASSIGN TO "INFILE"
ORGANIZATION SEQUENTIAL
ACCESS MODE SEQUENTIAL
FILE STATUS INPUT-FILE-STATUS.
SELECT
OUTPUT-FILE
ASSIGN TO OUTFILE
ASSIGN TO "OUTFILE"
ORGANIZATION SEQUENTIAL
ACCESS MODE SEQUENTIAL
FILE STATUS IS
Expand Down Expand Up @@ -42,14 +42,90 @@
WORKING-STORAGE SECTION.
01 FILLER.
05 INPUT-FILE-STATUS PIC XX.
88 INPUT-OK VALUE '00'.
88 END-OF-FILE VALUE '10'.
88 FILE-NOT-FOUND VALUE '35'.
05 OUTPUT-FILE-STATUS PIC XX.
88 OUTPUT-OK VALUE '00'.
05 WS-COUNT PIC S9(5) COMP-3.
05 WS-COUNT-FORMATTED PIC ZZ,ZZ9.
05 WS-ERROR-MESSAGE PIC X(60).
PROCEDURE DIVISION.
PERFORM 1000-INITIALIZE
PERFORM 5000-PROCESS
PERFORM 8000-HOUSEKEEPING
GOBACK
.
1000-INITIALIZE.
OPEN INPUT INPUT-FILE
EVALUATE TRUE
WHEN INPUT-OK
CONTINUE
WHEN FILE-NOT-FOUND
MOVE 'Input file not found'
TO WS-ERROR-MESSAGE
WHEN OTHER
STRING "Unexpected input file status on open "
DELIMITED BY SIZE
INPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-EVALUATE

OPEN OUTPUT OUTPUT-FILE
EVALUATE TRUE
WHEN OUTPUT-OK
CONTINUE
WHEN OTHER
STRING "Unexpected output file status on open "
DELIMITED BY SIZE
OUTPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-EVALUATE

MOVE ZERO TO WS-COUNT
.

5000-PROCESS.
READ INPUT-FILE
PERFORM WITH TEST BEFORE
UNTIL END-OF-FILE
PERFORM 5200-PREPARE-OUTPUT-RECORD
PERFORM 5400-WRITE-OUTPUT-RECORD
READ INPUT-FILE
END-PERFORM
.

5200-PREPARE-OUTPUT-RECORD.
MOVE SPACES TO OUTPUT-RECORD
MOVE IN-FIELD-1 TO OUT-FIELD-1
MOVE IN-FIELD-2 TO OUT-FIELD-2
MOVE "Good" TO OUT-FIELD-3
.

100-Dont-Just-Stand-There.
move 5 to ws-count
5400-WRITE-OUTPUT-RECORD.
WRITE OUTPUT-RECORD
IF NOT OUTPUT-OK
STRING "Unexpected output file status on write "
DELIMITED BY SIZE
OUTPUT-FILE-STATUS
DELIMITED BY SIZE
INTO WS-ERROR-MESSAGE
PERFORM 9999-ABORT
END-IF
ADD 1 TO WS-COUNT
.

9999-END.
8000-HOUSEKEEPING.
CLOSE OUTPUT-FILE
CLOSE INPUT-FILE
MOVE WS-COUNT TO WS-COUNT-FORMATTED
DISPLAY "Records processed: " WS-COUNT-FORMATTED
.
9999-ABORT.
DISPLAY WS-ERROR-MESSAGE
GOBACK
.
4 changes: 2 additions & 2 deletions src/main/cobol/copy/OUTREC.CBL
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
05 OUT-FIELD-1 PIC X(30).
05 OUT-FIELD-1 PIC X(5).
COPY OUTREC2.
05 FILLER PIC X(10).
05 FILLER PIC X(5).
2 changes: 1 addition & 1 deletion src/main/cobol/copy/OUTREC2.CBL
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
05 OUT-FIELD-2 PIC X(5).
05 OUT-FIELD-2 PIC X(16).
05 OUT-FIELD-3 PIC X(14).
Loading

0 comments on commit 3aaac49

Please sign in to comment.