Informatica Cobol file with more than two 01-level groups - cobol

I am using COBOL file as source where 01 level groups are two. Following are the details.
In Output file first and last row are required and middle two rows are extra. Am I missing any setting or there is some other error.
Input data File:
2014001100450005000000001141107TD2798600000200120011201400090029+000000000024850+000000000000000+000000000000000000CATALOG SCTEST TEST 12 MAIN ST HINGHAM MA 020430000111-111-111100000000000000000000000000000000000000000000000040000000000000001 0000 00000002786354800000000000000064486448
2015001000440007123456789123456789ABCD301088+123456789+1234567891234123456789ABCDEZZ1234ABCD12341234567890ABCDEFBCD1234567890ABCDEF12341234
OutPut file:
2014,11,45,5,2014001,100450005,1,141107TD27986,14,1107T,D27986,141107,TD,279,86,000,002,12,11,2014,9,29,248.50,0.00,0.000000000,CATALOG, , , ,SC,TEST TEST , ,12 MAIN ST ,HINGHAM ,MA ,020430000,2043,0,020430,000,111-111-1111,0,0,0,0,0,0,4,0,0,0,1, ,0, ,27863548,0,6448,6448
,2014,11,45,5,2014001,100450005,1,141107TD27986,14,1107T,D27986,141107,TD,279,86,000,002,120011.20,14000900.29,0,24,24,24,24,24,850+0,0,0,00000000,0,+000000000000000,000CATALOG SCTES,,
2015,10,44,7,2015001,440007,123456789,123456789ABCD,12,34567,89ABCD,123456,78,9AB,CD,301,088,123,4567,8901,2345,6789,,,,1234567,8,9,0A,BC,DEF1234123,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2015,10,44,7,2015001,440007,123456789,123456789ABCD,12,34567,89ABCD,123456,78,9AB,CD,301,088,1234567.89,1234567.89,1234,123456789,123456789,123456789,123456789,123456789,ABCDE,Z,Z,1234ABCD,1234,1234567890ABCDEF,BCD1234567890ABCDEF,1234,1234
Desired Output:
2014,11,45,5,2014001,100450005,1,141107TD27986,14,1107T,D27986,141107,TD,279,86,000,002,12,11,2014,9,29,248.50,0.00,0.000000000,CATALOG, , , ,SC,TEST TEST , ,12 MAIN ST ,HINGHAM ,MA ,020430000,2043,0,020430,000,111-111-1111,0,0,0,0,0,0,4,0,0,0,1, ,0, ,27863548,0,6448,6448
2015,10,44,7,2015001,440007,123456789,123456789ABCD,12,34567,89ABCD,123456,78,9AB,CD,301,088,1234567.89,1234567.89,1234,123456789,123456789,123456789,123456789,123456789,ABCDE,Z,Z,1234ABCD,1234,1234567890ABCDEF,BCD1234567890ABCDEF,1234,1234
Source File:
environment division.
select SAHDR-SAADMIN assign to "fname".
data division.
file section.
fd SAHDR-SAADMIN.
01 STSHDR-RECORD.
05 SAHDR-KEY.
10 SAHDR-FISCAL-POSTING-DATE.
15 SAHDR-FISCAL-YEAR PIC 9(04).
15 SAHDR-FISCAL-MONTH PIC 9(04).
15 SAHDR-FISCAL-WEEK PIC 9(04).
15 SAHDR-FISCAL-DAY PIC 9(04).
10 SAHDR-RELATIVE-DATE
REDEFINES SAHDR-FISCAL-POSTING-DATE.
15 SAHDR-DAY-IDNT PIC 9(07).
15 SAHDR-FILLER PIC 9(09).
10 SAHDR-STORE-NUMBER PIC 9(09).
10 SAHDR-TRANSACTION-NUMBER-KEY PIC X(13).
10 SAHDR-TRANSACTION-NUMBER
REDEFINES SAHDR-TRANSACTION-NUMBER-KEY.
15 SAHDR-REGISTER-NUMBER PIC X(02).
15 SAHDR-TRANS-NUMBER PIC X(05).
15 SAHDR-TRANS-SORT PIC X(06).
10 SAHDR-MO-TRANS-NUMBER
REDEFINES SAHDR-TRANSACTION-NUMBER-KEY.
15 SAHDR-MO-ORDER-DATE PIC X(06).
15 SAHDR-MO-DEPT-CLERK PIC X(02).
15 SAHDR-MO-ORDER-BATCH PIC X(03).
15 SAHDR-MO-ORDER-SEQ-NUMBER PIC X(02).
10 SAHDR-RECORD-TYPE PIC X(03).
88 SAHDR-HEADER-RECORD VALUE '000'.
10 SAHDR-TRANS-TYPE PIC X(03).
88 SAHDR-SALE-TRANSACTION VALUE '001'.
05 SAHDR-DATA.
10 SAHDR-TRANSACTION-DATE.
15 SAHDR-CALENDAR-MONTH PIC 9(04).
15 SAHDR-CALENDAR-DAY PIC 9(04).
15 SAHDR-CALENDAR-YEAR PIC 9(04).
10 SAHDR-TRANSACTION-TIME.
15 SAHDR-REG-TRANS-HOUR PIC 9(04).
15 SAHDR-REG-TRANS-MINUTE PIC 9(04).
10 SAHDR-TOTAL-TRANS-AMOUNT PIC +9(13)V99.
10 SAHDR-CONVERSION-TRANS-AMOUNT PIC +9(13)V99.
10 SAHDR-CONVERSION-RATE PIC +9(09)V9(9).
10 SAHDR-TRANS-ORIGIN PIC X(07).
88 SAHDR-POINT-OF-SALE VALUE 'POS '.
88 SAHDR-MAILORDER VALUE 'CATALOG'.
10 SAHDR-TRANS-VOID-DURING-FLAG PIC X(01).
10 SAHDR-TRANS-POST-VOID-FLAG PIC X(01).
10 SAHDR-TRANS-ERROR-CODE PIC X(02).
88 SAHDR-NO-ERRORS VALUE '00'.
10 SAHDR-RFS-LOCATION-TYPE PIC X(02).
10 SAHDR-CUSTOMER-NAME.
15 SAHDR-CUSTOMER-FNAME PIC X(10).
15 SAHDR-CUSTOMER-LNAME PIC X(20).
10 SAHDR-CUSTOMER-ADDRESS PIC X(35).
10 SAHDR-CUSTOMER-CITY PIC X(25).
10 SAHDR-CUSTOMER-STATE PIC X(03).
10 SAHDR-CUSTOMER-ZIPCODE PIC X(09).
10 SAHDR-USA-ZIPCODE
REDEFINES SAHDR-CUSTOMER-ZIPCODE.
15 SAHDR-CUSTOMER-FIRST-FIVE PIC 9(05).
15 SAHDR-CUSTOMER-LAST-FOUR PIC 9(04).
10 SAHDR-CANADA-ZIPCODE
REDEFINES SAHDR-CUSTOMER-ZIPCODE.
15 SAHDR-CANADA-CUST-ZIP PIC X(06).
15 FILLER PIC X(03).
10 SAHDR-CUSTOMER-PHONE PIC X(12).
10 SAHDR-SALESPERSON.
15 SAHDR-CASHIER PIC 9(07).
15 SAHDR-HEADER-SALESPERSON PIC 9(07).
10 SAHDR-EMPLOYEE-SELLING-NUMBER PIC 9(09).
10 SAHDR-EMPLOYEE-PURCHASE-NUMBER PIC 9(09).
10 SAHDR-SHIPPING-RECORD-NUMBER PIC 9(09).
10 SAHDR-ADMIN-COUNTER PIC 9(04).
10 SAHDR-ITEM-COUNTER PIC 9(04).
10 SAHDR-REGTOT-COUNTER PIC 9(04).
10 SAHDR-STRTOT-COUNTER PIC 9(04).
10 SAHDR-TAXRCD-COUNTER PIC 9(04).
10 SAHDR-TENDER-COUNTER PIC 9(04).
10 SAHDR-USERID PIC X(08).
10 SAHDR-EMP-DEPT PIC 9(04).
10 SAHDR-ERROR-CODE PIC X(01).
10 SAHDR-CUSTOMER-ID PIC 9(15).
10 SAHDR-LOYALTY-ID PIC 9(15).
10 SAHDR-TRANS-TIME.
15 SAHDR-REG-TRANS-HR PIC 9(04).
15 SAHDR-REG-TRANS-MIN PIC 9(04).
01 STSADMIN-RECORD.
05 SAADMIN-KEY.
10 SAADMIN-FISCAL-POSTING-DATE.
15 SAADMIN-FISCAL-YEAR PIC 9(04).
15 SAADMIN-FISCAL-MONTH PIC 9(04).
15 SAADMIN-FISCAL-WEEK PIC 9(04).
15 SAADMIN-FISCAL-DAY PIC 9(04).
10 SAADMIN-RELATIVE-DATE
REDEFINES SAADMIN-FISCAL-POSTING-DATE.
15 SAADMIN-DAY-IDNT PIC 9(07).
15 SAADMIN-FILLER PIC 9(09).
10 SAADMIN-STORE-NUMBER PIC 9(09).
10 SAADMIN-TRANSACTION-NUMBER-KEY PIC X(13).
10 SAADMIN-TRANSACTION-NUMBER
REDEFINES SAADMIN-TRANSACTION-NUMBER-KEY.
15 SAADMIN-REGISTER-NUMBER PIC X(02).
15 SAADMIN-TRANS-NUMBER PIC X(05).
15 SAADMIN-TRANS-SORT PIC X(06).
10 SAADMIN-MO-TRANSACTION-NUMBER
REDEFINES SAADMIN-TRANSACTION-NUMBER-KEY.
15 SAADMIN-MO-ORDER-DATE PIC X(06).
15 SAADMIN-MO-DEPT-CLERK PIC X(02).
15 SAADMIN-MO-ORDER-BATCH PIC X(03).
15 SAADMIN-MO-ORDER-SEQ-NUMBER PIC X(02).
10 SAADMIN-RECORD-TYPE PIC X(03).
88 SAADMIN-ADMINISTRATIVE VALUE '301'.
10 SAADMIN-TRANSACTION-TYPE PIC X(03).
88 SAADMIN-POST-VOID VALUE '088'.
05 SAADMIN-DATA.
10 SAADMIN-AMOUNT PIC +9(07)V99.
10 SAADMIN-CONVERSION-AMOUNT PIC +9(07)V99.
10 SAADMIN-POS-EXPENSE-NUMBER PIC 9(04).
10 SAADMIN-TRANS-ID-NUMBER PIC 9(09).
10 SAADMIN-CHARGE-ACCOUNT-NUMBER REDEFINES
SAADMIN-TRANS-ID-NUMBER PIC 9(09).
10 SAADMIN-GIFT-CERTIFICATE REDEFINES
SAADMIN-TRANS-ID-NUMBER PIC 9(09).
10 SAADMIN-MDSE-CREDIT-NUMBER REDEFINES
SAADMIN-TRANS-ID-NUMBER PIC 9(09).
10 SAADMIN-COUPON-NUMBER REDEFINES
SAADMIN-TRANS-ID-NUMBER PIC 9(09).
10 SAADMIN-ORIGINAL-TRAN-NUMBER PIC X(05).
10 SAADMIN-VOID-DURING-FLAG PIC X(01).
10 SAADMIN-POST-VOID-FLAG PIC X(01).
10 SAADMIN-USERID PIC X(08).
10 SAADMIN-EMP-DEPT PIC 9(04).
10 SAADMIN-GIFT-CARD-NUMBER PIC X(16).
10 SAADMIN-TOKEN-NUMBER PIC X(19).
10 SAADMIN-TRANS-TIME.
15 SAADMIN-REG-TRANS-HR PIC 9(04).
15 SAADMIN-REG-TRANS-MIN PIC 9(04).
working-storage section.
procedure division.
stop run.

Just do not use the ports from SAADMIN-FISCAL-YEAR to the end. What I understand, the statement "01 STSADMIN-RECORD." starts a new record using the same data. So, to get your desired output, propagate the ports for the first record (01 STSHDR-RECORD) only, which is up to SAHDR-REG-TRANS-MIN

Related

How do I fix a program bypass that is not working?

I have a program that works perfectly except when reading in the SEQ file it is suppose to skip/bypass the record entirely then move on to the next one in the file. It is suppose to bypass the input file if the student has graduated (skip Graduation Status if equal to 'Y'). Bypass if Class Standing is anything other than '1' or '2'. Lastly, bypass if Major is not 'DIG', 'NES', or 'PGM'. I have a Bypass in the program under 120-CHECK-BYPASS. but it is not sorting/stopping any records from processing. How do I fix this?
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-FIRST-IN PIC X(3).
05 SOCIAL-SECURITY-NUMBER-MIDDLE-IN PIC X(2).
05 SOCIAL-SECURITY-NUMBER-LAST-IN PIC X(4).
05 STUDENT-NAME-FIRST-IN PIC X.
05 STUDENT-NAME-MIDDLE-IN PIC X.
05 STUDENT-NAME-LAST-IN PIC X(9).
05 PIC X(5).
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-GPA PIC Z.ZZ VALUE ZERO.
01 WS-GRAND-HOURS PIC 9(7) VALUE ZERO.
01 WS-GRAND-POINTS PIC 9(7) VALUE ZERO.
01 WS-GRAND-GPA PIC Z.ZZ VALUE ZERO.
01 WS-PRO-STUDENT PIC 9(2) VALUE ZERO.
01 WS-GRAND-PRO-STUDENT PIC 99V9 VALUE ZERO.
01 WS-PRO-GPA-NUM PIC 99 VALUE ZERO.
01 WS-DIG-STUDENT PIC 99 VALUE ZERO.
01 WS-DIG-GPA-NUM PIC 99 VALUE ZERO.
01 WS-GRAND-DIG-STUDENT PIC 99V9 VALUE ZERO.
01 WS-GRAND-NES-STUDENT PIC 99V9 VALUE ZERO.
01 WS-NES-STUDENT PIC 99 VALUE ZERO.
01 WS-NES-GPA-NUM PIC 99 VALUE ZERO.
01 WS-OTHER PIC 99 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-FIRST-OUT PIC X(3).
05 SSN-FDASH PIC X VALUE "-".
05 SOCIAL-SECURITY-NUMBER-MIDDLE-OUT PIC X(2).
05 SSN-MDASH PIC X VALUE "-".
05 SOCIAL-SECURITY-NUMBER-LAST-OUT PIC X(4).
05 PIC X(3) VALUE SPACES.
05 STUDENT-NAME-FIRST-OUT PIC X.
05 PIC X VALUE SPACE.
05 STUDENT-NAME-MIDDLE-OUT PIC X.
05 PIC X VALUE SPACE.
05 STUDENT-NAME-LAST-OUT PIC X(9).
05 PIC X(2) VALUE SPACES.
05 CLASS-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 ZZZ.
05 PIC X(5) VALUE SPACES.
05 POINTS-OUT PIC ZZZ.
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(6) VALUE SPACES.
05 TL-GRAND-PRO-NUM-GPA PIC X(2).
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 99.9.
05 PIC X VALUE '%'.
01 TOTALS-LINE-3A.
05 PIC X VALUE SPACE.
05 PIC X(21) VALUE 'Digital Media Major:'.
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(6) VALUE SPACES.
05 TL-GRAND-DIG-NUM-GPA PIC XX.
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 99.9.
05 PIC X VALUE '%'.
01 TOTALS-LINE-4A.
05 PIC X VALUE SPACE.
05 PIC X(24) VALUE 'Network Security Major:'.
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(6) VALUE SPACES.
05 TL-GRAND-NET-NUM-GPA PIC XX.
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.
05 PIC X VALUE '%'.
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
PERFORM 700-GRAND-TOTALS-PROGRAMMING
PERFORM 800-PRO-GPA
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 120-CHECK-BYPASS
END-READ
END-PERFORM
CLOSE STUDENTS-FILE-IN
CLOSE STUDENTS-FILE-OUT
STOP RUN.
120-CHECK-BYPASS.
IF GRADUATION-STATUS-IN NOT EQUAL TO 'Y'
AND CLASS-STANDING-IN EQUAL TO '1' OR '2'
AND MAJOR-IN IS EQUAL TO 'DIG' OR 'NES' OR 'PGM'
PERFORM 200-PROCESS-ONE-RECORD
ELSE CONTINUE
END-IF.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 57
PERFORM 300-WRITE-HEADINGS
END-IF
PERFORM 725-PRO-STUDENT-NUM
COMPUTE WS-GPA ROUNDED = CREDIT-POINTS-EARNED-IN / CREDIT-HOURS-EARNED-IN
MOVE SOCIAL-SECURITY-NUMBER-FIRST-IN TO SOCIAL-SECURITY-NUMBER-FIRST-OUT
MOVE SOCIAL-SECURITY-NUMBER-MIDDLE-IN TO SOCIAL-SECURITY-NUMBER-MIDDLE-OUT
MOVE SOCIAL-SECURITY-NUMBER-LAST-IN TO SOCIAL-SECURITY-NUMBER-LAST-OUT
MOVE STUDENT-NAME-FIRST-IN TO STUDENT-NAME-FIRST-OUT
MOVE STUDENT-NAME-MIDDLE-IN TO STUDENT-NAME-MIDDLE-OUT
MOVE STUDENT-NAME-LAST-IN TO STUDENT-NAME-LAST-OUT
MOVE CLASS-STANDING-IN TO CLASS-STANDING-OUT
PERFORM 600-YEAR-PRINT
MOVE MAJOR-IN TO MAJOR-OUT
PERFORM 500-MAJOR-PRINT
MOVE CREDIT-HOURS-EARNED-IN TO HOURS-OUT
MOVE CREDIT-POINTS-EARNED-IN TO POINTS-OUT
MOVE WS-GPA TO STUDENT-GPA-OUT
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 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-POINTS / WS-GRAND-HOURS
PERFORM 800-PRO-GPA.
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 2
MOVE 3 TO LINES-PRINTED.
400-TOTALS-ROUTINE.
IF LINES-PRINTED > 57
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 2 LINES
ADD 2 TO LINES-PRINTED.
500-MAJOR-PRINT.
EVALUATE MAJOR-OUT
WHEN = 'NES'
MOVE 'Net Security' TO MAJOR-OUT
WHEN = 'PGM'
MOVE 'Programming' TO MAJOR-OUT
WHEN = 'DIG'
MOVE 'Digital Media' TO MAJOR-OUT
WHEN OTHER
MOVE '------' TO MAJOR-OUT
END-EVALUATE.
600-YEAR-PRINT.
EVALUATE CLASS-STANDING-OUT
WHEN = '1'
MOVE 'First Yr' TO CLASS-STANDING-OUT
WHEN = '2'
MOVE 'Second Yr' TO CLASS-STANDING-OUT
WHEN OTHER
MOVE '------' TO CLASS-STANDING-OUT
END-EVALUATE.
700-GRAND-TOTALS-PROGRAMMING.
MOVE TOTALS-LINE-2A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 4 LINES
MOVE WS-PRO-STUDENT TO TL-GRAND-PRO-STUDENT
MOVE TOTALS-LINE-2B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-PRO-GPA-NUM TO TL-GRAND-PRO-NUM-GPA
MOVE TOTALS-LINE-2C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-PRO-STUDENT = (WS-PRO-GPA-NUM / WS-PRO-STUDENT) * 100
MOVE WS-GRAND-PRO-STUDENT TO TL-GRAND-PRO-GPA-PER
MOVE TOTALS-LINE-2D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE TOTALS-LINE-3A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
MOVE WS-DIG-STUDENT TO TL-GRAND-DIG-STUDENT
MOVE TOTALS-LINE-3B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-DIG-GPA-NUM TO TL-GRAND-DIG-NUM-GPA
MOVE TOTALS-LINE-3C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-DIG-STUDENT = (WS-DIG-GPA-NUM / WS-DIG-STUDENT) * 100
MOVE WS-GRAND-DIG-STUDENT TO TL-GRAND-DIG-GPA-PER
MOVE TOTALS-LINE-3D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE TOTALS-LINE-4A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
MOVE WS-NES-STUDENT TO TL-GRAND-NET-STUDENT
MOVE TOTALS-LINE-4B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-NES-GPA-NUM TO TL-GRAND-NET-NUM-GPA
MOVE TOTALS-LINE-4C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-NES-STUDENT = (WS-NES-GPA-NUM / WS-NES-STUDENT) * 100
MOVE WS-GRAND-NES-STUDENT TO TL-GRAND-NET-GPA-PER
MOVE TOTALS-LINE-4D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE.
725-PRO-STUDENT-NUM.
EVALUATE MAJOR-IN
WHEN = 'NES'
ADD 1 TO WS-NES-STUDENT
WHEN = 'PGM'
ADD 1 TO WS-PRO-STUDENT
WHEN = 'DIG'
ADD 1 TO WS-DIG-STUDENT
WHEN OTHER
MOVE 0 TO WS-OTHER
END-EVALUATE.
800-PRO-GPA.
EVALUATE MAJOR-IN ALSO STUDENT-GPA-OUT
WHEN = 'NES' ALSO > '3.0'
ADD 1 TO WS-NES-GPA-NUM
WHEN = 'PGM' ALSO > '3.0'
ADD 1 TO WS-PRO-GPA-NUM
WHEN = 'DIG' ALSO > '3.0'
ADD 1 TO WS-DIG-GPA-NUM
WHEN OTHER
MOVE 0 TO WS-OTHER
END-EVALUATE.
You are ANDing your conditions. It seems you want to OR them. Also it seems you have your logic reversed.
I would do it this way...
[...]
FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SOCIAL-SECURITY-NUMBER-FIRST-IN PIC X(3).
05 SOCIAL-SECURITY-NUMBER-MIDDLE-IN PIC X(2).
05 SOCIAL-SECURITY-NUMBER-LAST-IN PIC X(4).
05 STUDENT-NAME-FIRST-IN PIC X.
05 STUDENT-NAME-MIDDLE-IN PIC X.
05 STUDENT-NAME-LAST-IN PIC X(9).
05 PIC X(5).
05 GRADUATION-STATUS-IN PIC X.
88 STUDENT-HAS-GRADUATED VALUE 'Y'
05 CLASS-STANDING-IN PIC X.
88 CLASS-STANDING-TO-SKIP VALUES '1' '2'.
05 MAJOR-IN PIC X(3).
88 MAJOR-TO-SKIP VALUES
'DIG' 'NES' 'PGM'.
05 CREDIT-HOURS-EARNED-IN PIC 9(3).
05 CREDIT-POINTS-EARNED-IN PIC 9(3).
[...]
120-CHECK-BYPASS.
IF STUDENT-HAS-GRADUATED
OR CLASS-STANDING-TO-SKIP
OR MAJOR-TO-SKIP
CONTINUE
ELSE
PERFORM 200-PROCESS-ONE-RECORD
END-IF.
This is just freehand, I haven't tried to compile it.

When I add slashes I get numbers added to the record

01 EMPLOYEE-RECORD1.
...
05 EMPLOYEEDOB1.
10 MONTH1 PIC 99.
*> here 10 FILLER PIC X(1) VALUE "/".
10 DAY11 PIC 99.
*> here 10 FILLER PIC X(1) VALUE "/".
10 YEARS1 PIC 9(4).
*> here
05 EMPLOYEE_YEARLYPAY1 PIC ZZ,ZZZV99.
...
There is more to the program and I will provide the code if necessary. In short my program takes input from a file and then loads it into a temp record. Then I copy the data from the temp record into the record for the output file and it writes it to the output file. When it writes it I lose the pay data and it adds numbers for the DOB instead of slashes. Why? What am I doing wrong?
program-id. Program1 as "NAME403.Program1".
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPFILE
ASSIGN TO "C:\COBOLClass\DataFiles\NAME402.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEWEMPFILE
ASSIGN TO "C:\COBOLClass\DataFiles\NAME403.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
data division.
FILE SECTION.
FD EMPFILE.
01 EMPLOYEE-RECORD.
05 EMPLOYEE_ADDRESS.
10 BLDGNUMB-AND-STREET PIC X(10).
10 CITY PIC X(10).
10 STATE PIC X(10).
10 ZIPCODE PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEENUMB PIC 9(6).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEEDOB.
10 MONTH PIC 99.
10 DAY1 PIC 99.
10 YEARS PIC 9(4).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_FNAME PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_MNAME PIC X(2).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_LNAME PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_YEARLYPAY PIC ZZ,ZZZ.99.
FD NEWEMPFILE.
01 EMPLOYEE-RECORD1.
05 EMPLOYEENUMB1 PIC 9(6).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_FNAME1 PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_MNAME1 PIC X(2).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_LNAME1 PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEEDOB1.
10 MONTH1 PIC 99.
10 FILLER PIC X VALUE "/".
10 DAY11 PIC 99.
10 FILLER PIC X VALUE "/".
10 YEARS1 PIC 9(4).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_YEARLYPAY1 PIC ZZ,ZZZ.99.
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_ADDRESS1.
10 BLDGNUMB-AND-STREET1 PIC X(10).
10 CITY1 PIC X(10).
10 FILLER PIC X(10) VALUE SPACE.
10 STATE1 PIC X(10).
10 FILLER PIC X(10) VALUE SPACE.
10 ZIPCODE1 PIC X(10).
10 FILLER PIC X(166) VALUE "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------".
05 EMPLOYEE_LNAME PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_YEARLYPAY PIC ZZ,ZZZ.99.
FD NEWEMPFILE.
01 EMPLOYEE-RECORD1.
05 EMPLOYEENUMB1 PIC 9(6).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_FNAME1 PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_MNAME1 PIC X(2).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_LNAME1 PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEEDOB1.
10 MONTH1 PIC 99.
10 FILLER PIC X VALUE "/".
10 DAY11 PIC 99.
10 FILLER PIC X VALUE "/".
10 YEARS1 PIC 9(4).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_YEARLYPAY1 PIC ZZ,ZZZ.99.
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_ADDRESS1.
10 BLDGNUMB-AND-STREET1 PIC X(10).
10 CITY1 PIC X(10).
10 FILLER PIC X(10) VALUE SPACE.
10 STATE1 PIC X(10).
10 FILLER PIC X(10) VALUE SPACE.
10 ZIPCODE1 PIC X(10).
10 FILLER PIC X(166) VALUE ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------".
working-storage section.
01 EMPLOYEE-RECORD-TEMP.
05 EMPLOYEE_ADDRESS-TEMP.
10 BLDGNUMB-AND-STREET-TEMP PIC X(10).
10 CITY-TEMP PIC X(10).
10 STATE-TEMP PIC X(10).
10 ZIPCODE-TEMP PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEENUMB-TEMP PIC 9(6).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEEDOB-TEMP.
10 MONTH-TEMP PIC 99.
10 DAY1-TEMP PIC 99.
10 YEARS-TEMP PIC 9(4).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_FNAME-TEMP PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_MNAME-TEMP PIC X(2).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_LNAME-TEMP PIC X(10).
05 FILLER PIC X(10) VALUE SPACE.
05 EMPLOYEE_YEARLYPAY-TEMP PIC ZZ,ZZZ.99.
01 SWITCHES.
05 CUSTMAST-EOF-SWITCH PIC X VALUE "N".
02 COUNTER PIC 9 VALUE 1.
procedure division.
000-STARTPROGRAM.
open input EMPFILE
output NEWEMPFILE.
PERFORM 100-GET-INFROMATION
UNTIL CUSTMAST-EOF-SWITCH="Y".
display "END OF SESSION.".
stop run.
100-GET-INFROMATION.
read EMPFILE into EMPLOYEE-RECORD-TEMP
at END
MOVE EMPLOYEE_ADDRESS-TEMP TO EMPLOYEE_ADDRESS1.
MOVE BLDGNUMB-AND-STREET-TEMP TO BLDGNUMB-AND-STREET1.
MOVE CITY-TEMP TO CITY1.
MOVE STATE-TEMP TO STATE1.
MOVE ZIPCODE-TEMP TO ZIPCODE1.
MOVE EMPLOYEENUMB-TEMP TO EMPLOYEENUMB1.
MOVE MONTH-TEMP TO MONTH1.
MOVE DAY1-TEMP TO DAY11.
MOVE YEARS-TEMP TO YEARS1.
MOVE EMPLOYEE_FNAME-TEMP TO EMPLOYEE_FNAME1.
MOVE EMPLOYEE_MNAME-TEMP TO EMPLOYEE_MNAME1.
move EMPLOYEE_LNAME-TEMP TO EMPLOYEE_LNAME1.
move EMPLOYEE_YEARLYPAY-TEMP to EMPLOYEE_YEARLYPAY1.
WRITE EMPLOYEE-RECORD1.
if COUNTER=5
close EMPFILE
close NEWEMPFILE
move "Y" to CUSTMAST-EOF-SWITCH
ELSE ADD 1 to COUNTER.
The actual MOVE or READ ... INTO are missing but I assume you (directly or indirectly) move a PIC 9(06) item to EMPLOYEEDOB1 which is a different format actual a PIC X(08).
As long as the question isn't improved (by showing both the data definition and the statement for the "copy") I say the answer to "What am I doing wrong?" is: You use the wrong definition for EMPLOYEEDOB1 and/or "copy" the data in falsely.
The target field definition must either match the original data or be changed to an edited field like PIC 99/99/99 (where the / are added automatically in the DISPLAY/WRITE you do with it) - in the later case: be aware that you cannot do any arithmetic with an edited field.
Alternative: MOVE all three parts of the date-of-birth (DOB) on their own and you can keep your definition (only useful if you want to do anything with the three parts afterwards).

How to do a two dimensional table (array) and fix errors

My outputs are not getting out right, and I'm not too sure how to go about doing a two dimensional array.
I have my outputs follow by the outputs should look like.....
Good example how to set up 2 dimensional table would help, since not sure what I find on line is good plus haven't found a good enough book to explain to an old person terms.
First is my code:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO DATAIN
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OUTPUT-FILE ASSIGN TO DATAOUT
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE ASSIGN TO DATAOUT2
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
*-------------------------------------------------------------*
* INPUT FILE LAYOUT *
*-------------------------------------------------------------*
FD INPUT-FILE.
01 INPUT-RECORD.
05 IR-JOB-NUM PIC 9(02).
88 IR-JOB-NUM-VALID VALUE 01 THRU 11.
05 IR-EMP-NUM PIC 9(01).
88 IR-EMP-NUM-VALID VALUE 1 THRU 4.
05 IR-NUM-COMPLETE PIC 9(04).
05 FILLER PIC X(03).
05 FILLER PIC X(07).
*-------------------------------------------------------------*
* OUTPUT FILE *
*-------------------------------------------------------------*
FD OUTPUT-FILE.
01 OUTPUT-RECORD PIC X(80).
*-------------------------------------------------------------*
* ERROR FILE *
*-------------------------------------------------------------*
FD ERROR-FILE.
01 ERROR-RECORD PIC X(80).
*-------------------------------------------------------------*
* WORKING STORAGE SECTION *
*-------------------------------------------------------------*
WORKING-STORAGE SECTION.
01 FLAGS-AND-ACCUMALATORS.
05 END-OF-FILE PIC XXX VALUE "NO".
88 AT-END-OF-FILE VALUE "YES".
05 ERROR-FLAG PIC XXX VALUE "NO".
05 BLANK-LINE PIC X(80) VALUE SPACES.
05 LINE-NUM-IR-POSITION PIC 999 VALUE ZERO.
01 SUBSCRIPT.
05 SUB PIC 99 VALUE ZERO.
*---------------------------------------------------------------*
* REPORT STRUCTURE *
*---------------------------------------------------------------*
* ERROR HEADER RECORD *
01 ER-HEADER.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(10) VALUE SPACES.
05 FILLER PIC X(06) VALUE "RECORD".
05 FILLER PIC X(15) VALUE SPACES.
05 FILLER PIC X(05) VALUE "ABOVE".
05 FILLER PIC X(33) VALUE SPACES.
* ERROR DETAIL RECORD *
01 ER-DETAIL-LINE.
05 FILLER PIC X(06) VALUE SPACES.
05 DL-ASTERIK PIC X(01) VALUE SPACES.
05 FILLER PIC X(01) VALUE SPACES.
05 DL-LINE-NUM PIC ZZ9 VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR PIC X(16) VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR-BIG-NUM PIC ZZZ9 VALUE SPACES.
* ERROR ERROR RECORD *
01 ER-ERROR-LINE.
05 FILLER PIC X(20) VALUE SPACES.
05 EL-JOB-NUM PIC X(02) VALUE SPACES.
05 EL-EMP-NUM PIC X(01) VALUE SPACES.
05 EL-NUM-COMPLETE PIC X(03) VALUE SPACES.
05 FILLER PIC X(54) VALUE SPACES.
* OUTPUT HEADER RECORD *
01 OR-HEADER.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(08) VALUE "LOCATION".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 1 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 2 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 3 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 4 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE "TOTAL".
05 FILLER PIC X(15) VALUE SPACES.
* OUTPUT DETAIL RECORD *
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC 9(02).
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
* SUMMARY RECORD *
01 OR-SUMMARY.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(06)
VALUE "TOTALS".
05 FILLER PIC X(04) VALUE SPACES.
05 OR-TOT1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
PROCEDURE DIVISION.
*****************************************************************
*0000-MAIN-PROCEDURE *
*****************************************************************
0000-MAIN-PROCEDURE SECTION.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE
ERROR-FILE.
PERFORM 1000-INITIALIZE.
PERFORM UNTIL AT-END-OF-FILE
READ INPUT-FILE
AT END
MOVE 'YES' TO END-OF-FILE
NOT AT END
PERFORM 2000-PROCESS
END-READ
END-PERFORM.
PERFORM VARYING SUB FROM 1 BY 1 UNTIL SUB > 11
PERFORM 3000-FINALIZE
END-PERFORM.
PERFORM 4000-SUMMARY.
CLOSE INPUT-FILE
OUTPUT-FILE
ERROR-FILE.
GOBACK.
0000-EXIT.
EXIT.
/
*****************************************************************
*1000-INITIALIZE *
*****************************************************************
*PURPOSE: INITIALIZE ALL THE VARIABLES AND *
* WRITE THE HEADER RECORDS TO THE OUTPUT FILES. *
*****************************************************************
1000-INITIALIZE SECTION.
WRITE ERROR-RECORD FROM ER-HEADER.
WRITE ERROR-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-HEADER.
WRITE OUTPUT-RECORD FROM BLANK-LINE.
1000-EXIT.
EXIT.
/
2000-PROCESS SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE 'NO' TO ERROR-FLAG.
ADD 1 TO LINE-NUM-IR-POSITION.
IF NOT IR-JOB-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-JOB-NUM
END-IF.
IF NOT IR-EMP-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-EMP-NUM
END-IF.
IF ERROR-FLAG = 'NO'
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
IF IR-NUM-COMPLETE IS NUMERIC
MOVE IR-JOB-NUM TO SUB
IF IR-EMP-NUM = 1
ADD IR-NUM-COMPLETE TO
OR-EMP1-AMT(SUB)
END-IF
IF IR-EMP-NUM = 2
ADD IR-NUM-COMPLETE TO
OR-EMP2-AMT(SUB)
END-IF
IF IR-EMP-NUM = 3
ADD IR-NUM-COMPLETE TO
OR-EMP3-AMT(SUB)
END-IF
IF IR-EMP-NUM = 4
ADD IR-NUM-COMPLETE TO
OR-EMP4-AMT(SUB)
END-IF
ELSE
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-NUM-COMPLETE
END-IF.
IF ERROR-FLAG = 'YES'
IF IR-NUM-COMPLETE > 50
MOVE ALL '*' TO DL-ASTERIK
MOVE IR-NUM-COMPLETE TO DL-ERROR-BIG-NUM
END-IF
WRITE ERROR-RECORD FROM ER-DETAIL-LINE
WRITE ERROR-RECORD FROM ER-ERROR-LINE
MOVE SPACES TO ER-DETAIL-LINE
MOVE SPACES TO ER-ERROR-LINE
END-IF.
2000-EXIT.
EXIT.
/
3000-FINALIZE SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE SUB TO OR-JOB-NUM(SUB).
ADD OR-EMP1-AMT(SUB)
OR-EMP2-AMT(SUB)
OR-EMP3-AMT(SUB)
TO OR-EMP4-AMT(SUB)
GIVING OR-JOB-TOT(SUB).
ADD OR-EMP1-AMT(SUB) TO OR-TOT1-AMT.
ADD OR-EMP2-AMT(SUB) TO OR-TOT2-AMT.
ADD OR-EMP3-AMT(SUB) TO OR-TOT3-AMT.
ADD OR-EMP4-AMT(SUB) TO OR-TOT4-AMT.
ADD OR-JOB-TOT(SUB) TO OR-TOT-TOT.
IF OR-JOB-TOT(SUB) > 0
WRITE OUTPUT-RECORD FROM OR-DETAIL(SUB)
WRITE OUTPUT-RECORD FROM BLANK-LINE
END-IF.
3000-EXIT.
EXIT.
/
4000-SUMMARY SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
WRITE OUTPUT-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-SUMMARY.
4000-EXIT.
EXIT.
My output in the Exception report is:
NO. RECORD ABOVE
3 0r4000700 03
**
6 074000Q00 06
***
* 7 075075000 07 750
*
* 8 06105 100 08 5 1
***
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
21 125000899 21
***
23 A01001111 23
**
But should be:
ERROR REPORT
NO. CONTENTS ABOVE
2 032 200 02
****
3 0r4000700 03
**
5 073 73000 05
****
6 074000Q00 06
****
* 7 075075000 07 750
*
8 06105 100 08
****
9 011 52000 09
****
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
* 20 091010000 20 100
21 125000899 21
***
23 A01001111 23
**
And my output for summary is:
NO. LOCATION 1 2 3 4 TOTAL
01 XXXXXXXX 00520 00000 00000 00000 00520
03 XXXXXXXX 00000 00002 00000 00007 00009
04 XXXXXXXX 00010 00010 00003 00000 00023
05 XXXXXXXX 00000 00012 00000 00004 00016
06 XXXXXXXX 00000 00000 00000 00004 00004
07 XXXXXXXX 00000 00000 00730 00000 00730
08 XXXXXXXX 00006 00000 00000 00004 00010
09 XXXXXXXX 00100 00000 00000 00000 00100
TOTALS 00636 00024 00733 00019 01412
And should look like this:
SUMMARY REPORT
NO. LOCATION 1 2 3 4 TOTAL
1 PETERS, FL 0 0 0 0 0
2 ATCHISON, KS 0 0 0 0 0
3 KANSAS CITY, MO 0 0 0 7 7
4 DENVER, CO 10 10 3 0 23
5 SAN JOSE, CA 0 12 0 4 16
6 REDMOND, WA 0 0 0 4 4
7 HOUSTON, TX 0 0 0 0 0
8 TOPEKA, KS 6 0 0 4 10
9 WICHITA, KS 100 0 0 0 100
10 JEFFERSON CITY, MO 0 0 0 0 0
11 ST. LOUIS MO 0 0 0 0 0
TOTALS 116 22 3 19 160
For Multi dimensional arrays in Cobol, just nest the occurs clause:
01 WS-DETAIL-totals OCCURS 11 TIMES.
05 WS-JOB-NUM PIC 9(02).
05 WS-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 WS-EMP-AMT occurs 4 PIC s9(05) COMP VALUE ZEROES.
05 WS-JOB-TOT PIC s9(05) COMP VALUE ZEROES.
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC z9.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 Filler occurs 4.
10 OR-EMP1-AMT PIC ----9.
10 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC ----9 VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
You should also accumulate in comp fields (like in ws table above) and move to output table.
The
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
statement in 2000- means errors like the following are not caught
2 032 200 02
****

How to skip a record in COBOL with an if statement

FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SSN-IN PIC X(9).
05 STUDENT-NAME-IN PIC X(11).
05 PIC X(5).
05 GRAD-STATUS-IN PIC X.
05 CLASS-STANDING-IN PIC X.
05 MAJOR-IN PIC X(3).
05 CREDIT-HOURS-IN PIC 9(3).
05 CREDIT-POINTS-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 PAGE-NUMBER PIC 99 VALUE ZERO.
01 LINE-COUNT PIC 99 VALUE ZERO.
01 SSID-BREAK.
03 FIRST-PART PIC X(3).
03 SECOND-PART PIC X(2).
03 THIRD-PART PIC X(4).
01 NAME-BREAK.
03 FIRST-LETTER PIC X(1).
03 MIDDLE-LETTER PIC X(1).
03 LAST-LETTER PIC X(10).
01 GRAD-CHECK PIC X.
01 WS-DATE.
05 RUN-YEAR PIC XX.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
01 HEADING-LINE-ONE.
05 PIC X(21) VALUE SPACES.
05 PIC X(33)
VALUE 'RHODES STATE COLLEGE GRADE REPORT'.
05 PIC X(6) VALUE SPACES.
05 HEADING-LINE-DATE.
10 MONTH-NOW PIC XX.
10 PIC X VALUE '/'.
10 DAY-NOW PIC XX.
10 PIC X VALUE '/'.
10 YEAR-NOW PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(4) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9 VALUE ZEROS.
01 HEADING-LINE-TWO.
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 DL-SSID.
10 SSID-1 PIC X(3).
10 PIC X VALUE "-".
10 SSID-2 PIC X(2).
10 PIC X VALUE "-".
10 SSID-3 PIC X(4).
05 BLANK-B PIC X(3) VALUE SPACES.
05 DL-NAME .
10 FIRST-INI PIC X.
10 PIC X VALUE SPACES.
10 MID-INI PIC X.
10 PIC X VALUE SPACES.
10 LAST-NAME PIC X(10).
05 BLANK-C PIC X(3) VALUE SPACES.
05 YEAR-STATUS PIC X(9).
05 BLANK-D PIC X(3) VALUE SPACES.
05 STUDENT-MAJOR PIC X(13).
05 BLANK-E PIC X(5) VALUE SPACES.
05 STUDNET-HOURS PIC ZZ9.
05 BLANK-F PIC X(5) VALUE SPACES.
05 STUDENT-POINTS PIC ZZ9.
05 BLANK-G PIC X(4) VALUE SPACES.
05 STUDENT-GPA PIC 9V99.
01 TOTALS-LINE.
05 TOTALS PIC X(6) VALUE 'TOTALS'.
05 PIC X(34) VALUE SPACES.
05 HITS-TOTAL PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 BATS-TOTAL PIC ZZZ,ZZZ.
05 PIC X(10) VALUE SPACES.
05 AVG-TOTAL PIC .999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT STUDENTS-FILE-IN
OPEN OUTPUT STUDENTS-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-NOW
MOVE RUN-DAY TO DAY-NOW
MOVE RUN-YEAR TO YEAR-NOW
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ STUDENTS-FILE-IN
AT END
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 LINE-COUNT >= 53
PERFORM 300-WRITE-HEADINGS
END-IF
* IF GRAD-STATUS-IN NOT = '1' AND NOT = '2'
* PERFORM 400-WRITE-TOTALS.
* END-IF
MOVE SSN-IN TO SSID-BREAK
MOVE FIRST-PART TO SSID-1
MOVE SECOND-PART TO SSID-2
MOVE THIRD-PART TO SSID-3
MOVE STUDENT-NAME-IN TO NAME-BREAK
MOVE FIRST-LETTER TO FIRST-INI
MOVE MIDDLE-LETTER TO MID-INI
MOVE LAST-LETTER TO LAST-NAME
MOVE GRAD-STATUS-IN TO GRAD-CHECK
IF GRAD-CHECK = 'Y'
END-IF
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINES
ADD 1 TO LINE-COUNT.
The input file looks like this
307662099KRAlexander Y2NES005017
Basically certain files won't meet the requirements and we are just suppose to just skip over them. This is an example of the file that we don't want to write to the output file and skip over. I apologize if I explained this poorly but I am really struggling with COBOL.
Your 200- paragraph needs to do something like this:
IF NOT ( <condition-for-skipping )
PERFORM PROCESS-THIS-RECORD
ELSE
PERFORM IGNORE-THIS-RECORD
END-IF
You can swap the conditions easily
IF ( <condition-for-skipping )
PERFORM IGNORE-THIS-RECORD
ELSE
PERFORM PROCESS-THIS-RECORD
END-IF
All the stuff you have in the 200- paragraph currently, you put in to a new paragrpah PROCESS-THIS-RECORD. You should have a new paragraph IGNORE-THIS-RECORD. If nothing else, it can count the records which are ignored. Then if you count the records which are processed, and count the input records, at the end you can check that everything is either processed or ignored.
You should check file-statuses. It is good to use scope-delimiters (like the END-IF) and keep full-stops/periods to a minimum.
88s are good to use for conditions. Saves lots of literals hanging about to make maintenance more complex.

Date Checking (COBOL)

As part of an assignment I need to create a "shipping" program that checks a certain field which tells the date an item is to be shipped. Any record with a date greater than 6 months away is to be omitted while sorting the rest of the data.
The problem is no matter what I try I get bad results. I figured an EVALUATE statement would be the best route to go, but I just can't seem to get it right. This is what I have down:
DATA DIVISION.
FILE SECTION.
COPY ORDERS-FILE-NEW-IN.COP.
FD ORDERS-FILE-NEW-IN.
01 ORDERS-RECORD-NEW-IN.
05 PART-NUMBER-N-IN PIC X(8).
05 QUANTITY-N-IN PIC 9(4).
05 REQUEST-DATE-N-IN.
10 REQUEST-YEAR-N-IN PIC X(4).
10 REQUEST-MONTH-N-IN PIC XX.
10 REQUEST-DAY-N-IN PIC XX.
05 CUST-NUMBER-N-IN PIC X(5).
05 CUST-ORDER-NUMBER-N-IN PIC X(10).
05 STOCK-AVAILABLE-N-IN PIC X.
COPY ORDERS-FILE-PRIOR-IN.COP.
FD ORDERS-FILE-PRIOR-IN.
01 ORDERS-RECORD-PRIOR-IN.
05 PART-NUMBER-P-IN PIC X(8).
05 QUANTITY-P-IN PIC 9(4).
05 REQUEST-DATE-P-IN.
10 REQUEST-YEAR-P-IN PIC X(4).
10 REQUEST-MONTH-P-IN PIC XX.
10 REQUEST-DAY-P-IN PIC XX.
05 CUST-NUMBER-P-IN PIC X(5).
05 CUST-ORDER-NUMBER-P-IN PIC X(10).
05 STOCK-AVAILABLE-P-IN PIC X.
COPY ORDERS-FILE-SORT.COP.
SD ORDERS-FILE-SORT.
01 ORDERS-RECORD-SORT.
05 PART-NUMBER-S PIC X(8).
05 QUANTITY-S PIC 9(4).
05 REQUEST-DATE-S.
10 REQUEST-YEAR-S PIC X(4).
10 REQUEST-MONTH-S PIC XX.
10 REQUEST-DAY-S PIC XX.
05 CUST-NUMBER-S PIC X(5).
05 CUST-ORDER-NUMBER-S PIC X(10).
05 STOCK-AVAILABLE-S PIC X.
FD ORDERS-FILE-OUT.
01 ORDERS-RECORD-OUT PIC X(80).
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 LINE-JUMP PIC X VALUE 'Y'.
01 PAGE-NUMBER PIC 99 VALUE ZEROS.
01 MONTH-TOTAL PIC 99 VALUE ZEROS.
01 YEAR-TOTAL PIC 99 VALUE ZEROS.
01 YEAR-CHECK PIC 99 VALUE ZEROS.
01 SPACE-LINE PIC X VALUE SPACE.
01 WS-DATE.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
05 RUN-YEAR PIC XX.
01 HEADING-LINE-1.
05 PIC X(15) VALUE SPACES.
05 PIC X(43)
VALUE 'OPEN ORDERS REPORT - NEXT SIX MONTHS'.
05 HL-1-DATE.
10 MONTH-1 PIC 99.
10 PIC X VALUE '/'.
10 DAY-1 PIC 99.
10 PIC X VALUE '/'.
10 YEAR-1 PIC 99.
05 PIC X(3) VALUE SPACES.
05 PAGE-1 PIC X(5) VALUE 'PAGE'.
05 NUMBER-PAGE PIC Z9.
01 HEADING-LINE-2.
05 PIC X(14)
VALUE 'REQUEST DATE'.
05 PIC X(12)
VALUE 'CUSTOMER #'.
05 PIC X(16)
VALUE 'CUSTOMER ORD #'.
05 PIC X(10)
VALUE 'PART #'.
05 PIC X(11)
VALUE 'QUANTITY'.
05 PIC X(8)
VALUE 'AVAIL'.
05 PIC X(5)
VALUE 'SHIP?'.
01 DETAIL-LINE.
05 REQUEST-DATE.
10 REQUEST-MONTH PIC XX.
10 PIC X VALUE '/'.
10 REQUEST-DAY PIC XX.
10 PIC X VALUE '/'.
10 REQUEST-YEAR PIC X(4).
05 PIC X(4) VALUE SPACES.
05 CUST-NUMBER PIC X(5).
05 PIC X(7) VALUE SPACES.
05 CUST-ORDER-NUMBER PIC X(10).
05 PIC X(6) VALUE SPACES.
05 PART-NUMBER PIC X(8).
05 PIC X(5) VALUE SPACES.
05 QUANTITY PIC Z,ZZZ.
05 PIC X(3) VALUE SPACES.
05 STOCK-AVAILABLE PIC X(3).
05 PIC X(5) VALUE SPACES.
05 SHIP-MESSAGE PIC X(4).
PROCEDURE DIVISION.
100-MAIN.
SORT ORDERS-FILE-SORT
ON ASCENDING KEY REQUEST-DATE-S
ON ASCENDING KEY CUST-NUMBER-S
ON ASCENDING KEY CUST-ORDER-NUMBER-S
ON ASCENDING KEY PART-NUMBER-S
INPUT PROCEDURE 200-SORT-SELECTION
OUTPUT PROCEDURE 300-FILE-START
STOP RUN.
200-SORT-SELECTION.
OPEN INPUT ORDERS-FILE-NEW-IN
ORDERS-FILE-PRIOR-IN
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-1
MOVE RUN-DAY TO DAY-1
MOVE RUN-YEAR TO YEAR-1
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ ORDERS-FILE-PRIOR-IN
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 210-SORT-ADD-PRIOR
END-READ
END-PERFORM
MOVE 'YES' TO ARE-THERE-MORE-RECORDS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ ORDERS-FILE-NEW-IN
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 220-SORT-ADD-NEW
END-READ
END-PERFORM
MOVE 'YES' TO ARE-THERE-MORE-RECORDS
CLOSE ORDERS-FILE-NEW-IN
ORDERS-FILE-PRIOR-IN.
210-SORT-ADD-PRIOR.
MOVE ORDERS-RECORD-PRIOR-IN TO ORDERS-RECORD-SORT
MOVE MONTH-1 TO MONTH-TOTAL
MOVE YEAR-1 TO YEAR-TOTAL
MOVE REQUEST-YEAR-P-IN TO YEAR-CHECK
ADD 6 TO MONTH-TOTAL
IF MONTH-TOTAL > 12
SUBTRACT 12 FROM MONTH-TOTAL
END-IF
EVALUATE REQUEST-MONTH-P-IN
WHEN 01 IF MONTH-TOTAL = 1 OR
(MONTH-TOTAL > 6 AND < 13)
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 02 IF (MONTH-TOTAL = 1 OR 2) OR
(MONTH-TOTAL > 7 AND < 13)
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 03 IF (MONTH-TOTAL > 0 AND < 4) OR
(MONTH-TOTAL > 8 AND < 13)
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 04 IF (MONTH-TOTAL > 0 AND < 5) OR
(MONTH-TOTAL > 9 AND < 13)
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 05 IF (MONTH-TOTAL > 0 AND < 6) OR
(MONTH-TOTAL = 11 OR 12)
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 06 IF (MONTH-TOTAL > 0 AND < 7) OR
MONTH-TOTAL = 12
IF YEAR-CHECK - YEAR-1 = 0 OR 1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 07 IF MONTH-TOTAL > 1 AND < 8
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 08 IF MONTH-TOTAL > 2 AND < 9
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 09 IF MONTH-TOTAL > 3 AND < 10
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 10 IF MONTH-TOTAL > 4 AND < 11
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 11 IF MONTH-TOTAL > 5 AND < 12
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
WHEN 12 IF MONTH-TOTAL > 6 AND < 13
IF YEAR-CHECK = YEAR-1
RELEASE ORDERS-RECORD-SORT
END-IF
END-IF
END-EVALUATE.
One of the first things you should learn as a programmer, COBOL or otherwise, is to nail down what your requirements really are. Your assignment is asking to compare two dates and perform certain actions if one is 6 months or less after another. Exactly what is the meaning of 6 months? Would it be: 183 days; would it be the month number plus 6, in such case, the dates 2011-01-31 and 2011-07-01 would be 6 months apart – but 33 days short of the 183 day alternative definition; other definitions are possible too. Dates, and date arithmetic in particular, can be confusing.
Next, beware of varying date formats: YYMMDD; YYYYMMDD; MMDDYYYY; DDMMYYYY and may more. The ACCEPT WS-DATE FROM DATE statement could be giving you a date format different from the one you are expecting (compile time options and/ or compiler installation defaults may affect the format). It is generally better form to request an explicit date format as in ACCEPT WS-YYYYMMDD FROM DATE YYYYMMDD. One of the problems in your program is related to this. You are mixing up 2 and 4 digit years, as in:
MOVE REQUEST-YEAR-P-IN TO YEAR-CHECK
Moves a 4 digit year to a two digit year. What do you suppose got truncated there? That in turn messes up your entire EVALUATE statement (which I recommend not using the way you have in this program).
Next I think you would be better off taking advantage of the way dates are presented to you in the input file. They are in YYYYMMDD format. All you need to do is calculate a date a date 6 months into the future from the current date and compare it directly to the date from the input file. If the input date is numerically less than the calculated date, keep the record.
Try something like:
10 WS-YYYYMMDD.
15 WS-YYYY PIC 9(4).
15 WS-MM PIC 9(2).
15 WS-DD PIC 9(2).
100-MAIN.
*
* Calculate a reference date 6 months into the future.
*
ACCEPT WS-YYYYMMDD FROM DATE YYYYMMDD
COMPUTE WS-MM = WS-MM + 6 END-COMPUTE
IF WS-MM > 12
COMPUTE WS-MM = WS-MM - 12 END-COMPUTE
COMPUTE WS-YYYY = WS-YYYY + 1 END-COMPUTE
END-IF
....
210-SORT-ADD-PRIOR.
IF REQUEST-DATE-P-IN < WS-YYYYMMDD
MOVE ORDERS-RECORD-PRIOR-IN TO ORDERS-RECORD-SORT
RELEASE ORDERS-RECORD-SORT
END-IF
.
Or something along these lines... but get rid of that huge EVALUATE.
If you want to know if a date is 6 months ahead I think it's easier to calculate just months
Compare
Year-today * 12 + month-Today + 6
With
Year-Shipping * 12 + month-Shipping
and you are done.
I can only assume this is too late to help with the homework, but compares of future dates may be easier with the intrinsic FUNCTION INTEGER-OF-DATE. You simply need integer compares after that. Assuming the dates are within the range of 16010101 and 99991231 you should be good to go (Gregorian).
IF MONTH-TOTAL > 12
SUBTRACT 12 FROM MONTH-TOTAL
END-IF
Maybe you need to add 1 to the year inside that IF?
I won't even try to write it in COBOL
I would suggest at the start of the program
you calculate the date 6 months in the future (and store in YYYYMMDD format).
You can then compare REQUEST-DATE-P-IN > Calculated-date
To calculate the future date:
Add 6 to month
if month > 12
Sub 12 from month
Add 1 to year
end-if
This is much simpler than the Evaluate

Resources