I am having a little issue I cannot solve. My lines are showing up wrong on my output. For example I have a line that is suppose to show up like this:
123-45-6789 J S Doe Second Yr Programming 88 266 3.02
but instead is showing up like this:
123-45-6789 J S Doe Second Yr Programming 88 266
3.02
Anyone know how to fix this. I have never encountered this problem before.
Here are is the storage area for the lines
01 DETAIL-LINE.
05 DL-FIRST-NUM PIC X(3).
05 DL-DASH-1 PIC X VALUE '-'.
05 DL-SECOND-NUM PIC XX.
05 DL-DASH-2 PIC X VALUE '-'.
05 DL-THIRD-NUM PIC X(4).
05 BLANK-A-OUT PIC X(3) VALUE SPACES.
05 DL-FIRST-LETTER PIC X.
05 BLANK-B-OUT PIC X VALUE SPACES.
05 DL-SECOND-LETTER PIC X.
05 BLANK-C-OUT PIC X VALUE SPACES.
05 DL-LAST-NAME PIC X(9).
05 BLANK-D-OUT PIC X(2) VALUE SPACES.
05 DL-CLASS-STANDING PIC X(9).
05 BLANK-E-OUT PIC X(3) VALUE SPACES.
05 DL-MAJOR PIC X(13).
05 BLANK-F-OUT PIC X(3) VALUE SPACES.
05 DL-HOURS PIC ZZ9.
05 BLANK-G-OUT PIC X(5) VALUE SPACES.
05 DL-POINTS PIC ZZ9.
05 BLANK-H-OUT PIC X(4) VALUE SPACES.
05 DL-GPA PIC 9.99.
and here is the code to write it out
400-PROCESS-ONE-RECORD.
IF LINE-COUNT >= 52
PERFORM 600-NEXT-PAGE
END-IF
ADD 2 TO LINE-COUNT
MOVE SSN-IN TO SSN-BREAK
MOVE FIRST-NUM TO DL-FIRST-NUM
MOVE SECOND-NUM TO DL-SECOND-NUM
MOVE THIRD-NUM TO DL-THIRD-NUM
MOVE STUDENT-NAME-IN TO NAME-BREAK
MOVE FIRST-LETTER TO DL-FIRST-LETTER
MOVE SECOND-LETTER TO DL-SECOND-LETTER
MOVE LAST-NAME TO DL-LAST-NAME
IF CLASS-STANDING-IN = 0
MOVE 'HIGH SCHOOL' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 1
MOVE 'First Yr' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 2
MOVE 'Second Yr' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = 3
MOVE 'PROGRAM 60' TO DL-CLASS-STANDING
END-IF
IF CLASS-STANDING-IN = ' ' OR 4
MOVE ' ' TO DL-CLASS-STANDING
END-IF
IF MAJOR-IN = 'NES'
MOVE 'Net Security' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'NET'
MOVE 'Networking' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'PGM'
MOVE 'Programming' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'DIG'
MOVE 'Digital Media' TO DL-MAJOR
END-IF
IF MAJOR-IN = 'COR'
MOVE ' ' TO DL-MAJOR
END-IF
MOVE CREDIT-HOURS-IN TO DL-HOURS
IF MAJOR-IN = 'NES'
ADD 1 TO NES-TOTAL
END-IF
IF MAJOR-IN = 'NET'
ADD 1 TO NET-TOTAL
END-IF
IF MAJOR-IN = 'PGM'
ADD 1 TO PGM-TOTAL
END-IF
IF MAJOR-IN = 'DIG'
ADD 1 TO DIG-TOTAL
END-IF
MOVE CREDIT-POINTS-IN TO DL-POINTS
COMPUTE TOTAL-GPA ROUNDED
= CREDIT-POINTS-IN / CREDIT-HOURS-IN
IF MAJOR-IN = 'NES' AND TOTAL-GPA > '3.O'
ADD 1 TO NES-GPA
END-IF
IF MAJOR-IN = 'NET' AND TOTAL-GPA > '3.O'
ADD 1 TO NET-GPA
END-IF
IF MAJOR-IN = 'PGM' AND TOTAL-GPA > '3.O'
ADD 1 TO PGM-GPA
END-IF
IF MAJOR-IN = 'DIG' AND TOTAL-GPA > '3.O'
ADD 1 TO DIG-GPA
END-IF
MOVE TOTAL-GPA TO DL-GPA
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
IF DL-CLASS-STANDING = 'First Yr' OR 'Second Yr' AND
GRAD-STAT-IN = ' ' OR 'X'
ADD CREDIT-POINTS-IN TO TOTAL-POINTS
ADD CREDIT-HOURS-IN TO TOTAL-HOURS
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINES
END-IF.
There are a couple of possible explanations for the line break.
The first explanation to eliminate is line wrapping caused by
whatever device you are displaying output on. Based on the DETAIL-LINE record
layout you have provided, the wrap occurs at column 72. Suspicious. Does your output device (eg. screen, or file) wrap lines at column 72
The next possible explanation involves some non-SPACE character, such as a line feed,
stored in BLANK-H-OUT. This may have happened through any number of programming goofs
elsewhere in the program. Unchecked out of bounds array/table references are often the
source of this sort of thing. Working this out will take some real debugging.
Are you writing to a 72 character wide file? My hunch is that your record is 3 characters too short.
Can you post your File Section?
Related
This program is to read in the SEQ file and take the data thru different validations, if it fails to comply with one of the validations the error message is moved to FIELD-NAME and FIELD-VALUE is the errored field.
After all data is processed all transaction are to be used to create the RPT file.
PROBLEM: When reviewing the RPT file, a weird issue is that ERROR FIELD NAME/ERROR FIELD VALUE keeps repeating the same error after entry is passed. I believe the problem is located in the 300, 310, 320, 330, 340, 350 sections.
Part number validation requirements Col. 01-05 must be a number, col 06 must be a capital, 07-08 must be a number in the range 01-68 or 78-99
Quantity validation requirements Leading spaces are allowed(can be all spaces), if not all spaces must be a number after leading spaces, zero value is allowed, value over 20,000 is an error
Date validation requirements month value must be 01-12, day value must be 01-31
Charge Number validation requirements cannot be blank, must be left justified(no leading spaces), and no more than one dash (hyphen) allowed
Initial validation requirements both must be letters (upper or lower case OK)
Transaction Code validation requirements must be REC, ISS, AJ+, or AJ-
If you run my attached program with the attached SEQ, your RPT will look like mine.
Below is the desired output. (pg 1)
SEQ:
11438A01 5000102667-X44 JBISS
12345A77 120103OK BY MIKELLREC
12789B02 14460606144-X22A AJ+
13168A02 31231722394 mkISS
13168A02 70102221-Q18 JBAJ-
2074B01 25 0532 OK BY JIMK RE
22109A04 20000325669-Y5Z DCISS
3077.B22 1000801144X MWAJ-
32149A01 10625567-X1 dcREC
39886B02 2000203517-AA JBAJ+
40442A2( 33 333-Q67 MKISS
43009B01 1440801899-23 MKISS
47890A02 30000422X-4-8 DCISS
49000B01 1000831901-Y6 MWAJ+
51111A011052X0905901-Y66 JBREC
52301A02 10228733876-X1 ABREC
55986b01 99990430A DCISS
57989A01 21130144X JBAJ+
57989A01 500831722394-XX MKISS
59901B0220300133X966-QQ22 MWREC
60022A01 400823 517-X1-33MWAJ+
66780B01 1000831722-YY BwREC
68999A01 21028123-Q88 MKISS
75312B01 500222966-32 BISS
77771A03 12780606 ABISS
78896B02 1000831123456-X13DCREC
80090B01 881$25983334-X25jbAJ
82432A05 420912722-X9 MWISS
83058C04 65000325Q1234 K*AJ+
85987D02 1061214Charge #32KBAJ-
87167B01 7000930144XX DCAJ+
91986 01 25072 900-23 MWISS
9576XA00 1001122j55 kbREC
96134B05 60214GOOD BSAJ-
98407C03254*00416Confirmed EHISS
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. INVTRAN.
* Tate
***************************************************************
* This program reads a fie of inventory transaction,
* validates the data, prints a report showing all transactions
* (with errors indicated), and writes a data file of
* all transactions without errors.
***************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INVENTORY-TRANS-FILE-IN
ASSIGN TO 'INVTRAN.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
* SELECT INVENTORY-TRANS-FILE-OUT
* ASSIGN TO 'INVTRAN.OUT'
* ORGANIZATION IS LINE SEQUENTIAL.
SELECT INVENTORY-TRANS-FILE-OUT-2
ASSIGN TO 'INVTRAN.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INVENTORY-TRANS-FILE-IN.
01 INVENTORY-TRANS-RECORD-IN.
05 PART-NUMBER-IN.
10 PART-NUMERIC-1-IN PIC X(5).
10 PART-ALPHABETIC-IN PIC X.
10 PART-NUMERIC-2-IN PIC XX.
88 VALID-PART-NUMERIC-2 VALUE '01' THRU '68' '78' THRU '99'.
05 QUANTITY-IN.
10 QUANTITY-9-IN PIC 9(5).
05 DATE-IN.
10 MONTH-IN PIC XX.
88 VALID-MONTH-IN VALUE '01' THRU '12'.
10 DAY-IN PIC XX.
88 VALID-DAY-IN VALUE '01' THRU '31'.
05 CHARGE-NUMBER-IN PIC X(10).
05 INITIALS-IN.
10 INITIALS-1-IN PIC X.
10 INITIALS-2-IN PIC X.
05 TRANS-CODE-IN PIC X(3).
88 VALID-TRANS-CODE-IN VALUE 'REC' 'ISS' 'AJ+' 'AJ-'.
FD INVENTORY-TRANS-FILE-OUT-2.
01 INVENTORY-TRANS-RECORD-OUT-2 PIC X(80).
WORKING-STORAGE SECTION.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 RECORDS-ERROR-SWITCH PIC X(3).
01 FIELD-ERROR-SWITCH PIC X(3).
01 WS-TOTAL PIC 99 VALUE ZERO.
01 WS-ERROR PIC 99 VALUE ZERO.
01 WS-GOOD PIC 99 VALUE ZERO.
01 WS-QUANTITY PIC 9(4) VALUE ZERO.
01 TOTAL-ERROR-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-QUANTITY PIC 9(5) VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(17) VALUE SPACES.
05 PIC X(35) VALUE 'INVENTORY TRANSACTIONS AUDIT TRAIL'.
05 PIC X(8) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-1 PIC XX.
10 PIC X VALUE '/'.
10 DAY-1 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-1 PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(5) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X(10) VALUE 'PART NO'.
05 PIC X(5) VALUE 'QUAN'.
05 PIC X(5) VALUE 'DATE'.
05 PIC X(11) VALUE 'CHARGE NO'.
05 PIC X(3) VALUE 'IN'.
05 PIC X(4) VALUE 'TRN'.
05 PIC X(3) VALUE SPACES.
05 PIC X(20) VALUE 'ERROR FIELD NAME'.
05 PIC X(17) VALUE 'ERROR FIELD VALUE'.
01 DETAIL-LINE.
05 PART-NUMBER PIC X(8).
05 PIC X VALUE SPACE.
05 QUANTITY PIC X(5).
05 PIC X VALUE SPACE.
05 DATE-X PIC X(4).
05 PIC X VALUE SPACE.
05 CHARGE-NUMBER PIC X(10).
05 PIC X VALUE SPACE.
05 INITIALS PIC XX.
05 PIC X VALUE SPACE.
05 TRANS-CODE PIC X(3).
05 PIC X(4) VALUE SPACES.
05 FIELD-NAME PIC X(18).
05 PIC XX VALUE SPACES.
05 FIELD-VALUE PIC X(10).
01 TRANSACTIONS.
05 PIC X(41) VALUE 'Total Transactions:'.
05 T-1 PIC 99.
01 ERROR-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Error Transactions:'.
05 T-2 PIC 99.
01 GOOD-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Good Transactions:'.
05 T-3 PIC 99.
01 QUANTITY-TOTAL.
05 PIC X(41) VALUE 'Good Transactions Quantity Total:'.
05 Q-4 PIC 9,999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT INVENTORY-TRANS-FILE-IN
OPEN OUTPUT INVENTORY-TRANS-FILE-OUT-2
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM 150-WRITE-HEADINGS
PERFORM UNTIL RECORDS-ERROR-SWITCH = 'YES'
READ INVENTORY-TRANS-FILE-IN
AT END
PERFORM 500-TRANSACTIONS
PERFORM 510-ERROR-TRANSACTIONS
PERFORM 520-GOOD-TRANSACTIONS
PERFORM 530-QUANTITY
MOVE 'YES' TO RECORDS-ERROR-SWITCH
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE INVENTORY-TRANS-FILE-IN
CLOSE INVENTORY-TRANS-FILE-OUT-2
STOP RUN.
150-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO INVENTORY-TRANS-RECORD-OUT-2
IF WS-FIRST-TIME-THRU = 'YES'
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 1 TO LINES-PRINTED.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 54
PERFORM 150-WRITE-HEADINGS
END-IF
MOVE 'NO' TO RECORDS-ERROR-SWITCH
PERFORM 300-VALIDATE-PART-NUMBER
PERFORM 310-VALIDATE-QUANTITY
PERFORM 320-VALIDATE-DATE
PERFORM 330-VALIDATE-CHARGE-NUMBER
PERFORM 340-VALIDATE-INITIALS
PERFORM 350-VALIDATE-TRANSACTION-CODE
MOVE PART-NUMBER-IN TO PART-NUMBER
MOVE QUANTITY-IN TO QUANTITY
MOVE DATE-IN TO DATE-X
MOVE CHARGE-NUMBER-IN TO CHARGE-NUMBER
MOVE INITIALS-IN TO INITIALS
MOVE TRANS-CODE-IN TO TRANS-CODE
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
ELSE
ADD 1 TO TOTAL-ERROR-COUNT
END-IF.
300-VALIDATE-PART-NUMBER.
IF NOT VALID-PART-NUMERIC-2
MOVE 'Part Number' TO FIELD-NAME
MOVE PART-NUMBER-IN TO FIELD-VALUE
END-IF.
310-VALIDATE-QUANTITY.
IF FUNCTION NUMVAL (QUANTITY-IN) IS GREATER THAN 20000
MOVE 'Quantity' TO FIELD-NAME
MOVE QUANTITY-IN TO FIELD-VALUE
END-IF.
320-VALIDATE-DATE.
IF NOT VALID-MONTH-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
ELSE
IF NOT VALID-DAY-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
END-IF
END-IF.
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ' '
MOVE 'Charge Number' TO FIELD-NAME
MOVE CHARGE-NUMBER-IN TO FIELD-VALUE
END-IF.
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO ' ') OR (INITIALS-2-IN IS EQUAL TO ' '))
MOVE 'Initials' TO FIELD-NAME
MOVE INITIALS-IN TO FIELD-NAME
END-IF.
350-VALIDATE-TRANSACTION-CODE.
IF NOT VALID-TRANS-CODE-IN
MOVE 'Transaction Code' TO FIELD-NAME
MOVE TRANS-CODE-IN TO FIELD-VALUE
END-IF.
500-TRANSACTIONS.
MOVE WS-TOTAL TO TRANSACTIONS
MOVE T-1 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
510-ERROR-TRANSACTIONS.
MOVE WS-ERROR TO ERROR-TRANSACTIONS
MOVE T-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
520-GOOD-TRANSACTIONS.
MOVE WS-GOOD TO GOOD-TRANSACTIONS
MOVE T-3 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
530-QUANTITY.
MOVE WS-QUANTITY TO QUANTITY-TOTAL
MOVE Q-4 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
Please ask questions if you need more clarification.
Thank you.
The reason the content of FIELD-NAME and FIELD-VALUE are repeated is that nothing was done to change the content of those fields. At a minimum, it is necessary to move spaces into those fields after writing the report line. In 200-PROCESS-ONE-RECORD, insert a MOVE statement after writing the record, such as that shown below.
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE SPACES TO FIELD-NAME FIELD-VALUE
This program is to read in the SEQ file and take the data thru different validations, if it fails to comply with one of the validations the error message is moved to FIELD-NAME.
After all data is processed all transaction are to be used to create the RPT file.
PROBLEM: When reviewing the RPT file, everything is duplicated except the Heading-Line-1. Another weird issue is that ERROR FIELD NAME/ERROR FIELD VALUE keeps repeating the same error after entry is passed.
If you run the code provided with the SEQ also provide you will see how the data currently prints. Attached below is a link to how the first page of data should look.
Desired Output file
SEQ:
11438A01 5000102667-X44 JBISS
12345A77 120103OK BY MIKELLREC
12789B02 14460606144-X22A AJ+
13168A02 31231722394 mkISS
13168A02 70102221-Q18 JBAJ-
2074B01 25 0532 OK BY JIMK RE
22109A04 20000325669-Y5Z DCISS
3077.B22 1000801144X MWAJ-
32149A01 10625567-X1 dcREC
39886B02 2000203517-AA JBAJ+
40442A2( 33 333-Q67 MKISS
43009B01 1440801899-23 MKISS
47890A02 30000422X-4-8 DCISS
49000B01 1000831901-Y6 MWAJ+
51111A011052X0905901-Y66 JBREC
52301A02 10228733876-X1 ABREC
55986b01 99990430A DCISS
57989A01 21130144X JBAJ+
57989A01 500831722394-XX MKISS
59901B0220300133X966-QQ22 MWREC
60022A01 400823 517-X1-33MWAJ+
66780B01 1000831722-YY BwREC
68999A01 21028123-Q88 MKISS
75312B01 500222966-32 BISS
77771A03 12780606 ABISS
78896B02 1000831123456-X13DCREC
80090B01 881$25983334-X25jbAJ
82432A05 420912722-X9 MWISS
83058C04 65000325Q1234 K*AJ+
85987D02 1061214Charge #32KBAJ-
87167B01 7000930144XX DCAJ+
91986 01 25072 900-23 MWISS
9576XA00 1001122j55 kbREC
96134B05 60214GOOD BSAJ-
98407C03254*00416Confirmed EHISS
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. INVTRAN.
* Tate
***************************************************************
* This program reads a fie of inventory transaction,
* validates the data, prints a report showing all transactions
* (with errors indicated), and writes a data file of
* all transactions without errors.
***************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INVENTORY-TRANS-FILE-IN
ASSIGN TO 'INVTRAN.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
* SELECT INVENTORY-TRANS-FILE-OUT
* ASSIGN TO 'INVTRAN.OUT'
* ORGANIZATION IS LINE SEQUENTIAL.
SELECT INVENTORY-TRANS-FILE-OUT-2
ASSIGN TO 'INVTRAN.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INVENTORY-TRANS-FILE-IN.
01 INVENTORY-TRANS-RECORD-IN.
05 PART-NUMBER-IN.
10 PART-NUMERIC-1-IN PIC X(5).
10 PART-ALPHABETIC-IN PIC X.
10 PART-NUMERIC-2-IN PIC XX.
88 VALID-PART-NUMERIC-2 VALUE '01' THRU '68' '78' THRU '99'.
05 QUANTITY-IN.
10 QUANTITY-9-IN PIC 9(5).
05 DATE-IN.
10 MONTH-IN PIC XX.
88 VALID-MONTH-IN VALUE '01' THRU '12'.
10 DAY-IN PIC XX.
88 VALID-DAY-IN VALUE '01' THRU '31'.
05 CHARGE-NUMBER-IN PIC X(10).
05 INITIALS-IN.
10 INITIALS-1-IN PIC X.
10 INITIALS-2-IN PIC X.
05 TRANS-CODE-IN PIC X(3).
88 VALID-TRANS-CODE-IN VALUE 'REC' 'ISS' 'AJ+' 'AJ-'.
FD INVENTORY-TRANS-FILE-OUT-2.
01 INVENTORY-TRANS-RECORD-OUT-2 PIC X(80).
WORKING-STORAGE SECTION.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 RECORDS-ERROR-SWITCH PIC X(3).
01 FIELD-ERROR-SWITCH PIC X(3).
01 WS-TOTAL PIC 99 VALUE ZERO.
01 WS-ERROR PIC 99 VALUE ZERO.
01 WS-GOOD PIC 99 VALUE ZERO.
01 WS-QUANTITY PIC 9V999 VALUE ZERO.
01 TOTAL-ERROR-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-COUNT PIC 9(3) VALUE ZERO.
01 TOTAL-GOOD-QUANTITY PIC 9(5) VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(17) VALUE SPACES.
05 PIC X(35) VALUE 'INVENTORY TRANSACTIONS AUDIT TRAIL'.
05 PIC X(8) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-1 PIC XX.
10 PIC X VALUE '/'.
10 DAY-1 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-1 PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(5) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X(10) VALUE 'PART NO'.
05 PIC X(5) VALUE 'QUAN'.
05 PIC X(5) VALUE 'DATE'.
05 PIC X(11) VALUE 'CHARGE NO'.
05 PIC X(3) VALUE 'IN'.
05 PIC X(4) VALUE 'TRN'.
05 PIC X(3) VALUE SPACES.
05 PIC X(20) VALUE 'ERROR FIELD NAME'.
05 PIC X(17) VALUE 'ERROR FIELD VALUE'.
01 DETAIL-LINE.
05 PART-NUMBER PIC X(8).
05 PIC X VALUE SPACE.
05 QUANTITY PIC X(5).
05 PIC X VALUE SPACE.
05 DATE-X PIC X(4).
05 PIC X VALUE SPACE.
05 CHARGE-NUMBER PIC X(10).
05 PIC X VALUE SPACE.
05 INITIALS PIC XX.
05 PIC X VALUE SPACE.
05 TRANS-CODE PIC X(3).
05 PIC X(4) VALUE SPACES.
05 FIELD-NAME PIC X(18).
05 PIC XX VALUE SPACES.
05 FIELD-VALUE PIC X(10).
01 TRANSACTIONS.
05 PIC X(41) VALUE 'Total Transactions:'.
05 T-1 PIC 99.
01 ERROR-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Error Transactions:'.
05 T-2 PIC 99.
01 GOOD-TRANSACTIONS.
05 PIC X(41) VALUE 'Total Good Transactions:'.
05 T-3 PIC 99.
01 QUANTITY-TOTAL.
05 PIC X(41) VALUE 'Good Transactions Quantity Total:'.
05 Q-4 PIC 9,999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT INVENTORY-TRANS-FILE-IN
OPEN OUTPUT INVENTORY-TRANS-FILE-OUT-2
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM 150-WRITE-HEADINGS
PERFORM UNTIL RECORDS-ERROR-SWITCH = 'YES'
READ INVENTORY-TRANS-FILE-IN
AT END
PERFORM 500-TRANSACTIONS
PERFORM 510-ERROR-TRANSACTIONS
PERFORM 520-GOOD-TRANSACTIONS
PERFORM 530-QUANTITY
MOVE 'YES' TO RECORDS-ERROR-SWITCH
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE INVENTORY-TRANS-FILE-IN
CLOSE INVENTORY-TRANS-FILE-OUT-2
STOP RUN.
150-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO INVENTORY-TRANS-RECORD-OUT-2
IF WS-FIRST-TIME-THRU = 'YES'
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE 1 TO LINES-PRINTED.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 54
PERFORM 150-WRITE-HEADINGS
END-IF
MOVE 'NO' TO RECORDS-ERROR-SWITCH
PERFORM 300-VALIDATE-PART-NUMBER
PERFORM 310-VALIDATE-QUANTITY
PERFORM 320-VALIDATE-DATE
PERFORM 330-VALIDATE-CHARGE-NUMBER
PERFORM 340-VALIDATE-INITIALS
PERFORM 350-VALIDATE-TRANSACTION-CODE
MOVE PART-NUMBER-IN TO PART-NUMBER
MOVE QUANTITY-IN TO QUANTITY
MOVE DATE-IN TO DATE-X
MOVE CHARGE-NUMBER-IN TO CHARGE-NUMBER
MOVE INITIALS-IN TO INITIALS
MOVE TRANS-CODE-IN TO TRANS-CODE
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
ELSE
ADD 1 TO TOTAL-ERROR-COUNT
END-IF.
300-VALIDATE-PART-NUMBER.
IF NOT VALID-PART-NUMERIC-2
MOVE 'Part Number' TO FIELD-NAME
MOVE PART-NUMBER-IN TO FIELD-VALUE
END-IF.
310-VALIDATE-QUANTITY.
IF QUANTITY-9-IN IS GREATER THAN '20,000'
MOVE 'Quantity' TO FIELD-NAME
MOVE QUANTITY-IN TO FIELD-VALUE
END-IF.
320-VALIDATE-DATE.
IF NOT VALID-MONTH-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
ELSE
IF NOT VALID-DAY-IN
MOVE 'Date' TO FIELD-NAME
MOVE DATE-IN TO FIELD-VALUE
END-IF
END-IF.
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ''
MOVE 'Charge Number' TO FIELD-NAME
MOVE CHARGE-NUMBER-IN TO FIELD-VALUE
END-IF.
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO '') OR (INITIALS-2-IN IS EQUAL TO ''))
MOVE 'Initials' TO FIELD-NAME
MOVE INITIALS-IN TO FIELD-NAME
END-IF.
350-VALIDATE-TRANSACTION-CODE.
IF NOT VALID-TRANS-CODE-IN
MOVE 'Transaction Code' TO FIELD-NAME
MOVE TRANS-CODE-IN TO FIELD-VALUE
END-IF.
500-TRANSACTIONS.
MOVE WS-TOTAL TO TRANSACTIONS
MOVE T-1 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
510-ERROR-TRANSACTIONS.
MOVE WS-ERROR TO ERROR-TRANSACTIONS
MOVE T-2 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
520-GOOD-TRANSACTIONS.
MOVE WS-GOOD TO GOOD-TRANSACTIONS
MOVE T-3 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
530-QUANTITY.
MOVE WS-QUANTITY TO QUANTITY-TOTAL
MOVE Q-4 TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2 AFTER ADVANCING 2 LINES.
If you have any questions please let me know.
The duplicate output occurs in the following code.
IF RECORDS-ERROR-SWITCH = 'NO'
ADD 1 TO TOTAL-GOOD-COUNT
ADD 1 TO TOTAL-GOOD-QUANTITY
WRITE INVENTORY-TRANS-RECORD-OUT-2
MOVE DETAIL-LINE TO INVENTORY-TRANS-RECORD-OUT-2
WRITE INVENTORY-TRANS-RECORD-OUT-2
The first WRITE statement prints a duplicate of the previous line. The second WRITE statement prints a new line, which is printed again on the next loop. Remove the first WRITE statement.
Other problems I noted are:
Invalid literals
330-VALIDATE-CHARGE-NUMBER.
IF CHARGE-NUMBER-IN IS EQUAL TO ''
340-VALIDATE-INITIALS.
IF ((INITIALS-1-IN IS EQUAL TO '') OR (INITIALS-2-IN IS EQUAL TO ''))
A zero-length literal is not permitted; thus, in each case, '' should be ' '.
Invalid numeric compare
310-VALIDATE-QUANTITY.
IF QUANTITY-9-IN IS GREATER THAN '20,000'
QUANTITY-9-IN is defined as PIC 9(5); however the data contains leading spaces and '20,000' is not valid for numeric comparisons. A proper numeric comparison could be:
IF FUNCTION NUMVAL (QUANTITY-IN) IS GREATER THAN 20000
These following were not investigated further than noted.
Print spacing does not match the desired output
There are no ADVANCING phrases for the lines written, thus only single-spacing is used.
Totals do not print correctly
WS-QUANTITY is defined as PIC 9V999. It should be 9999 or 9(4).
The data items for the totals are not being incremented.
The MOVE statements in the 500-, 510-, 520-, and 530- paragraphs overwrite fixed text.
This program have an SEQ file that it reads and is suppose to bypass all students that are graduated (Y), if Class Standing is other than first-year or second-year (1 or 2), and if their major is not programming (PGM), digital media (DIG) or Network Security (NES). My program is suppose to also do calculates, but currently I m just trying to get the data to print out in an RPT file. It is also suppose to format the Social Security Numbers (like XXX-XX-XXXX). Format Student Name: First Initial Middle Initial Last Name (like A B Brown) Then print First Yr or Second Yr. Next, what there major is. Then how many hours, points, and calculate and display their GPA.
Column Field Type / Format
01-09 Social Security Number Alphanumeric
(no dashes in data file)
10-21 Student Name Alphanumeric
(first initial, middle initial, last name --- no spaces between these items in data file)
26 Graduation Status Alphanumeric
(Y = student has graduated --- and other values of Graduation Status)
27 Class Standing Alphanumeric
(1 = first-year, 2 = second-year --- and other values of Class Standing)
28-30 Major Alphanumeric
(PGM, DIG, NES --- and other values of Major)
(PGM = Programming, DIG = Digital Media, and NES = Network Security)
31-33 Credit Hours Earned Numeric, no decimals
34-36 Credit Points Earned Numeric, no decimals
Current program:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT STUDENTS-FILE-IN
ASSIGN TO 'STUDENTS.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT STUDENTS-FILE-OUT
ASSIGN TO 'STUDENTS.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SOCIAL-SECURITY-NUMBER-IN PIC X(9).
05 STUDENT-NAME-IN PIC X(12).
05 PIC X(4).
05 GRADUATION-STATUS-IN PIC X.
05 CLASS-STANDING-IN PIC X.
05 MAJOR-IN PIC X(3).
05 CREDIT-HOURS-EARNED-IN PIC 9(3).
05 CREDIT-POINTS-EARNED-IN PIC 9(3).
FD STUDENTS-FILE-OUT.
01 STUDENTS-RECORD-OUT PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 WS-GRAND-HOURS PIC 9(3) VALUE ZERO.
01 WS-GRAND-POINTS PIC 9(3) VALUE ZERO.
01 WS-GRAND-GPA PIC Z.ZZ VALUE ZERO.
01 WS-PRO-STUDENT PIC ZZ VALUE ZERO.
01 WS-PRO-GPA-NUM PIC ZZ VALUE ZERO.
01 WS-PRO-GPA-PER PIC ZZ.Z VALUE ZERO.
01 WS-DIG-STUDENT PIC ZZ VALUE ZERO.
01 WS-DIG-GPA-NUM PIC ZZ VALUE ZERO.
01 WS-DIG-GPA-PER PIC ZZ.Z VALUE ZERO.
01 WS-NES-STUDENT PIC ZZ VALUE ZERO.
01 WS-NES-GPA-NUM PIC ZZ VALUE ZERO.
01 WS-PRO-GPA-PER PIC ZZ.Z VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(22) VALUE SPACES.
05 PIC X(33) VALUE '------ ----- ------- ----- ------'.
05 PIC X(6) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-2 PIC XX.
10 PIC X VALUE'/'.
10 DAY-2 PIC XX.
10 PIC X VALUE'/'.
10 YEAR-2 PIC XX.
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X VALUE SPACE.
05 PIC X(10) VALUE 'SOC SEC NO'.
05 PIC X(4) VALUE SPACES.
05 PIC X(12) VALUE 'STUDENT NAME'.
05 PIC X(3) VALUE SPACES.
05 PIC X(8) VALUE 'STANDING'.
05 PIC X(4) VALUE SPACES.
05 PIC X(5) VALUE 'MAJOR'.
05 PIC X(10) VALUE SPACES.
05 PIC X(5) VALUE 'HOURS'.
05 PIC X(2) VALUE SPACES.
05 PIC X(6) VALUE 'POINTS'.
05 PIC X(5) VALUE SPACES.
05 PIC X(3) VALUE 'GPA'.
01 DETAIL-LINE.
05 PIC X VALUE SPACE.
05 SOCIAL-SECURITY-NUMBER-OUT PIC X(11).
05 SSN-FIRST PIC X(3).
05 SSN-FDASH PIC X VALUE "-".
05 SSN-MIDDLE PIC X(02).
05 SSN-MDASH PIC X VALUE "-".
05 SSN-LAST PIC X(04).
05 PIC X(3) VALUE SPACES.
05 STUDENT-NAME-OUT PIC X(13).
05 FNAME PIC X.
05 PIC X VALUE SPACE.
05 MNAME PIC X.
05 PIC X VALUE SPACE.
05 LNAME PIC X(9).
05 STANDING-OUT PIC X(9).
05 PIC X(3) VALUE SPACES.
05 MAJOR-OUT PIC X(13).
05 PIC X(4) VALUE SPACES.
05 HOURS-OUT PIC X(2).
05 PIC X(5) VALUE SPACES.
05 POINTS-OUT PIC X(3).
05 PIC X(4) VALUE SPACES.
05 STUDENT-GPA-OUT PIC 9.99.
01 TOTALS-LINE.
05 PIC X VALUE SPACE.
05 PIC X(6) VALUE 'TOTALS'.
05 PIC X(50) VALUE SPACES.
05 TL-GRAND-HOURS PIC Z,ZZZ.
05 PIC X(2) VALUE SPACES.
05 TL-GRAND-POINTS PIC ZZ,ZZZ.
05 PIC X(4) VALUE SPACES.
05 TL-GRAND-GPA PIC 9.99.
01 TOTALS-LINE-2A.
05 PIC X VALUE SPACE.
05 PIC X(19) VALUE 'PROGRAMMING MAJORS:'.
01 TOTALS-LINE-2B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'NUMBER OF STUDENTS'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-PRO-STUDENT PIC X(2).
01 TOTALS-LINE-2C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'NUMBER WITH GPA > 3.0'.
05 PIC X(7) VALUE SPACES.
05 TL-GRAND-PRO-NUM-GPA PIC X.
01 TOTALS-LINE-2D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'PERCENT WITH GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-PRO-GPA-PER PIC ZZ.9.
01 TOTALS-LINE-3A.
05 PIC X VALUE SPACE.
05 PIC X(21) VALUE 'DIGITAL MEDIA MAJORS:'.
01 TOTALS-LINE-3B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'NUMBER OF STUDENTS'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-DIG-STUDENT PIC X(2).
01 TOTALS-LINE-3C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'NUMBER WITH GPA > 3.0'.
05 PIC X(7) VALUE SPACES.
05 TL-GRAND-DIG-NUM-GPA PIC X.
01 TOTALS-LINE-3D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'PERCENT WITH GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-DIG-GPA-PER PIC ZZ.9.
01 TOTALS-LINE-4A.
05 PIC X VALUE SPACE.
05 PIC X(24) VALUE 'NETWORK SECURITY MAJORS:'.
01 TOTALS-LINE-4B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'NUMBER OF STUDENTS'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-NET-STUDENT PIC X(2).
01 TOTALS-LINE-4C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'NUMBER WITH GPA > 3.0'.
05 PIC X(7) VALUE SPACES.
05 TL-GRAND-NET-NUM-GPA PIC X.
01 TOTALS-LINE-4D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'PERCENT WITH GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-NET-GPA-PER PIC ZZ.9.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT STUDENTS-FILE-IN
OPEN OUTPUT STUDENTS-FILE-OUT
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ STUDENTS-FILE-IN
AT END
PERFORM 400-TOTALS-ROUTINE
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE STUDENTS-FILE-IN
CLOSE STUDENTS-FILE-OUT
STOP RUN.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 53
PERFORM 300-WRITE-HEADINGS
END-IF
IF GRADUATION-STATUS-IN IS NOT EQUAL TO 'Y'
CONTINUE
IF CLASS-STANDING-IN IS EQUAL TO '1' OR '2'
CONTINUE
IF MAJOR-IN IS EQUAL TO 'PGM' OR 'NES' OR 'DIG'
END-IF
MOVE SOCIAL-SECURITY-NUMBER-IN TO SOCIAL-SECURITY-NUMBER-OUT
MOVE STUDENT-NAME-IN TO STUDENT-NAME-OUT
IF CLASS-STANDING-IN IS EQUAL TO '1'
MOVE 'First Yr' TO STANDING-OUT
IF CLASS-STANDING-IN IS EQUAL TO '2'
MOVE 'Second Yr' TO STANDING-OUT
END-IF
IF MAJOR-IN IS EQUAL TO 'PGM'
MOVE 'Programming' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'NES'
MOVE 'Net Security' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'DIG'
MOVE 'Digital Media' TO MAJOR-OUT
END-IF
MOVE CREDIT-HOURS-EARNED-IN TO HOURS-OUT
MOVE CREDIT-POINTS-EARNED-IN TO POINTS-OUT
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
COMPUTE WS-GRAND-HOURS = WS-GRAND-HOURS + CREDIT-HOURS-EARNED-IN
COMPUTE WS-GRAND-POINTS = WS-GRAND-POINTS + CREDIT-POINTS-EARNED-IN
COMPUTE WS-GRAND-GPA ROUNDED = WS-GRAND-HOURS / WS-GRAND-POINTS.
300-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO STUDENTS-RECORD-OUT
IF WS-FIRST-TIME-THRU = 'YES'
WRITE STUDENTS-RECORD-OUT
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE STUDENTS-RECORD-OUT AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1
MOVE 3 TO LINES-PRINTED.
400-TOTALS-ROUTINE.
IF LINES-PRINTED > 53
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-GRAND-HOURS TO TL-GRAND-HOURS
MOVE WS-GRAND-POINTS TO TL-GRAND-POINTS
MOVE WS-GRAND-GPA TO TL-GRAND-GPA
MOVE TOTALS-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT AFTER ADVANCING 3 LINES
ADD 2 TO LINES-PRINTED.
Current RPT output file:
------ ----- ------- ----- ------ 03/03/21 PAGE 1
SOC SEC NO STUDENT NAME STANDING MAJOR HOURS POINTS GPA
TOTALS 0.00
Needs RPT file needs to print like:
------ ----- ------- ----- ------ 03/03/21 PAGE 1
SOC SEC NO STUDENT NAME STANDING MAJOR HOURS POINTS GPA
377-65-8797 M J Abbott First Yr Digital Media 21 70 3.33
445-90-3241 J C Armour Second Yr Programming 59 140 2.37
877-39-5401 K F Ault First Yr Net Security 44 132 3.00
980-44-3254 R L Bishop First Yr Net Security 20 62 3.10
307-54-8872 D R Boyer Second Yr Digital Media 55 168 3.05
345-21-3465 R D Byers First Yr Net Security 10 24 2.40
659-87-6655 S A Campbell Second Yr Programming 66 180 2.73
907-88-3271 D E Copeland Second Yr Net Security 67 202 3.01
387-78-9843 K D Curtis Second Yr Programming 55 160 2.91
887-65-8341 R M Davis First Yr Programming 40 119 2.98
477-80-9325 D P Donaldson First Yr Digital Media 5 12 2.40
207-55-9801 A L Duffy First Yr Net Security 23 75 3.26
399-82-3781 A F Edwards Second Yr Net Security 66 261 3.95
345-32-1092 M L Evans Second Yr Digital Media 70 201 2.87
768-43-2214 W S Ewing First Yr Programming 21 44 2.10
335-76-9801 A C Farkas Second Yr Programming 80 241 3.01
555-87-9214 T E Frail First Yr Digital Media 1 3 3.00
609-95-4386 R L Fuller Second Yr Net Security 88 352 4.00
872-11-9903 J M Garcia Second Yr Digital Media 65 190 2.92
847-64-3902 R S Gordon First Yr Programming 5 17 3.40
675-50-9821 S L Guthrie First Yr Programming 22 88 4.00
226-54-7855 R L Hartman First Yr Net Security 111 440 3.96
448-82-3177 G C Hill Second Yr Programming 87 169 1.94
598-87-3240 W E Hyde Second Yr Programming 55 159 2.89
389-55-7430 H P Ickes First Yr Net Security 18 56 3.11
499-08-7112 D L Imler Second Yr Net Security 74 209 2.82
299-00-6573 R D Isley First Yr Digital Media 10 39 3.90
776-04-4879 H L Jackson First Yr Digital Media 42 108 2.57
899-01-2845 K M Joseph Second Yr Programming 88 260 2.95
176-59-0831 D L Justice Second Yr Digital Media 76 230 3.03
769-94-1659 F D Kahle Second Yr Digital Media 79 240 3.04
307-98-5332 E S Kirk First Yr Programming 9 16 1.78
387-95-6422 D A Koch Second Yr Net Security 63 222 3.52
822-43-8009 S R Laman Second Yr Net Security 80 240 3.00
078-96-5516 C J Lott First Yr Programming 9 30 3.33
188-64-3487 P T Lyons First Yr Programming 45 136 3.02
307-88-4251 J A McDonnell First Yr Net Security 9 28 3.11
598-77-4365 S B Miller Second Yr Digital Media 86 249 2.90
218-87-9563 L R Nickles First Yr Net Security 44 144 3.27
345-90-1226 R J Nunn First Yr Programming 32 99 3.09
465-58-9021 R T O'Brien Second Yr Digital Media 88 352 4.00
774-65-8832 D E Osborne Second Yr Digital Media 76 228 3.00
489-97-6092 R V Parent Second Yr Net Security 66 200 3.03
783-22-5185 D W Price Second Yr Programming 78 228 2.92
999-04-7621 S D Queen First Yr Programming 20 60 3.00
836-61-9047 N C Quinn First Yr Digital Media 44 133 3.02
657-73-2064 D W Rabe Second Yr Digital Media 99 381 3.85
227-68-9014 D L Robinson First Yr Programming 38 113 2.97
376-65-9081 L A Smith Second Yr Net Security 112 336 3.00
117-98-0236 J I Taylor First Yr Net Security 42 127 3.02
988-72-5701 L R Truman Second Yr Programming 100 380 3.80
430-95-7205 N H Underwood Second Yr Net Security 98 392 4.00
RHODES STATE COLLEGE GRADE REPORT 10/11/12 PAGE 2
SOC SEC NO STUDENT NAME STANDING MAJOR HOURS POINTS GPA
309-44-7620 L J Uzelac First Yr Programming 23 72 3.13
467-09-8853 C A Valenti First Yr Programming 10 10 1.00
988-32-0851 H E Vorhees Second Yr Net Security 21 68 3.24
598-83-2016 C L Wagner First Yr Digital Media 29 88 3.03
699-38-7440 L S Wood Second Yr Net Security 60 177 2.95
499-02-1987 J A Yant First Yr Net Security 42 127 3.02
399-78-0041 R E Young Second Yr Digital Media 111 333 3.00
498-37-6022 R J Zellers Second Yr Digital Media 90 360 4.00
984-00-2164 R T Zuber Second Yr Programming 88 266 3.02
Totals 3,235 10,246 3.17
Programming Majors:
Number of students 22
Number with GPA > 3.0 9
Percent with GPA > 3.0 40.9%
Digital Media Majors:
Number of students 18
Number with GPA > 3.0 10
Percent with GPA > 3.0 55.6%
Network Security Majors:
Number of students 21
Number with GPA > 3.0 15
Percent with GPA > 3.0 71.4%
SEQ file:
675509821SLGuthrie 1PGM022088
226547855RLHartman 1NES111440
448823177GCHill 2PGM087169
598873240WEHyde 2PGM055159
389557430HPIckes 1NES018056
499087112DLImler 2NES074209
299006573RDIsley 1DIG010039
776044879HLJackson X1DIG042108
899012845KMJoseph 2PGM088260
176590831DLJustice 2DIG076230
769941659FDKahle 2DIG079240
307985332ESKirk 1PGM009016
387956422DAKoch 2NES063222
822438009SRLaman 2NES080240
409875621KRLester DIG065190
078965516CJLott 1PGM009030
188643487PTLyons 1PGM045136
307884251JAMcDonnell 1NES009028
598774365SBMiller 2DIG086249
218879563LRNickles 1NES044144
345901226RJNunn 1PGM032099
465589021RTO'Brien 2DIG088352
774658832DEOsborne 2DIG076228
489976092RVParent 2NES066200
783225185DWPrice 2PGM078228
999047621SDQueen 1PGM020060
836619047NCQuinn 1DIG044133
657732064DWRabe 2DIG099381
227689014DLRobinson 1PGM038113
848769033PBSadler 1COR008030
376659081LASmith 2NES112336
117980236JITaylor 1NES042127
988725701LRTruman 2PGM100380
430957205NHUnderwood 2NES098392
309447620LJUzelac 1PGM023072
467098853CAValenti 1PGM010010
988320851HEVorhees 2NES021068
598832016CLWagner 1DIG029088
699387440LSWood 2NES060177
499021987JAYant 1NES042127
399780041REYoung 2DIG111333
498376022RJZellers 2DIG090360
231442095JBZink 0PGM090360
984002164RTZuber 2PGM088266
In Cobol if statements must be explicitly ended by either a end-if or .
So
IF MAJOR-IN IS EQUAL TO 'PGM'
MOVE 'Programming' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'NES'
MOVE 'Net Security' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'DIG'
MOVE 'Digital Media' TO MAJOR-OUT
END-IF
MOVE CREDIT-HOURS-EARNED-IN TO HOURS-OUT
MOVE CREDIT-POINTS-EARNED-IN TO POINTS-OUT
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
indented properly would be
IF MAJOR-IN IS EQUAL TO 'PGM'
MOVE 'Programming' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'NES'
MOVE 'Net Security' TO MAJOR-OUT
IF MAJOR-IN IS EQUAL TO 'DIG'
MOVE 'Digital Media' TO MAJOR-OUT
END-IF
MOVE CREDIT-HOURS-EARNED-IN TO HOURS-OUT
MOVE CREDIT-POINTS-EARNED-IN TO POINTS-OUT
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
The only way student record will be written is if
MAJOR-IN = 'PGM' and MAJOR-IN = 'NES' at the same time which is impossible so nothing is written.
This is just one of the problems in the program, I will leave you to apply similar fixes through out the program
Also CONTINUE means do nothing, so is pointless in this code as written
IF GRADUATION-STATUS-IN IS NOT EQUAL TO 'Y'
CONTINUE
IF CLASS-STANDING-IN IS EQUAL TO '1' OR '2'
CONTINUE
IF MAJOR-IN IS EQUAL TO 'PGM' OR 'NES' OR 'DIG'
END-IF
Work out you want the code to do and fix it.
Written my program but I cannot get the right output as needed
Below is my code and my input with the output.
Also does my procedure program make sense or should I revise it, it seems it makes sense but after looking at different books I'm not sure anymore.
FD INPUT-FILE.
01 INPUT-RECORD.
05 EXCUSE-NUMBER PIC 9(02).
88 VALID-EXCUSE VALUE 1 THRU 10.
05 FILLER PIC X(03).
05 NUMBER-TIMES-USED PIC 9(02).
05 FILLER PIC X(73).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(80).
FD ERROR-FILE.
01 ERROR-RECORD PIC X(80).
WORKING-STORAGE SECTION.
******************************************************************
* DEFINES PROCESSINGVARIABLES AND OUTPUT LINES *
******************************************************************
01 WS-AREA.
05 WS-IF-STATUS PIC X(02).
05 WS-OF-STATUS PIC X(02).
05 WS-EF-STATUS PIC X(02).
05 WS-END-OF-FILE PIC X(01) VALUE "N".
88 AT-WS-END-OF-FILE VALUE "Y".
05 WS-INVALID-RECORD PIC X(01) VALUE "N".
05 WS-LINE-NUMBER PIC 9(03) VALUE 0.
05 WS-MOST-USED-EXCUSE PIC 9(02) VALUE 0.
05 WS-EXCUSE PIC 9(02) VALUE 0.
05 WS-EXCUSE-TOTAL PIC 9(04).
01 BLANK-LINE.
05 PIC X(80).
******************************************************************
* (THIS IS WHERE THE HEADING ON THE PRINT OUT SHEET GOES) *
******************************************************************
01 HEADING-LINE-1.
05 FILLER PIC X(14) VALUE SPACES.
05 FILLER PIC X(37)
VALUE "TEN MOST OUTRAGEOUS HOME-WORK EXCUSES".
01 HEADING-LINE-2.
05 FILLER PIC X(11).
05 FILLER PIC X(06) VALUE "RECORD".
05 FILLER PIC X(08).
05 FILLER PIC X(05) VALUE "IMAGE".
******************************************************************
* DETAIL-LINE COMMENTS. *
* on the detail line we are writing out the Data information *
* in particular, when we write out the line-number, error *
* excuse number, excuses used, and how many times used *
* Detail summary will be reported out *
* Stars will be Display underneath bad data. *
*****************************************************************
01 DETAIL-LINE.
05 FILLER PIC X(03).
05 DL-EXCUSE-NUMBER PIC 9(02).
05 FILLER PIC X(03).
05 DL-EXCUSE-USED PIC X(51).
05 FILLER PIC X(03).
05 DL-AMOUNT-USED PIC ZZ9.
01 DETAIL-LINE-ERROR-1.
05 FILLER PIC X(08) VALUE SPACES.
05 DLE-LINE-NUMBER PIC ZZ9.
05 FILLER PIC X(09) VALUE SPACES.
05 DLE-ERROR PIC X(16).
01 DETAIL-LINE-ERROR-2.
05 FILLER PIC X(20) VALUE SPACES.
05 DLE-EXCUSE-NUMBER PIC X(02) VALUE SPACES.
05 FILLER PIC X(03) VALUE SPACES.
05 DLE-EXCUSE PIC X(02) VALUE SPACES.
01 DETAIL-TOTAL.
05 FILLER PIC X(41) VALUE SPACES.
05 FILLER PIC X(20)
VALUE "TOTAL EXCUSES USED =".
05 DT-TOTAL PIC ZZZ9 VALUE ZERO.
01 DETAIL-TOTAL-MOST-USED.
05 FILLER PIC X(34) VALUE SPACES.
05 FILLER PIC X(27)
VALUE "EXCUSE USE THE MOST TIMES =".
05 DTMU-HIGH PIC ZZZ9.
******************************************************************
* This is where we hard code the excuses used with the table *
* from the input file. *
******************************************************************
01 TABLE-EXCUSES-1.
05 PIC X(51)
VALUE "JOHN CONVINCE ME TO CONVERT TO LINUX".
05 PIC X(51)
VALUE "BEACUSE OF SECURITY REASON I CAN'T CONFIRM NOR DENY".
05 PIC X(51)
VALUE "BECAUSE THE HOSPITAL DOESN'T HAVE WIFI'".
05 PIC X(51)
VALUE "AFTER INSTALLING LINUX MY SYSTEM CRASHED".
05 PIC X(51)
VALUE "WHAT WAS THE QUESTION AGAIN".
05 PIC X(51)
VALUE "ARE YOU SURE, I REMEBER TURNING IT IN".
05 PIC X(51)
VALUE "I'M INVOKING MY 5TH AMENDMENT RIGHT".
05 PIC X(51)
VALUE "LINUX MADE ME CRAZY I THREW MY COMPUTER".
05 PIC X(51)
VALUE "SOMEONE STOLED MY BACKPACK".
05 PIC X(51)
VALUE "BEACUSE OF SECURITY REASON I CAN'T CONFIRM NOR DENY".
01 TABLE-EXCUSES-2 REDEFINES TABLE-EXCUSES-1.
05 TEN-EXCUSES OCCURS 10 TIMES PIC X(51).
01 TABLE-EXCUSES-COUNTER.
05 TABLE-EXCUSES-COUNT OCCURS 10 TIMES PIC 9(03).
PROCEDURE DIVISION.
******************************************************************
* Finally - where the real work gets done *
* it is divided into paragraphs (or modules) generally called *
* from the main controlling module (here 1000-MAIN-CONTROL). *
* 1000-Main be the control module, *
* 2000-Initialize *
* 3000-Process *
* 4000-Finish *
******************************************************************
1000-MAIN.
OPEN INPUT INPUT-FILE
OUTPUT REPORT-FILE, ERROR-FILE
PERFORM 2000-INITIALIZE
PERFORM UNTIL AT-WS-END-OF-FILE
READ INPUT-FILE
AT END MOVE "Y" TO WS-END-OF-FILE
NOT AT END PERFORM 3000-PROCESS
END-READ
END-PERFORM
PERFORM 4000-FINISH
VARYING WS-EXCUSE
FROM 1 BY 1
UNTIL WS-EXCUSE > 10
MOVE WS-MOST-USED-EXCUSE TO DTMU-HIGH
MOVE WS-EXCUSE-TOTAL TO DT-TOTAL
WRITE REPORT-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM DETAIL-TOTAL
WRITE REPORT-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM DETAIL-TOTAL-MOST-USED.
CLOSE INPUT-FILE REPORT-FILE ERROR-FILE
STOP RUN.
2000-INITIALIZE.
INITIALIZE WS-EXCUSE
INITIALIZE TABLE-EXCUSES-COUNTER
WRITE ERROR-RECORD FROM HEADING-LINE-2
WRITE ERROR-RECORD FROM BLANK-LINE
WRITE REPORT-RECORD FROM HEADING-LINE-1
WRITE REPORT-RECORD FROM BLANK-LINE.
3000-PROCESS.
MOVE "N" TO WS-INVALID-RECORD
ADD 1 TO WS-LINE-NUMBER
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF.
IF WS-INVALID-RECORD = "N"
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER IS NUMERIC
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF.
IF WS-INVALID-RECORD = "Y"
WRITE ERROR-RECORD FROM DETAIL-LINE-ERROR-1
WRITE ERROR-RECORD FROM DETAIL-LINE-ERROR-2
MOVE SPACES TO DETAIL-LINE-ERROR-1
MOVE SPACES TO DETAIL-LINE-ERROR-2
END-IF.
4000-FINISH.
MOVE WS-EXCUSE TO DL-EXCUSE-NUMBER
MOVE TEN-EXCUSES(WS-EXCUSE) TO DL-EXCUSE-USED
MOVE TABLE-EXCUSES-COUNT(WS-EXCUSE) TO DL-AMOUNT-USED
WRITE REPORT-RECORD FROM DETAIL-LINE
WRITE REPORT-RECORD FROM BLANK-LINE
MOVE SPACES TO DETAIL-LINE.
My output is as follow then follow by what it should be.
RECORD IMAGE
3 0r4000700 03
**
12 125999999 12
**
21 125000899 21
**
23 A01001111 23
**
Should be:
RECORD IMAGE
3 0r4000700 03
**
6 074000Q00 06
**
12 125999999 12
**
21 125000899 21
**
23 A01001111 23
**
You have two problems which is causing record number three to not appear with the correct error and record number six not to appear as an error at all.
I've indented your code to allow you to better see what is going on.
As usual, the compiler doesn't care, doesn't take note of indentation, so it is for humans. So do it. Indent. Often you'll see some of your own errors just by doing that.
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
IF WS-INVALID-RECORD = "N"
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER IS NUMERIC
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF
If we take record three first.
Your range-test on the 88 (good to use 88s, do it more) is this, in hexadecimal:
X'3031' through X'3130'.
This will work if the field is already known to be NUMERIC, but otherwise, since numbers appear before letters in ASCII, a whole slew of stuff you don't want gets treated as "valid". The value of 12 are rejected because they are large than 10 (X'3130'). Any letter, preceded by a zero, will be treated as valid, as will any control-code or any remaining value that happens to fit in the huge range of non-numeric values.
As Bruce Martin indicated, you need to know that the field is NUMERIC before applying that test.
IF EXCUSE-NUMBER NUMERIC
AND NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
That's become a little difficult for humans to read (the compiler doesn't mind). Bruce's suggestion for simplification (positive checks and CONTINUE with ELSE to catch the bad data) is a good one:
IF ( EXCUSE-NUMBER NUMERIC )
AND ( VALID-EXCUSE )
[all the good data goes here]
CONTINUE
ELSE
[leaving all the bad data here, ie both not numeric and
numeric but not in range]
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
Note: You need the NUMERIC-plus-range when you are validating data. Once good data is in your system, range-checks will work "as expected" as there will be no intervening non-numeric data to spoil the plot.
You also get to do both types errors for EXCUSE-NUMBER at once, simplifying the following IF.
If you can have a leading blank in either field, you need to deal with that before any checking. You don't need to use INSPECT.
With a two-byte field just REDEFINES so you can give the entire field as alpha-numeric a name, and first byte a name. Put 88s on those with a value of space. If the 88 is true, set that to zero (whole field, or byte, two tests):
IF 88-level
MOVE ZERO TO name-you've-given
END-IF
So far, record three has been treated as valid. Now it gets into your nested-IF. It EXCUSE-NUMBER is not NUMERIC, so hits the ELSE, where you have coding for the second field, . Because you didn't indent, this was obscured.
Record three has been rejected "by accident".
In the nested-IF, you meant to check NUMBER-TIMES-USED for NUMERIC.
Which explains why record six does not appear as an error, because it's only fault is NUMBER-TIMES-USED not being NUMERIC, which your program currently doesn't notice.
You've also erroneously added EXCUSE-NUMBER instead of NUMBER-TIMES-USED.
IF WS-INVALID-RECORD = "N"
[stuff for leading space]
IF NUMBER-TIMES-USED IS NUMERIC
ADD NUMBER-TIMES-USED TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
IF TABLE-EXCUSES-COUNT(EXCUSE-NUMBER) >
WS-MOST-USED-EXCUSE
MOVE TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
TO WS-MOST-USED-EXCUSE
END-IF
ADD NUMBER-TIMES-USED TO WS-EXCUSE-TOTAL
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
END-IF
END-IF
Be aware that the size of TABLE-EXCUSES-COUNT is greater than the size of WS-MOST-USED-EXCUSE. If you keep it like that, you will get unexpected behaviour when you have more than 99 of the same type of excuse.
Your nested-IF is a bit tortuous, and you have some repetition. Here's some simplification:
IF ( EXCUSE-NUMBER NUMERIC )
AND ( VALID-EXCUSE )
PERFORM CHECK-NUMBER-TIMES-USED
ELSE
PERFORM SET-STANDARD-REJECTION
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
...
CHECK-NUMBER-TIMES-USED.
IF 88-level-first-byte-space
MOVE ZERO TO name-you've-given-the-first-byte
END-IF
IF 88-level-field-space
MOVE ZERO TO field
END-IF
IF NUMBER-TIMES-USED IS NUMERIC
ADD NUMBER-TIMES-USED TO TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
WS-EXCUSE-TOTAL
PERFORM CHECK-HIGHEST-EXCUSE-COUNT
ELSE
PERFORM SET-STANDARD-REJECTION
MOVE ALL "*" TO DLE-EXCUSE
END-IF
SET-STANDARD-REJECTION.
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
.
CHECK-HIGHEST-EXCUSE-COUNT.
IF TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
GREATER THAN WS-COUNT-OF-MOST-USED
MOVE TABLE-EXCUSES-COUNT ( EXCUSE-NUMBER )
TO WS-COUNT-OF-MOST-USED
MOVE EXCUSE-NUMBER TO WS-EXCUSE
END-IF
.
There's at least one more simplification when you get to the totals, but see how that goes.
VALID-EXCUSE may well be implemented as
EXCUSE-NUMBER >= '01' and EXCUSE-NUMBER < '12'
So in procedure 3000-PROCESS, I would try replacing
IF NOT VALID-EXCUSE
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF.
with
INSPECT EXCUSE-NUMBER REPLACING LEADING SPACES BY ZERO
IF EXCUSE-NUMBER is numeric
and VALID-EXCUSE
continue
else
MOVE INPUT-RECORD TO DLE-ERROR
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE "Y" TO WS-INVALID-RECORD
MOVE ALL "*" TO DLE-EXCUSE-NUMBER
END-IF
if not NUMBER-TIMES-USED is numeric
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
end-if
also remove the following:
ELSE
MOVE "Y" TO WS-INVALID-RECORD
MOVE WS-LINE-NUMBER TO DLE-LINE-NUMBER
MOVE INPUT-RECORD TO DLE-ERROR
MOVE ALL "*" TO DLE-EXCUSE
This code is in completely the wrong place.
There are other errors e.g.
ADD EXCUSE-NUMBER TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
should probably be
ADD 1 TO TABLE-EXCUSES-COUNT(EXCUSE-NUMBER)
I seem to have yet another problem dealing with COBOL. My teacher has assigned us with having to take a file of names and make it into two columns going 54 rows down. I thought this was going to be simple as I looked in the book as it was more or less using a new function to do what I had all ready been doing, but once I got home and put down my code it all went to heck. Th program I made, for some reason unknown to me, only writes one name in the first column of row one and the does the same ever 54 rows. I am obviously on the wrong track but in my mind it looks right. Here is what I got:
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 REPORT-START PIC X VALUE 'Y'.
01 LINE-COUNT PIC 99 VALUE ZEROS.
01 PAGE-NUMBER PIC 99 VALUE ZEROS.
01 NAME-COUNT PIC 9(3) VALUE ZEROS.
01 WORK-AREA-1.
05 N-COLUMN-1 PIC 99 VALUE ZEROS.
01 WORK-AREA-2.
05 N-COLUMN-2 PIC 9(3) VALUE 54.
01 NAME-STORAGE.
05 NAME-STO OCCURS 108 TIMES PIC X(30).
01 WS-DATE.
05 RUN-YEAR PIC XX.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(32) VALUE SPACES.
05 PIC X(16)
VALUE 'NAME LIST REPORT'.
05 PIC X(6) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-2 PIC XX.
10 PIC X VALUE '/'.
10 DAY-2 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-2 PIC XX.
05 PIC X(4) VALUE SPACES.
05 PAGE-1 PIC X(4) VALUE 'PAGE'.
05 PIC X(1) VALUE SPACES.
05 NUMBER-PAGE PIC Z9.
01 DETAIL-LINE.
05 BLANK-A-OUT PIC X(4) VALUE SPACES.
05 DL-COLUMN-1 PIC X(30).
05 BLANK-E-OUT PIC X(20) VALUE SPACES.
05 DL-COLUMN-2 PIC X(30).
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT NAMELIST-FILE-IN
OPEN OUTPUT NAMELIST-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2
PERFORM 200-NEXT-PAGE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ NAMELIST-FILE-IN
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-STORE-NAME
END-READ
END-PERFORM
CLOSE NAMELIST-FILE-IN
CLOSE NAMELIST-FILE-OUT
STOP RUN.
200-NEXT-PAGE.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO NUMBER-PAGE
MOVE HEADING-LINE-1 TO NAMELIST-RECORD-OUT
IF REPORT-START = 'N'
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING PAGE
ELSE
MOVE 'N' TO REPORT-START
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING 1 LINE
END-IF.
MOVE ZEROS TO LINE-COUNT.
300-STORE-NAME.
ADD 1 TO NAME-COUNT
MOVE NAME-IN TO NAME-STORAGE
IF NAME-COUNT > 54
PERFORM 400-PROCESS-FILE
END-IF.
400-PROCESS-FILE.
IF LINE-COUNT >= 52
PERFORM 200-NEXT-PAGE
END-IF
ADD 1 TO LINE-COUNT
ADD 1 TO N-COLUMN-1
ADD 1 TO N-COLUMN-2
MOVE NAME-STO (N-COLUMN-1) TO DL-COLUMN-1
MOVE NAME-STO (N-COLUMN-2) TO DL-COLUMN-2
MOVE DETAIL-LINE TO NAMELIST-RECORD-OUT
WRITE NAMELIST-RECORD-OUT
AFTER ADVANCING 1 LINE
IF N-COLUMN-2 = 108
MOVE 0 TO NAME-COUNT
MOVE 0 TO N-COLUMN-1
MOVE 54 TO N-COLUMN-2
END-IF.
This is not all I have to do, but until I figure this out I cannot continue.
I'm not familiar with this dialect of COBOL, but i thnk the problem is with:
MOVE NAME-IN TO NAME-STORAGE
I t should look like this:
MOVE NAME-IN TO NAME-STO OF NAME-STORAGE(NAME-COUNT)
Am i right am i wrong or am i just dreaming?