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
Related
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.
My calculations are correct. But the output file's ONLY first calculated record becomes as BLANK and affects all the records.
In the output file [A5-SalaryReport-5A.out], you may see the first record's position comes BLANK.
THIS IS MY INPUT FILE [A5.dat]
030ALLDREN RUTH 21G202000002200000
185DONNEMAN THOMAS06G042300900460000
004ACHER WILLIAM 01N072600500720000
325HATFIELD MARK 01G112200201100000
730REEDE OWEN 09G055501000620000
111CARTOLER VIOLET02G099800701000000
590NEIL CLARENCE 07N006500900100000
801SCHEIBER HARRY 01N100000001000000
956WANGLEY THEO 01N099999101000000
999BAKER RON 03G300001403500000
181DELBERT EDWARD 12G065901300770000
311GROLER GRACE 23N064302000770000
318HANEY CAROL 09G500001405500000
487KING MILDRED 18N091996301000000
834TRAWLEY HARRIS 05N732600507700000
027ALHOUER ELAINE 01G257300202500000
171COSTA NAN 15N035600500400000
317HANBEE ALETA 03G500000305500000
739RIDEL ROBERT 05N019400800200000
806STOCKTON NORMAN06G250700704300000
122CENNA DICK 03N577700406000000
207EBERHARDT RON 05G400700904500000
308GLEASON JAMES 01G500000305000000
568LYNNF GERALD 09N448701304500000
909UDSON DORIS 01N449900304500000
100BATES TONY 08N106602001000000
179DAMSON ERIC 03N250201802500000
292EVERLEY DONNA 03G200001702500000
409ICK MICK 25G999999910500000
607ODELLE NICK 10G250701803000000
825TILLMAN DON 12N044401900500000
214EDMONSON RICK 02N100000001000000
310GORMALLY MARIE 03N302200603000000
332HELD ANNA 02G400000204000000
689OWNEY REED 04N317460303500000
802SHEA MICHAEL 06G203300802300000
102BELLSLEY ART 08G300000903500000
282ESTABAN JUAN 19G405500004500000
322HARLETON JEAN 07N089901201000000
505LAMBERT JERRY 01G400100404000000
921ULL GEORGE 18N229885102500000
105BOYLE RALPH 08N804401407800000
215EDSON WILBUR 06G705000808000000
315HALE ALAN 12N400001604500000
THIS IS MY COBOL PROJECT FILE .cbl [A5-SalaryReport-5A.cbl]
identification division.
program-id. A5-SalaryReport-5A.
author. Nirmal Patel.
date-written. 11 March 2021.
* NOTE: I could have finished this, I just had too much for
* this week so I couldn not give this enough time. And I
* started this assignment on the day it it was due, 5th
* March.
environment division.
input-output section.
file-control.
select input-file
assign to "../../../data/A5.dat"
organization is line sequential.
select output-file
assign to "../../../data/A5-SalaryReport-5A.out"
organization is line sequential.
*
select outputdat-file
assign to
"../../../data/A5-SalaryData-NonGrad.dat"
organization is line sequential.
data division.
file section.
fd input-file
data record is input-rec
record contains 36 characters.
01 input-rec.
05 in-emp-no pic 9(3).
05 in-name pic x(15).
05 in-yrs-serv pic 9(2).
05 in-edu-code pic x(1).
88 il-88-type-K value "N".
05 in-prsnt-sly pic 9(5)V99.
05 in-bgt-est pic 9(6)V99.
fd output-file
data record is output-file
record contains 120 characters.
*
01 output-line pic x(120).
fd outputdat-file
data record is outputdat-line
record contains 55 characters.
01 outputdat-line pic x(55).
working-storage section.
01 ws-eof-flag pic x value 'n'.
*
01 ws-heading-info-line.
05 filler pic x(26)
value "Nirmal Patel, Assignment 4".
* ----+----1----+----2----+-
05 filler pic x(15) value spaces.
05 filler pic x(8) value "20210411".
05 filler pic x(23) value spaces.
05 filler pic x(7) value "1951043".
01 ws-heading-line-1.
05 filler pic x(30) value spaces.
05 filler pic x(22)
value "EMPLOYEE SALARY REPORT".
05 filler pic x(14) value spaces.
05 filler pic x(6) value "PAGE ".
05 page-num pic 9 value 1.
01 ws-heading-line-2.
05 filler pic x(3) value "EMP".
05 filler pic x(2) value spaces.
05 filler pic x(3) value "EMP".
05 filler pic x(32) value spaces.
05 filler pic x(7) value "PRESENT".
05 filler pic x(2) value spaces.
05 filler pic x(8) value "INCREASE".
05 filler pic x(5) value spaces.
05 filler pic x(3) value "PAY".
05 filler pic x(11) value spaces.
05 filler pic x(3) value "NEW".
01 ws-heading-line-3.
05 filler pic x(3) value "NUM".
05 filler pic x(2) value spaces.
05 filler pic x(4) value "NAME".
05 filler pic x(10) value spaces.
05 filler pic x(5) value "YEARS".
05 filler pic x(1) value spaces.
05 filler pic x(8) value "POSITION".
05 filler pic x(8) value spaces.
05 filler pic x(6) value "SALARY".
05 filler pic x(5) value spaces.
05 filler pic x(1) value "%".
05 filler pic x(7) value spaces.
05 filler pic x(8) value "INCREASE".
05 filler pic x(7) value spaces.
05 filler pic x(6) value "SALARY".
01 ws-record-line.
05 ws-emp-num pic 9(3).
05 filler pic x(1) value spaces.
05 ws-emp-name pic 9(15).
05 filler pic x(2) value spaces.
05 ws-years pic Z9.
05 filler pic x(2) value spaces.
05 ws-position pic x(12).
05 filler pic x(2) value spaces.
05 ws-salary pic ZZ,ZZ9.99.
05 filler pic x(2) value spaces.
05 ws-inc-per pic 9(2).9.
05 filler pic x(1) value "%".
05 filler pic x(3) value spaces.
05 ws-pay-inc pic $ZZ,ZZ9.99.
05 filler pic x(1) value "+".
05 filler pic x(1) value spaces.
05 filler pic x(1) value "$".
05 filler pic x(1) value spaces.
05 ws-new-salary pic ZZ,ZZZ,ZZ9.99.
01 ws-blank-line.
05 ws-blank-position pic x(12).
01 ws-totals-line-1.
05 filler pic x(15) value "EMPLOYEE CLASS:".
05 filler pic x(8) value spaces.
05 filler pic x(7) value "Analyst".
05 filler pic x(4) value spaces.
05 filler pic x(8) value "Sen Prog".
05 filler pic x(4) value spaces.
05 filler pic x(4) value "Prog".
05 filler pic x(4) value spaces.
05 filler pic x(7) value "Jr Prog".
05 filler pic x(4) value spaces.
05 filler pic x(12) value "Unclassified".
01 ws-totals-line-2.
05 filler pic x(15) value "# ON THIS PAGE:".
05 filler pic x(14) value spaces.
05 ws-no-of-analyst pic 9.
05 filler pic x(11) value spaces.
05 ws-no-of-sen-prog pic 9.
05 filler pic x(7) value spaces.
05 ws-no-of-prog pic 9.
05 filler pic x(10) value spaces.
05 ws-no-of-jr-prog pic 9.
05 filler pic x(15) value spaces.
05 ws-no-of-unclassified
pic 9.
01 ws-sub-total-line-1.
05 filler pic x(18)
value "AVERAGE INCREASES:".
05 filler pic x(3) value spaces.
05 filler pic x(8) value "ANALYST=".
05 filler pic x(5) value spaces.
05 ws-analyst-avg-inc pic Z,ZZ9.99.
05 filler pic x(5) value spaces.
05 filler pic x(9) value "SEN PROG=".
05 filler pic x(3) value spaces.
05 ws-sen-prog-avg-inc pic Z,ZZ9.99.
01 ws-sub-total-line-2.
05 filler pic x(21) value spaces.
05 filler pic x(5) value "PROG=".
05 filler pic x(8) value spaces.
05 ws-prog-avg-inc pic Z,ZZ9.99.
05 filler pic x(5) value spaces.
05 filler pic x(8) value "JR PROG=".
05 filler pic x(4) value spaces.
05 ws-jr-prog-avg-inc pic Z,ZZ9.99.
01 ws-oth-line.
05 filler pic x(25)
value " Type NON-GRADS count = ".
05 ws-oth-staff-count pic zz9.
05 filler pic x(7)
value spaces.
05 filler pic x(26)
value " Type NON-GRADA Salary = ".
05 ws-oth-salary pic $$$,$$$,$$9.
05 filler pic x(38)
value spaces.
05 ws-calc-position pic x(12).
01 ws-const-calc.
05 ws-page-count pic 99 value 0.
05 ws-edu-code pic x(1).
05 ws-o-staff-count pic 999 value 0.
05 ws-o-salary pic 9(10) value 0.
05 ws-s-staff-count pic 999 value 0.
05 ws-s-salary pic 9(10) value 0.
77 ws-lines-per-page pic 99 value 20.
77 ws-line-count pic 99 value 0.
procedure division.
000-main.
open input input-file.
open output output-file
outputdat-file.
write output-line from ws-heading-info-line
*
read input-file
at end
move "y" to ws-eof-flag.
*
* Process each input record and read in next record
*
perform 100-process-pages
until ws-eof-flag equals "y".
write output-line from ws-sub-total-line-1
after advancing 1 line.
write output-line from ws-sub-total-line-2.
close input-file
output-file
outputdat-file.
goback.
100-process-pages.
*
* Initialize detail calculation variables for page
*
move 0 to ws-s-staff-count
ws-s-salary
ws-line-count.
perform 110-print-headings.
*
* process input and output results until
* current page has been filled
* OR EOF has been encountered
*
perform 120-process-lines
varying ws-line-count from 1 by 1
until (ws-line-count > ws-lines-per-page
OR ws-eof-flag = "y").
perform 150-print-page-totals.
*
110-print-headings.
* Increase page count by 1
add 1 to ws-page-count.
move ws-page-count to page-num.
*
* Write the report heading with a blank line before heading
* and blank line after heading
*
if (ws-page-count > 1) then
write output-line
after advancing page
write output-line from ws-heading-line-1
after advancing 1 line
write output-line from ws-heading-line-2
after advancing 2 line
write output-line from ws-heading-line-3
else
write output-line from ws-heading-line-1
after advancing 1 line
write output-line from ws-heading-line-2
after advancing 2 line
write output-line from ws-heading-line-3
end-if.
120-process-lines.
* Decide whether to output to report or data file
*
if il-88-type-K
perform 210-process-data-lines
else
add 1 to ws-line-count
* if ws-line-count = 1
* perform 120-print-headings
* end-if
perform 220-process-rpt-lines
if ws-line-count > ws-lines-per-page
or ws-eof-flag = "y"
perform 230-print-page-totals
end-if
end-if.
*
* Logic to calculate the POSITION based on years of xp..
*
if in-yrs-serv > 15
then
move "ANALYST" to ws-calc-position
else
**
if in-yrs-serv > 7 and in-yrs-serv < 15
then
move "SEN PROG" to ws-calc-position
else
***
if in-yrs-serv > 2 and in-yrs-serv < 7
then
move "PROG" to ws-calc-position
else
****
if in-yrs-serv < 2
then
move "UNCLASSIFIED"
to ws-calc-position
* ----+----1--
end-if
****
end-if
***
end-if
**
end-if
*
* Read next input record for the next iteration of perform loop
*
read input-file
at end
move "y" to ws-eof-flag.
*
*
150-print-page-totals.
*
* PRINT TOTAL LINES
write output-line from ws-totals-line-1
after advancing 2 line.
write output-line from ws-totals-line-2.
*
*
210-process-data-lines.
*
add 1 to ws-o-staff-count.
add in-prsnt-sly to ws-o-salary.
move ws-position to ws-blank-position.
*
write outputdat-line from input-rec.
220-process-rpt-lines.
*
*
* Count staff and accumulate salary for page subtotals
*
add 1 to ws-s-staff-count.
add in-prsnt-sly to ws-s-salary.
*
*
* Output Salesperson Detail Line
*
* Clear the detail line
move spaces to ws-record-line.
*
*
* Move input lines(sales-file) to output lines(report-line)
*
move in-emp-no to ws-emp-num.
move in-name to ws-emp-name.
move in-yrs-serv to ws-years.
move in-prsnt-sly to ws-salary.
move ws-page-count to page-num.
move ws-o-staff-count to ws-oth-staff-count.
move ws-calc-position to ws-position.
*
write output-line from ws-record-line.
230-print-page-totals.
* Move subtotals to subtotal line and write to output file
* with blank line after subtotal line
*
*
write outputdat-line from ws-record-line.
*
*
move 0 to ws-s-staff-count
ws-s-salary.
*
*
end program A5-SalaryReport-5A.
THIS IS MY OUTPUT FILE [A5-SalaryReport-5A.out]
Nirmal Patel, Assignment 4 20210411 1951043
EMPLOYEE SALARY REPORT PAGE 1
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
030 ALLDREN RUTH 21 20,200.00
185 DONNEMAN THOMAS 6 ANALYST 4,230.09
325 HATFIELD MARK 1 UNCLASSIFIED 11,220.02
730 REEDE OWEN 9 UNCLASSIFIED 5,550.10
111 CARTOLER VIOLET 2 SEN PROG 9,980.07
999 BAKER RON 3 UNCLASSIFIED 30,000.14
181 DELBERT EDWARD 12 PROG 6,590.13
318 HANEY CAROL 9 ANALYST 50,000.14
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 2
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
027 ALHOUER ELAINE 1 PROG 25,730.02
317 HANBEE ALETA 3 UNCLASSIFIED 50,000.03
806 STOCKTON NORMAN 6 PROG 25,070.07
207 EBERHARDT RON 5 PROG 40,070.09
308 GLEASON JAMES 1 PROG 50,000.03
292 EVERLEY DONNA 3 PROG 20,000.17
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 3
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
409 ICK MICK 25 PROG 99,999.99
607 ODELLE NICK 10 ANALYST 25,070.18
332 HELD ANNA 2 PROG 40,000.02
802 SHEA MICHAEL 6 PROG 20,330.08
102 BELLSLEY ART 8 PROG 30,000.09
282 ESTABAN JUAN 19 SEN PROG 40,550.00
505 LAMBERT JERRY 1 ANALYST 40,010.04
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 4
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
215 EDSON WILBUR 6 SEN PROG 70,500.08
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
AVERAGE INCREASES: ANALYST= SEN PROG=
PROG= JR PROG=
I know it is not an ez thing to figure out and I appreciate whatever answer you provide.
Cheers!
The problem I see is that the correct value for ws-position shows on the next record; this happens because ws-calc-position is determined after the line is printed. This caused a blank on the first record and an incorrect value on the following print lines.
I suggest moving the code for determining ws-calc-position to just before it is needed. 120-process-lines and 220-process-rpt-lines incorporates those suggestions.
The IF code should not include AND, as expressed originally. It causes some values to be missed, where in-yrs-serv is 15, 07, or 02. Those particular values caused (or would cause) the previously determined position to appear in the output. That change has be made below.
Also, this line
05 ws-emp-name pic 9(15).
should be
05 ws-emp-name pic x(15).
120-process-lines.
* Decide whether to output to report or data file
*
if il-88-type-K
perform 210-process-data-lines
else
add 1 to ws-line-count
* if ws-line-count = 1
* perform 120-print-headings
* end-if
perform 220-process-rpt-lines
if ws-line-count > ws-lines-per-page
or ws-eof-flag = "y"
perform 230-print-page-totals
end-if
end-if.
* NOTE: Moved code to determine position to 225-determine-position
*
* Read next input record for the next iteration of perform loop
*
read input-file
at end
move "y" to ws-eof-flag.
220-process-rpt-lines.
*
*
* Count staff and accumulate salary for page subtotals
*
add 1 to ws-s-staff-count.
add in-prsnt-sly to ws-s-salary.
*
*
* Output Salesperson Detail Line
*
* Clear the detail line
move spaces to ws-record-line.
*
*
* Move input lines(sales-file) to output lines(report-line)
*
move in-emp-no to ws-emp-num.
move in-name to ws-emp-name.
move in-yrs-serv to ws-years.
move in-prsnt-sly to ws-salary.
move ws-page-count to page-num.
move ws-o-staff-count to ws-oth-staff-count.
perform 225-determine-position.
move ws-calc-position to ws-position.
*
write output-line from ws-record-line.
225-determine-position.
*
* Logic to calculate the POSITION based on years of xp..
*
if in-yrs-serv > 15
then
move "ANALYST" to ws-calc-position
else
**
if in-yrs-serv > 7
then
move "SEN PROG" to ws-calc-position
else
***
if in-yrs-serv > 2
then
move "PROG" to ws-calc-position
else
****
move "UNCLASSIFIED" to ws-calc-position
****
end-if
***
end-if
**
end-if.
I am still new to COBOL and have been working on a project for school for almost a week now. I am running OpenCobol 1.1.
When I try to compile it I get this error.
typeck.c:5912: Invalid type cast from 'null'
Tag 1 0 Tag 2 10
Aborting compile of lab4.cob at line 214
I've been frustrated because I've tried changing the code around a lot with no luck.
Procedure Division.
000-Main.
Perform 100-initialize
Perform Until EndOfFile = "Y"
Read Lab4-in-File
At End
Move "Y" To EndOfFile
Not At End
Perform 300-process
End-Read
End-Perform
Perform 900-finalize
Stop Run.
100-intialize.
Perform 110-open-files
Perform 120-get-data.
110-open-files.
Open Input Lab4-in-File
Output Ot-File.
120-get-date.
Accept WS-date from date yyyymmdd
Move WS-Year To PH-Year
Move WS-Month To PH-Month
Move WS-Day To PH-Day.
300-process.
Move Dept-no To dl-dep-no
Move Employee-no To dl-emp-no
If First-name Not = "Null"
String First-name Delimited By Size
" " Delimited By Size
Last-name Delimited By Size
Into dl-emp
else
Move Last-name To dl-emp
End-If
Move Job-title To dl-job
Move DOH To dl-doh
Move Mar-status To dl-marital
Move Dependents To dl-dependents
Move MCoverage To dl-insurance
Move DCoverage To dl-insurance
Move VCoverage To dl-insurance
Move 401K To dl-401k
Move Pay-code To dl-pay-code
If Pay-code = "C" Or "S"
Compute Pay-hold rounded =
Pay / 12
Move Pay-hold To dl-monthly-pay
else
Compute Pay-hold rounded =
Pay * HPW * 4
Move Pay-hold To dl-monthly-pay
End-If
If Pay-code = "C"
Compute Com-hold rounded =
Act-sale * C-rate
Move Com-hold To dl-commission
Else
Move 0 To dl-commission
End-If
Perform 800-print
Multiply C-rate By Act-sale Giving
total-sales
Add Pay To total-sales.
800-print.
If LineNum > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Detail-Line
**After advancing 1 line** *> This is line 214
Add 1 To LineNum.
825-new-page.
If PageNum > 0
Write Lab4-Record2 From Blank-line
After advancing 1 line
End-If
Add 1 To PageNum
Move PageNum To PH-PageNo
Write Lab4-Record2 From Page-Header
After advancing page
Write Lab4-Record2 From Blank-line
After advancing 1 line
Write Lab4-Record2 From Column-Header
After advancing 1 line
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move 5 To LineNum.
900-finalize.
Perform 950-print-monthly-total
Perform 999-close-files.
950-print-monthly-total.
If LineNum + 1 > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move total-sales To Total-pay
Write Lab4-Record2 From Total-Line
After advancing 1 line
Add 2 To LineNum.
999-close-files.
Close Lab4-in-File Ot-File.
I would really appreciate it if someone could help me find what is causing the error. Thanks in advance!
Working-Storage Section.
01 EndOfFile Pic X Value "N".
01 Report-fields.
05 PageNum Pic 9(3) value 0.
05 LinesPerPage Pic 9(2) value 40.
05 LineNum Pic 9(2) value 41.
01 WS-date.
05 WS-Year Pic 9(4).
05 WS-Month Pic 99.
05 WS-Day Pic 99.
01 total-fields.
05 total-sales Pic 9(11)v99 Value 0.
01 Page-Header.
05 PH-Month Pic Z9/.
05 PH-Day Pic 99/.
05 PH-Year Pic 9999.
05 Pic X(7) Value Spaces.
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium"
05 Pic X(6) Value "Page:".
05 PH-PageNo Pic ZZ9.
01 Column-Header.
05 Pic X(8) Value "Dep #".
05 Pic X(15) Value "Emp #".
05 Pic X(27) Value "Employee".
05 Pic X(18) Value "Title".
05 Pic X(9) Value "DOH".
05 Pic X(9) Value "Marital".
05 Pic X(7) Value "#Deps".
05 Pic X(6) Value "Ins".
05 Pic X(6) Value "401K".
05 Pic X(6) Value "Pay".
05 Pic X(27) Value "Expected " &
"Pay + Commission".
01 Pay-hold Pic 9(9)V9(2) Value 0.
01 Com-hold Pic 9(9)V9(2) Value 0.
01 Detail-Line.
05 dl-dep-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp Pic X(35).
05 Pic X(1) Value spaces.
05 dl-job Pic X(20).
05 Pic X(1) Value spaces.
05 dl-doh Pic X(8).
05 Pic X(1) Value spaces.
05 dl-marital Pic X.
05 Pic X(1) Value spaces.
05 dl-dependents Pic 9(2).
05 Pic X(1) Value spaces.
05 dl-insurance Pic X(3).
05 Pic X(1) Value spaces.
05 dl-401k Pic Z.9ZZ.
05 Pic X(1) Value spaces.
05 dl-pay-code Pic X.
05 Pic X(1) Value spaces.
05 dl-monthly-pay Pic $$$$,$$$,$$9.99.
05 Pic X(1) Value spaces.
05 dl-commission Pic $$$,$$9.99.
01 Total-Line.
05 Pic X(61) Value Spaces.
05 Pic X(24) Value "Total" &
" Expected Payroll: ".
05 Total-pay Pic $$$$,$$$,$$$,$$9.99.
01 Blank-line Pic X Value spaces.
The compiler has a broken parser. It is broken because of a coding error (still a compiler bug). In cases like this you only have the chance to either spot the error or - much better - use a newer version.
I've just put your code in an online compiler using the last release of the compiler: GnuCOBOL 2.2. I highly suggest to upgrade to at least this version.
See your code here - I've just added a minimal header and end.
Then click on "Execute" and you compile it online, leading to the following error messages:
main.cobc: 27: error: duplicate PICTURE clause
main.cobc: 27: error: duplicate VALUE clause
main.cobc: 64: error: a Z or * which is after the decimal point cannot follow 9
If you check the line 27 in this program you see
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium" *> <<- missing period
05 Pic X(6) Value "Page:".
Fixed code is also available.
I am trying to finish a program that I have started but am confused as to what I need to do and how to do the last step. The instructions are to:
At the end of report:
A. Print the number of personnel records processed.
B. The number of records where there was an unsuccessful search of the Dept Table.
C. The number of records where there was an unsuccessful search of the Title Table.
I have completed all of the program except this last step. Can someone please help me finish this program?
enter code here ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PERSONNEL-FILE
ASSIGN TO 'CH12PPPF.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT DEPT-TABLE-FILE
ASSIGN TO 'CH12PPDT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT TITLE-TABLE-FILE
ASSIGN TO 'CH12PPTT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRINT-FILE
ASSIGN TO 'THORNTONCA4.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD PERSONNEL-FILE.
01 PERSONNEL-REC.
05 SSNO-IN PIC 9(9).
05 NAME-IN PIC X(20).
05 SALARY-IN PIC 9(6).
05 CAMPUS-CODE-IN PIC 9.
05 DEPT-CODE-IN PIC 99.
05 TITLE-CODE-IN PIC 999.
FD DEPT-TABLE-FILE.
01 DEPT-REC.
05 T-DEPT-NO PIC 99.
05 T-DEPT-NAME PIC X(10).
FD TITLE-TABLE-FILE.
01 TITLE-REC.
05 T-TITLE-CODE PIC 999.
05 T-TITLE-NAME PIC X(10).
FD PRINT-FILE.
01 PRINT-REC PIC X(80).
WORKING-STORAGE SECTION.
01 STORED-AREAS.
05 MORE-RECS PIC X(3) VALUE 'YES'.
05 WS-DATE.
10 WS-YEAR PIC 9999.
10 WS-MONTH PIC 99.
10 WS-DAY PIC 99.
05 WS-PAGE-CT PIC 99
VALUE ZERO.
05 WS-LINE-CT PIC 99
VALUE ZERO.
01 HDR1-OUT.
05 PIC X(25)
VALUE SPACES.
05 PIC X(20)
VALUE 'FINAL REPORT'.
05 DATE-OUT.
10 MONTH-OUT PIC 99.
10 PIC X
VALUE '/'.
10 DAY-OUT PIC 99.
10 PIC X
VALUE '/'.
10 YEAR-OUT PIC 9999.
05 PIC X(2)
VALUE SPACES.
05 PIC X(5)
VALUE 'PAGE'.
05 PAGE-OUT PIC Z9.
*****************************************************************
* The Campus Table consists of 5 10-position names and will be *
* accessed as a direct-referenced table. EACH_CAMPUS *
* subscriped by the CAMPUS_CODE_IN will provide the name. *
*****************************************************************
01 CAMPUTS-TABLE
VALUE 'UPSTATE DOWNSTATE CITY MELVILLE HUNTINGTON'.
05 EACH-CAMPUS
OCCURS 5 TIMES PIC X(10).
*****************************************************************
* The Dept Table will be accessed by a SEARCH. Even if the *
* table is entered in Dept No sequence, there would be no *
* real benefit to using a SEARCH ALL since there are only *
* 25 entries. *
*****************************************************************
01 DEPT-TABLE.
05 DEPT-ENTRIES OCCURS 25 TIMES INDEXED BY X1.
10 DEPT-NO PIC 99.
10 DEPT-NAME PIC X(10).
*****************************************************************
* The Title Talbe will be accessed by a SEARCH ALL. To use a *
* binary seach the entries must be in sequence by a key *
* field and the table should be relatively large. *
*****************************************************************
01 TITLE-TABLE.
05 TITLE-ENTRIES OCCURS 50 TIMES
ASCENDING KEY IS TITLE-NO INDEXED BY X2.
10 TITLE-NO PIC 999.
10 TITLE-NAME PIC X(10).
01 DETAIL-REC.
05 PIC X(1) VALUE SPACES.
05 SSNO-OUT PIC 999B99B9999.
05 PIC X(1) VALUE SPACES.
05 NAME-OUT PIC X(20).
05 PIC X(1) VALUE SPACES.
05 SALARY-OUT PIC $ZZZ,ZZZ.
05 PIC X(1) VALUE SPACES.
05 CAMPUS-OUT PIC X(10).
05 PIC X(1) VALUE SPACES.
05 DEPT-OUT PIC X(10).
05 PIC X(1) VALUE SPACES.
05 TITLE-OUT PIC X(10).
PROCEDURE DIVISION.
100-MAIN-MODULE.
OPEN INPUT PERSONNEL-FILE
DEPT-TABLE-FILE
TITLE-TABLE-FILE
OUTPUT PRINT-FILE
MOVE FUNCTION CURRENT-DATE TO WS-DATE
MOVE WS-MONTH TO MONTH-OUT
MOVE WS-DAY TO DAY-OUT
MOVE WS-YEAR TO YEAR-OUT
PERFORM 500-HDG-RTN.
PERFORM 200-LOAD-DEPT-TABLE
PERFORM 300-LOAD-TITLE-TABLE
PERFORM UNTIL MORE-RECS = 'NO '
READ PERSONNEL-FILE
AT END
MOVE 'NO ' TO MORE-RECS
NOT AT END
PERFORM 400-CALC-RTN
END-READ
END-PERFORM
CLOSE PERSONNEL-FILE
DEPT-TABLE-FILE
TITLE-TABLE-FILE
PRINT-FILE
STOP RUN.
200-LOAD-DEPT-TABLE.
PERFORM VARYING X1 FROM 1 BY 1
UNTIL X1 > 25
READ DEPT-TABLE-FILE
AT END DISPLAY 'NOT ENOUGH DEPT TABLE RECORDS'
STOP RUN
END-READ
MOVE DEPT-REC TO DEPT-ENTRIES (X1)
END-PERFORM.
300-LOAD-TITLE-TABLE.
PERFORM VARYING X2 FROM 1 BY 1
UNTIL X2 > 50
READ TITLE-TABLE-FILE
AT END DISPLAY 'NOT ENOUH TITLE TABLE RECORDS'
STOP RUN
END-READ
MOVE TITLE-REC TO TITLE-ENTRIES (X2)
IF X2 > 1 THEN
IF TITLE-NO (X2) <= TITLE-NO (X2 - 1)
DISPLAY 'TITLE RECORDS ARE NOT IN SEQUENCE'
STOP RUN
END-IF
END-IF
END-PERFORM.
400-CALC-RTN.
MOVE SPACES TO DETAIL-REC
MOVE SSNO-IN TO SSNO-OUT
MOVE NAME-IN TO NAME-OUT
MOVE SALARY-IN TO SALARY-OUT
IF CAMPUS-CODE-IN >= 1 AND <= 5
MOVE EACH-CAMPUS (CAMPUS-CODE-IN) TO CAMPUS-OUT
END-IF
SET X1 TO 1
SEARCH DEPT-ENTRIES
AT END MOVE 'XXXXXXXXXX' TO DEPT-OUT
WHEN DEPT-CODE-IN = DEPT-NO (X1)
MOVE DEPT-NAME (X1) TO DEPT-OUT
END-SEARCH
SEARCH ALL TITLE-ENTRIES
AT END MOVE 'XXXXXXXXXX' TO TITLE-OUT
WHEN TITLE-NO (X2) = TITLE-CODE-IN
MOVE TITLE-NAME (X2) TO TITLE-OUT
END-SEARCH
WRITE PRINT-REC FROM DETAIL-REC
AFTER ADVANCING 2 LINES.
500-HDG-RTN.
ADD 1 TO WS-PAGE-CT
MOVE WS-PAGE-CT TO PAGE-OUT
WRITE PRINT-REC FROM HDR1-OUT
AFTER ADVANCING PAGE
MOVE ZEROS TO WS-LINE-CT.
You need to:
Produce code to accumulate all the values you need to print at the end
Produce definition(s) of the final part of the report
Produce the final part of report once the main input file has been processed, ie after your first PERFORM and before the CLOSE
You should get into the habit of checking all file statuses after each IO operation, using FILE-STATUS, and accurately report when something unexpected happens.
You'll find it worthwhile to give good names even to indexes, and use 88s wherever possible for IF or EVALUATE and avoid using things like this "IF CAMPUS-CODE-IN >= 1 AND <= 5".
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?