I have a program that is suppose to sort an input file (seq) and they output an RPT file.
This program code should be correct, the problem should only be in the sorting of this program. Currently, it prints is weird chunks.
SORT: The output records need to sort LEAGUE-S (major) in descending order. TEAM-S (intermediate) ascending order. NAME-S (minor) ascending order.
SEQ:
Alonso NL SD 549 150
Altuve NL HOU 576 167
Andrus AL TEX 629 180
Aoki NL MIL 520 150
Aybar AL LAA 517 150
Belt NL SF 411 113
Beltre AL TEX 604 194
Bernadina NL WSH 227 066
Berry AL DET 291 075
Betemit AL BAL 341 089
Bloomquist NL ARI 324 098
Bourn NL ATL 624 171
Brantley AL CLE 552 159
Braun NL MIL 598 191
Butler AL KC 614 192
Cabrera AL CLE 555 150
Cabrera AL DET 622 205
Cain AL KC 222 059
Callaspo AL LAA 457 115
Cano AL NYY 627 196
Carpenter NL STL 296 087
Carroll AL MIN 470 126
Castro NL CHC 646 183
Cespedes AL OAK 487 142
Chavez AL NYY 278 078
Choo AL CLE 598 169
Ciriaco AL BOS 259 076
Colvin NL COL 420 122
Craig NL STL 469 144
Crisp AL OAK 455 118
Cruz AL TEX 585 152
Cruz NL LAD 283 084
Davis AL BAL 515 139
Davis AL TOR 447 115
De Aza AL CWS 524 147
Denorfia NL SD 348 102
Desmond NL WSH 513 150
Dirks AL DET 314 101
Dobbs NL MIA 319 091
Doumit AL MIN 484 133
Dyson AL KC 292 076
Ellsbury AL BOS 303 082
Encarnacion AL TOR 542 152
Escobar AL KC 605 177
Escobar AL TOR 558 141
Ethier NL LAD 556 158
Fielder AL DET 581 182
Forsythe NL SD 315 086
Fowler NL COL 454 136
Frandsen NL PHI 195 066
Frazier NL CIN 422 115
Freese NL STL 501 147
Gentry AL TEX 240 073
Getz AL KC 189 052
Goldschmidt NL ARI 514 147
Gomes AL OAK 279 073
Gonzalez AL BOS 484 145
Gonzalez NL COL 518 157
Gordon AL KC 642 189
Grandal NL SD 192 057
Hairston NL LAD 238 065
Hamilton AL TEX 562 160
Hanigan NL CIN 317 087
Harper NL WSH 533 144
Hart NL MIL 562 152
Headley NL SD 604 173
Hill NL ARI 609 184
Holliday NL STL 599 177
Hunter AL LAA 534 167
Infante AL DET 226 058
Infante NL MIA 328 094
Izturis AL LAA 289 074
Jackson AL DET 543 163
Jaso AL SEA 294 081
Jay NL STL 443 135
Jeter AL NYY 683 216
Johnson NL ARI 488 137
Johnson NL ATL 269 078
Jones AL BAL 648 186
Jones NL ATL 387 111
Jones NL PIT 475 130
Kemp NL LAD 403 122
Kendrick AL LAA 550 158
Keppinger AL TB 385 125
Kinsler AL TEX 655 168
Kipnis AL CLE 591 152
Konerko AL CWS 533 159
LaRoche NL WSH 571 155
Lawrie AL TOR 494 135
LeMahieu NL COL 229 068
Lind AL TOR 321 082
Lombardozzi NL WSH 384 105
Longoria AL TB 273 079
Lucroy NL MIL 316 101
Ludwick NL CIN 422 116
Machado AL BAL 191 050
Markakis AL BAL 420 125
Mauer AL MIN 545 174
McCutchen NL PIT 593 194
McLouth AL BAL 209 056
Middlebrooks AL BOS 267 077
Molina NL STL 505 159
Montero AL SEA 515 134
Montero NL ARI 486 139
Morales AL LAA 484 132
Moreland AL TEX 327 090
Morneau AL MIN 505 135
Morse NL WSH 406 118
Moss AL OAK 265 077
Murphy AL TEX 457 139
Murphy NL NYM 571 166
Nelson NL COL 345 104
Ortiz AL BOS 324 103
Pacheco NL COL 475 147
Pagan NL SF 605 174
Parra NL ARI 385 105
Pedroia AL BOS 563 163
Perez AL KC 289 087
Phillips NL CIN 580 163
Pierre NL PHI 394 121
Pierzynski AL CWS 479 133
Podsednik AL BOS 199 060
Posey NL SF 530 178
Prado NL ATL 617 186
Pujols AL LAA 607 173
Ramirez AL CWS 593 157
Ramirez NL MIL 570 171
Revere AL MIN 511 150
Reyes NL MIA 642 184
Rios AL CWS 605 184
Rizzo NL CHC 337 096
Rodriguez AL NYY 463 126
Rosario NL COL 396 107
Ross AL BOS 476 127
Ruggiano NL MIA 288 090
Ruiz NL PHI 372 121
Rutledge NL COL 277 076
Sanchez NL SF 218 061
Sandoval NL SF 396 112
Santana AL CLE 507 128
Schumaker NL STL 272 075
Scutaro NL SF 620 190
Seager AL SEA 594 154
Solano NL MIA 285 084
Span AL MIN 516 146
Stanton NL MIA 449 130
Suzuki AL NYY 629 178
Sweeney AL BOS 204 053
Swisher AL NYY 537 146
Teixeira AL NYY 451 113
Tejada NL NYM 464 134
Theriot NL SF 352 095
Trout AL LAA 559 182
Trumbo AL LAA 544 146
Tulowitzki NL COL 181 052
Upton NL ARI 554 155
Viciedo AL CWS 505 129
Votto NL CIN 374 126
Walker NL PIT 472 132
Werth NL WSH 300 090
Willingham AL MIN 519 135
Wise AL CWS 224 058
Wright NL NYM 581 178
Young AL DET 574 153
Young AL TEX 611 169
Young NL COL 174 055
Zimmerman NL WSH 578 163
Zobrist AL TB 560 151
Program:
IDENTIFICATION DIVISION.
PROGRAM-ID. BASEBALL-5.
* TATE
******************************************************************
* This program will sort different stats for different baseball
* players while keeping running totals and averages with breaks.
******************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BASEBALL-FILE-UNSORTED-IN
ASSIGN TO 'BASEBALL-5.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE
ASSIGN TO 'SORT.DAT'.
SELECT BASEBALL-FILE-IN
ASSIGN TO 'BASEBALL-5.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT BASEBALL-FILE-OUT
ASSIGN TO 'BASEBALL-5.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD BASEBALL-FILE-UNSORTED-IN.
01 BASEBALL-RECORD-UNSORTED-IN PIC X(36).
SD SORT-FILE.
01 SORT-RECORD.
05 NAME-S PIC X(18).
05 PIC XX.
05 LEAGUE-S PIC XX.
05 PIC X.
05 TEAM-S PIC XXX.
05 PIC X(10).
FD BASEBALL-FILE-IN.
01 BASEBALL-RECORD-IN.
05 NAME-IN PIC X(18).
05 PIC XX.
05 LEAGUE-IN PIC XX.
05 PIC X.
05 TEAM-IN PIC X(3).
05 PIC X(3).
05 AT-BATS-IN PIC 9(3).
05 PIC X.
05 HITS-IN PIC 9(3).
FD BASEBALL-FILE-OUT.
01 BASEBALL-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-RECORD-READ PIC X(3) VALUE 'YES'.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 WS-HOLD-PREVIOUS-TEAM-IN PIC X(3) VALUE SPACES.
01 WS-HOLD-PREVIOUS-LEAGUE-IN PIC XX VALUE SPACES.
01 WS-TEAM-HITS PIC 9(4) VALUE ZERO.
01 WS-TEAM-AT-BATS PIC 9(4) VALUE ZERO.
01 WS-TEAM-AVERAGE PIC V999 VALUE ZERO.
01 WS-AVERAGE PIC V999 VALUE ZERO.
01 WS-LEAGUE-HITS PIC 9(5) VALUE ZERO.
01 WS-LEAGUE-AT-BATS PIC 9(5) VALUE ZERO.
01 WS-LEAGUE-AVERAGE PIC V999 VALUE ZERO.
01 WS-GRAND-HITS PIC 9(6) VALUE ZERO.
01 WS-GRAND-AT-BATS PIC 9(6) VALUE ZERO.
01 WS-GRAND-AVERAGE PIC V999 VALUE ZERO.
01 WS-HIGHEST-AVERAGE PIC V999 VALUE ZERO.
01 WS-LOWEST-AVERAGE PIC V999 VALUE .999.
01 WS-BLANK-LINE PIC X(80) VALUE SPACES.
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(24) VALUE SPACES.
05 PIC X(26) VALUE 'BASEBALL PLAYER STATISTICS'.
05 PIC X(9) 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(6) VALUE 'LEAGUE'.
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE 'TEAM'.
05 PIC X(6) VALUE SPACES.
05 PIC X(4) VALUE 'NAME'.
05 PIC X(18) VALUE SPACES.
05 PIC X(4) VALUE 'HITS'.
05 PIC X(9) VALUE SPACES.
05 PIC X(7) VALUE 'AT BATS'.
05 PIC X(6) VALUE SPACES.
05 PIC X(7) VALUE 'AVERAGE'.
01 DETAIL-LINE.
05 DL-LEAGUE PIC XX.
05 BLANK-A-OUT PIC X(8) VALUE SPACES.
05 DL-TEAM PIC X(3).
05 BLANK-B-OUT PIC X(7) VALUE SPACES.
05 DL-NAME PIC X(12).
05 BLANK-C-OUT PIC X(11) VALUE SPACES.
05 DL-HITS PIC ZZ9.
05 BLANK-D-OUT PIC X(13) VALUE SPACES.
05 DL-AT-BATS PIC ZZ9.
05 BLANK-E-OUT PIC X(9) VALUE SPACES.
05 DL-AVERAGE-OUT PIC .999.
01 TEAM-TOTALS.
05 ZTL-LEAGUE PIC XX.
05 PIC X(8) VALUE SPACES.
05 ZTL-TEAM PIC X(3).
05 PIC X(7) VALUE SPACES.
05 PIC X(15) VALUE '* Team Totals *'.
05 PIC X(6) VALUE SPACES.
05 ZTL-TEAM-HITS PIC Z,ZZ9.
05 PIC X(11) VALUE SPACES.
05 ZTL-TEAM-AT-BATS PIC Z,ZZ9.
05 PIC X(9) VALUE SPACES.
05 ZTL-TEAM-AVERAGE PIC .999.
01 TOTALS-LINE.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* Final Totals *'.
05 PIC X(3) VALUE SPACES.
05 TL-GRAND-HITS PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-AT-BATS PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-AVERAGE PIC .999.
01 LOW-TOTALS.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* Low Average *'.
05 PIC X(35) VALUE SPACES.
05 TL-LOW-AVERAGE PIC .999.
01 HIGH-TOTALS.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* High Average *'.
05 PIC X(35) VALUE SPACES.
05 TL-HIGH-AVERAGE PIC .999.
01 LEAGUE-TOTALS.
05 LTL-LEAGUE PIC XX.
05 PIC X(18) VALUE SPACES.
05 PIC X(17) VALUE '* League Totals *'.
05 PIC X(3) VALUE SPACES.
05 LTL-LEAGUE-HITS PIC ZZ,ZZ9.
05 PIC X(10) VALUE SPACES.
05 LTL-LEAGUE-AT-BATS PIC ZZ,ZZ9.
05 PIC X(9) VALUE SPACES.
05 LTL-LEAGUE-AVERAGE PIC .999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT BASEBALL-FILE-UNSORTED-IN
OPEN INPUT BASEBALL-FILE-IN
OPEN OUTPUT BASEBALL-FILE-OUT
PERFORM 110-PROCESS-FILE-DATES
SORT SORT-FILE
DESCENDING KEY LEAGUE-S
ASCENDING KEY TEAM-S
ASCENDING KEY NAME-S
INPUT PROCEDURE 120-SORT-INPUT-PROCEDURE
OUTPUT PROCEDURE 130-SORT-OUTPUT-PROCEDURE
CLOSE BASEBALL-FILE-UNSORTED-IN
CLOSE BASEBALL-FILE-IN
CLOSE BASEBALL-FILE-OUT
STOP RUN.
110-PROCESS-FILE-DATES.
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2.
120-SORT-INPUT-PROCEDURE.
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ BASEBALL-FILE-IN
AT END
PERFORM 350-TEAM-TOTALS-ROUTINE
PERFORM 375-LEAGUE-TOTALS-ROUTINE
PERFORM 400-TOTALS-ROUTINE
PERFORM 425-LOW-ROUTINE
PERFORM 450-HIGH-ROUTINE
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM.
130-SORT-OUTPUT-PROCEDURE.
PERFORM 200-PROCESS-ONE-RECORD.
200-PROCESS-ONE-RECORD.
IF TEAM-IN <> WS-HOLD-PREVIOUS-TEAM-IN AND WS-FIRST-RECORD-READ <> 'YES'
PERFORM 350-TEAM-TOTALS-ROUTINE
END-IF
IF LEAGUE-IN <> WS-HOLD-PREVIOUS-LEAGUE-IN AND WS-FIRST-RECORD-READ <> 'YES'
PERFORM 375-LEAGUE-TOTALS-ROUTINE
END-IF
MOVE 'NO' TO WS-FIRST-RECORD-READ
MOVE LEAGUE-IN TO WS-HOLD-PREVIOUS-LEAGUE-IN
MOVE TEAM-IN TO WS-HOLD-PREVIOUS-TEAM-IN
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
COMPUTE WS-AVERAGE ROUNDED = HITS-IN / AT-BATS-IN
MOVE LEAGUE-IN TO DL-LEAGUE
MOVE SPACES TO BLANK-A-OUT
MOVE TEAM-IN TO DL-TEAM
MOVE SPACES TO BLANK-B-OUT
MOVE NAME-IN TO DL-NAME
MOVE SPACES TO BLANK-C-OUT
MOVE HITS-IN TO DL-HITS
MOVE SPACES TO BLANK-D-OUT
MOVE AT-BATS-IN TO DL-AT-BATS
MOVE SPACES TO BLANK-E-OUT
MOVE WS-AVERAGE TO DL-AVERAGE-OUT
MOVE DETAIL-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
AFTER ADVANCING 1 LINE
ADD 1 TO LINES-PRINTED
* CALCULATE FINAL TOTALS
COMPUTE WS-GRAND-HITS = WS-GRAND-HITS + HITS-IN
COMPUTE WS-GRAND-AT-BATS = WS-GRAND-AT-BATS + AT-BATS-IN
COMPUTE WS-GRAND-AVERAGE ROUNDED = WS-GRAND-HITS / WS-GRAND-AT-BATS.
* CALCULATE ZTL HERE
COMPUTE WS-TEAM-HITS = WS-TEAM-HITS + HITS-IN
COMPUTE WS-TEAM-AT-BATS = WS-TEAM-AT-BATS + AT-BATS-IN
COMPUTE WS-TEAM-AVERAGE ROUNDED = WS-TEAM-HITS / WS-TEAM-AT-BATS
* CALCULATE LTL HERE
COMPUTE WS-LEAGUE-HITS = WS-LEAGUE-HITS + HITS-IN
COMPUTE WS-LEAGUE-AT-BATS = WS-LEAGUE-AT-BATS + AT-BATS-IN
COMPUTE WS-LEAGUE-AVERAGE ROUNDED = WS-LEAGUE-HITS / WS-LEAGUE-AT-BATS
* CALCULATE LOW/HIGH AVERAGES
IF WS-AVERAGE > WS-HIGHEST-AVERAGE
MOVE WS-AVERAGE TO WS-HIGHEST-AVERAGE
END-IF
IF WS-AVERAGE < WS-LOWEST-AVERAGE
MOVE WS-AVERAGE TO WS-LOWEST-AVERAGE
END-IF.
300-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
IF WS-FIRST-TIME-THRU = 'YES'
WRITE BASEBALL-RECORD-OUT
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
MOVE 1 TO LINES-PRINTED.
350-TEAM-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-HOLD-PREVIOUS-LEAGUE-IN TO ZTL-LEAGUE
MOVE WS-HOLD-PREVIOUS-TEAM-IN TO ZTL-TEAM
MOVE WS-TEAM-HITS TO ZTL-TEAM-HITS
MOVE WS-TEAM-AT-BATS TO ZTL-TEAM-AT-BATS
MOVE WS-TEAM-AVERAGE TO ZTL-TEAM-AVERAGE
MOVE TEAM-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
MOVE WS-BLANK-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 1 LINES
ADD 1 TO LINES-PRINTED
MOVE ZEROS TO WS-TEAM-HITS
MOVE ZEROS TO WS-TEAM-AT-BATS
MOVE ZEROS TO WS-TEAM-AVERAGE.
375-LEAGUE-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-HOLD-PREVIOUS-LEAGUE-IN TO LTL-LEAGUE
MOVE WS-LEAGUE-HITS TO LTL-LEAGUE-HITS
MOVE WS-LEAGUE-AT-BATS TO LTL-LEAGUE-AT-BATS
MOVE WS-LEAGUE-AVERAGE TO LTL-LEAGUE-AVERAGE
MOVE LEAGUE-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
MOVE WS-BLANK-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 1 LINES
ADD 1 TO LINES-PRINTED
MOVE ZEROS TO WS-LEAGUE-HITS
MOVE ZEROS TO WS-LEAGUE-AT-BATS
MOVE ZEROS TO WS-LEAGUE-AVERAGE.
400-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-GRAND-HITS TO TL-GRAND-HITS
MOVE WS-GRAND-AT-BATS TO TL-GRAND-AT-BATS
MOVE WS-GRAND-AVERAGE TO TL-GRAND-AVERAGE
MOVE TOTALS-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED.
425-LOW-ROUTINE.
MOVE WS-LOWEST-AVERAGE TO TL-LOW-AVERAGE
MOVE LOW-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES.
450-HIGH-ROUTINE.
MOVE WS-HIGHEST-AVERAGE TO TL-HIGH-AVERAGE
MOVE HIGH-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES.
FIRST PAGE OF DESIRED OUTPUT:
SORT is not being used correctly. The report is being printed in 120-SORT-INPUT-PROCEDURE using the fields from BASEBALL-RECORD-IN. It should be printed in 130-SORT-OUTPUT-PROCEDURE using the fields from SORT-RECORD.
Furthermore, no records are sorted because there is no RELEASE statement in the input procedure. To access records after the sort, a RETURN statement is used in the same manner as a READ statement for a sequential file.
The input procedure should be used to move the data from selected records to the sort record, after which the record is released to sort.
The output procedure may then used to produce a report from the sorted data by returning and printing each record until the there are no more sorted records.
Related
I have a program that is suppose to sort an input file (seq) and then output an RPT file.
This program code should be correct, the problem should only be in the sorting of this program.
CURRENTLY: Program will not compile.
SORT: The output records need to sort LEAGUE-S (major) in descending order. TEAM-S (intermediate) ascending order. NAME-S (minor) ascending order.
PLEASE: show in code and explain, this is my first time trying the sort a file.
SEQ:
Alonso NL SD 549 150
Altuve NL HOU 576 167
Andrus AL TEX 629 180
Aoki NL MIL 520 150
Aybar AL LAA 517 150
Belt NL SF 411 113
Beltre AL TEX 604 194
Bernadina NL WSH 227 066
Berry AL DET 291 075
Betemit AL BAL 341 089
Bloomquist NL ARI 324 098
Bourn NL ATL 624 171
Brantley AL CLE 552 159
Braun NL MIL 598 191
Butler AL KC 614 192
Cabrera AL CLE 555 150
Cabrera AL DET 622 205
Cain AL KC 222 059
Callaspo AL LAA 457 115
Cano AL NYY 627 196
Carpenter NL STL 296 087
Carroll AL MIN 470 126
Castro NL CHC 646 183
Cespedes AL OAK 487 142
Chavez AL NYY 278 078
Choo AL CLE 598 169
Ciriaco AL BOS 259 076
Colvin NL COL 420 122
Craig NL STL 469 144
Crisp AL OAK 455 118
Cruz AL TEX 585 152
Cruz NL LAD 283 084
Davis AL BAL 515 139
Davis AL TOR 447 115
De Aza AL CWS 524 147
Denorfia NL SD 348 102
Desmond NL WSH 513 150
Dirks AL DET 314 101
Dobbs NL MIA 319 091
Doumit AL MIN 484 133
Dyson AL KC 292 076
Ellsbury AL BOS 303 082
Encarnacion AL TOR 542 152
Escobar AL KC 605 177
Escobar AL TOR 558 141
Ethier NL LAD 556 158
Fielder AL DET 581 182
Forsythe NL SD 315 086
Fowler NL COL 454 136
Frandsen NL PHI 195 066
Frazier NL CIN 422 115
Freese NL STL 501 147
Gentry AL TEX 240 073
Getz AL KC 189 052
Goldschmidt NL ARI 514 147
Gomes AL OAK 279 073
Gonzalez AL BOS 484 145
Gonzalez NL COL 518 157
Gordon AL KC 642 189
Grandal NL SD 192 057
Hairston NL LAD 238 065
Hamilton AL TEX 562 160
Hanigan NL CIN 317 087
Harper NL WSH 533 144
Hart NL MIL 562 152
Headley NL SD 604 173
Hill NL ARI 609 184
Holliday NL STL 599 177
Hunter AL LAA 534 167
Infante AL DET 226 058
Infante NL MIA 328 094
Izturis AL LAA 289 074
Jackson AL DET 543 163
Jaso AL SEA 294 081
Jay NL STL 443 135
Jeter AL NYY 683 216
Johnson NL ARI 488 137
Johnson NL ATL 269 078
Jones AL BAL 648 186
Jones NL ATL 387 111
Jones NL PIT 475 130
Kemp NL LAD 403 122
Kendrick AL LAA 550 158
Keppinger AL TB 385 125
Kinsler AL TEX 655 168
Kipnis AL CLE 591 152
Konerko AL CWS 533 159
LaRoche NL WSH 571 155
Lawrie AL TOR 494 135
LeMahieu NL COL 229 068
Lind AL TOR 321 082
Lombardozzi NL WSH 384 105
Longoria AL TB 273 079
Lucroy NL MIL 316 101
Ludwick NL CIN 422 116
Machado AL BAL 191 050
Markakis AL BAL 420 125
Mauer AL MIN 545 174
McCutchen NL PIT 593 194
McLouth AL BAL 209 056
Middlebrooks AL BOS 267 077
Molina NL STL 505 159
Montero AL SEA 515 134
Montero NL ARI 486 139
Morales AL LAA 484 132
Moreland AL TEX 327 090
Morneau AL MIN 505 135
Morse NL WSH 406 118
Moss AL OAK 265 077
Murphy AL TEX 457 139
Murphy NL NYM 571 166
Nelson NL COL 345 104
Ortiz AL BOS 324 103
Pacheco NL COL 475 147
Pagan NL SF 605 174
Parra NL ARI 385 105
Pedroia AL BOS 563 163
Perez AL KC 289 087
Phillips NL CIN 580 163
Pierre NL PHI 394 121
Pierzynski AL CWS 479 133
Podsednik AL BOS 199 060
Posey NL SF 530 178
Prado NL ATL 617 186
Pujols AL LAA 607 173
Ramirez AL CWS 593 157
Ramirez NL MIL 570 171
Revere AL MIN 511 150
Reyes NL MIA 642 184
Rios AL CWS 605 184
Rizzo NL CHC 337 096
Rodriguez AL NYY 463 126
Rosario NL COL 396 107
Ross AL BOS 476 127
Ruggiano NL MIA 288 090
Ruiz NL PHI 372 121
Rutledge NL COL 277 076
Sanchez NL SF 218 061
Sandoval NL SF 396 112
Santana AL CLE 507 128
Schumaker NL STL 272 075
Scutaro NL SF 620 190
Seager AL SEA 594 154
Solano NL MIA 285 084
Span AL MIN 516 146
Stanton NL MIA 449 130
Suzuki AL NYY 629 178
Sweeney AL BOS 204 053
Swisher AL NYY 537 146
Teixeira AL NYY 451 113
Tejada NL NYM 464 134
Theriot NL SF 352 095
Trout AL LAA 559 182
Trumbo AL LAA 544 146
Tulowitzki NL COL 181 052
Upton NL ARI 554 155
Viciedo AL CWS 505 129
Votto NL CIN 374 126
Walker NL PIT 472 132
Werth NL WSH 300 090
Willingham AL MIN 519 135
Wise AL CWS 224 058
Wright NL NYM 581 178
Young AL DET 574 153
Young AL TEX 611 169
Young NL COL 174 055
Zimmerman NL WSH 578 163
Zobrist AL TB 560 151
Program:
IDENTIFICATION DIVISION.
PROGRAM-ID. BASEBALL-5.
* Tate
******************************************************************
* This program will sort different stats for different baseball
* players while keeping running totals and averages with breaks.
******************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BASEBALL-FILE-UNSORTED-IN
ASSIGN TO 'BASEBALL-5.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE
ASSIGN TO 'SORT.DAT'.
SELECT BASEBALL-FILE-IN
ASSIGN TO 'BASEBALL-5.SOR'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT BASEBALL-FILE-OUT
ASSIGN TO 'BASEBALL-5.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD BASEBALL-FILE-UNSORTED-IN.
01 BASEBALL-RECORD-UNSORTED-IN PIC X(36).
SD SORT-FILE.
01 SORT-RECORD.
05 NAME-S PIC X(18).
05 PIC XX.
05 LEAGUE-S PIC XX.
05 PIC X.
05 TEAM-S PIC XXX.
05 PIC X(10).
FD BASEBALL-FILE-IN.
01 BASEBALL-RECORD-IN.
05 NAME-IN PIC X(18).
05 PIC XX.
05 LEAGUE-IN PIC XX.
05 PIC X.
05 TEAM-IN PIC X(3).
05 PIC X(3).
05 AT-BATS-IN PIC 9(3).
05 PIC X.
05 HITS-IN PIC 9(3).
FD BASEBALL-FILE-OUT.
01 BASEBALL-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-RECORD-READ PIC X(3) VALUE 'YES'.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 WS-HOLD-PREVIOUS-TEAM-IN PIC X(3) VALUE SPACES.
01 WS-HOLD-PREVIOUS-LEAGUE-IN PIC XX VALUE SPACES.
01 WS-TEAM-HITS PIC 9(4) VALUE ZERO.
01 WS-TEAM-AT-BATS PIC 9(4) VALUE ZERO.
01 WS-TEAM-AVERAGE PIC V999 VALUE ZERO.
01 WS-AVERAGE PIC V999 VALUE ZERO.
01 WS-LEAGUE-HITS PIC 9(5) VALUE ZERO.
01 WS-LEAGUE-AT-BATS PIC 9(5) VALUE ZERO.
01 WS-LEAGUE-AVERAGE PIC V999 VALUE ZERO.
01 WS-GRAND-HITS PIC 9(6) VALUE ZERO.
01 WS-GRAND-AT-BATS PIC 9(6) VALUE ZERO.
01 WS-GRAND-AVERAGE PIC V999 VALUE ZERO.
01 WS-HIGHEST-AVERAGE PIC V999 VALUE ZERO.
01 WS-LOWEST-AVERAGE PIC V999 VALUE .999.
01 WS-BLANK-LINE PIC X(80) VALUE SPACES.
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(24) VALUE SPACES.
05 PIC X(26) VALUE 'BASEBALL PLAYER STATISTICS'.
05 PIC X(9) 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(6) VALUE 'LEAGUE'.
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE 'TEAM'.
05 PIC X(6) VALUE SPACES.
05 PIC X(4) VALUE 'NAME'.
05 PIC X(18) VALUE SPACES.
05 PIC X(4) VALUE 'HITS'.
05 PIC X(9) VALUE SPACES.
05 PIC X(7) VALUE 'AT BATS'.
05 PIC X(6) VALUE SPACES.
05 PIC X(7) VALUE 'AVERAGE'.
01 DETAIL-LINE.
05 DL-LEAGUE PIC XX.
05 BLANK-A-OUT PIC X(8) VALUE SPACES.
05 DL-TEAM PIC X(3).
05 BLANK-B-OUT PIC X(7) VALUE SPACES.
05 DL-NAME PIC X(12).
05 BLANK-C-OUT PIC X(11) VALUE SPACES.
05 DL-HITS PIC ZZ9.
05 BLANK-D-OUT PIC X(13) VALUE SPACES.
05 DL-AT-BATS PIC ZZ9.
05 BLANK-E-OUT PIC X(9) VALUE SPACES.
05 DL-AVERAGE-OUT PIC .999.
01 TEAM-TOTALS.
05 ZTL-LEAGUE PIC XX.
05 PIC X(8) VALUE SPACES.
05 ZTL-TEAM PIC X(3).
05 PIC X(7) VALUE SPACES.
05 PIC X(15) VALUE '* Team Totals *'.
05 PIC X(6) VALUE SPACES.
05 ZTL-TEAM-HITS PIC Z,ZZ9.
05 PIC X(11) VALUE SPACES.
05 ZTL-TEAM-AT-BATS PIC Z,ZZ9.
05 PIC X(9) VALUE SPACES.
05 ZTL-TEAM-AVERAGE PIC .999.
01 TOTALS-LINE.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* Final Totals *'.
05 PIC X(3) VALUE SPACES.
05 TL-GRAND-HITS PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-AT-BATS PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-AVERAGE PIC .999.
01 LOW-TOTALS.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* Low Average *'.
05 PIC X(35) VALUE SPACES.
05 TL-LOW-AVERAGE PIC .999.
01 HIGH-TOTALS.
05 PIC X(20) VALUE SPACES.
05 PIC X(16) VALUE '* High Average *'.
05 PIC X(35) VALUE SPACES.
05 TL-HIGH-AVERAGE PIC .999.
01 LEAGUE-TOTALS.
05 LTL-LEAGUE PIC XX.
05 PIC X(18) VALUE SPACES.
05 PIC X(17) VALUE '* League Totals *'.
05 PIC X(3) VALUE SPACES.
05 LTL-LEAGUE-HITS PIC ZZ,ZZ9.
05 PIC X(10) VALUE SPACES.
05 LTL-LEAGUE-AT-BATS PIC ZZ,ZZ9.
05 PIC X(9) VALUE SPACES.
05 LTL-LEAGUE-AVERAGE PIC .999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT BASEBALL-FILE-IN
OPEN OUTPUT BASEBALL-FILE-OUT
PERFORM 110-PROCESS-FILE-DATES
SORT SORT-FILE
DESCENDING KEY LEAGUE-S
ASCENDING KEY TEAM-S
ASCENDING KEY NAME-S
USING BASEBALL-FILE-UNSORTED-IN
OUTPUT PROCEDURE 140-SORT-OUTPUT-PROCEDURE
CLOSE BASEBALL-FILE-IN
CLOSE BASEBALL-FILE-OUT
STOP RUN.
110-PROCESS-FILE-DATES.
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2.
140-SORT-OUTPUT-PROCEDURE.
MOVE 'YES' TO ARE-THERE-MORE-RECORDS
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ BASEBALL-FILE-IN
AT END
PERFORM 350-TEAM-TOTALS-ROUTINE
PERFORM 375-LEAGUE-TOTALS-ROUTINE
PERFORM 400-TOTALS-ROUTINE
PERFORM 425-LOW-ROUTINE
PERFORM 450-HIGH-ROUTINE
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM.
200-PROCESS-ONE-RECORD.
IF TEAM-IN <> WS-HOLD-PREVIOUS-TEAM-IN AND WS-FIRST-RECORD-READ <> 'YES'
PERFORM 350-TEAM-TOTALS-ROUTINE
END-IF
IF LEAGUE-IN <> WS-HOLD-PREVIOUS-LEAGUE-IN AND WS-FIRST-RECORD-READ <> 'YES'
PERFORM 375-LEAGUE-TOTALS-ROUTINE
END-IF
MOVE 'NO' TO WS-FIRST-RECORD-READ
MOVE LEAGUE-IN TO WS-HOLD-PREVIOUS-LEAGUE-IN
MOVE TEAM-IN TO WS-HOLD-PREVIOUS-TEAM-IN
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
COMPUTE WS-AVERAGE ROUNDED = HITS-IN / AT-BATS-IN
MOVE LEAGUE-IN TO DL-LEAGUE
MOVE SPACES TO BLANK-A-OUT
MOVE TEAM-IN TO DL-TEAM
MOVE SPACES TO BLANK-B-OUT
MOVE NAME-IN TO DL-NAME
MOVE SPACES TO BLANK-C-OUT
MOVE HITS-IN TO DL-HITS
MOVE SPACES TO BLANK-D-OUT
MOVE AT-BATS-IN TO DL-AT-BATS
MOVE SPACES TO BLANK-E-OUT
MOVE WS-AVERAGE TO DL-AVERAGE-OUT
MOVE DETAIL-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
AFTER ADVANCING 1 LINE
ADD 1 TO LINES-PRINTED
* CALCULATE FINAL TOTALS
COMPUTE WS-GRAND-HITS = WS-GRAND-HITS + HITS-IN
COMPUTE WS-GRAND-AT-BATS = WS-GRAND-AT-BATS + AT-BATS-IN
COMPUTE WS-GRAND-AVERAGE ROUNDED = WS-GRAND-HITS / WS-GRAND-AT-BATS.
* CALCULATE ZTL HERE
COMPUTE WS-TEAM-HITS = WS-TEAM-HITS + HITS-IN
COMPUTE WS-TEAM-AT-BATS = WS-TEAM-AT-BATS + AT-BATS-IN
COMPUTE WS-TEAM-AVERAGE ROUNDED = WS-TEAM-HITS / WS-TEAM-AT-BATS
* CALCULATE LTL HERE
COMPUTE WS-LEAGUE-HITS = WS-LEAGUE-HITS + HITS-IN
COMPUTE WS-LEAGUE-AT-BATS = WS-LEAGUE-AT-BATS + AT-BATS-IN
COMPUTE WS-LEAGUE-AVERAGE ROUNDED = WS-LEAGUE-HITS / WS-LEAGUE-AT-BATS
* CALCULATE LOW/HIGH AVERAGES
IF WS-AVERAGE > WS-HIGHEST-AVERAGE
MOVE WS-AVERAGE TO WS-HIGHEST-AVERAGE
END-IF
IF WS-AVERAGE < WS-LOWEST-AVERAGE
MOVE WS-AVERAGE TO WS-LOWEST-AVERAGE
END-IF.
300-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
IF WS-FIRST-TIME-THRU = 'YES'
WRITE BASEBALL-RECORD-OUT
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
MOVE 1 TO LINES-PRINTED.
350-TEAM-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-HOLD-PREVIOUS-LEAGUE-IN TO ZTL-LEAGUE
MOVE WS-HOLD-PREVIOUS-TEAM-IN TO ZTL-TEAM
MOVE WS-TEAM-HITS TO ZTL-TEAM-HITS
MOVE WS-TEAM-AT-BATS TO ZTL-TEAM-AT-BATS
MOVE WS-TEAM-AVERAGE TO ZTL-TEAM-AVERAGE
MOVE TEAM-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
MOVE WS-BLANK-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 1 LINES
ADD 1 TO LINES-PRINTED
MOVE ZEROS TO WS-TEAM-HITS
MOVE ZEROS TO WS-TEAM-AT-BATS
MOVE ZEROS TO WS-TEAM-AVERAGE.
375-LEAGUE-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-HOLD-PREVIOUS-LEAGUE-IN TO LTL-LEAGUE
MOVE WS-LEAGUE-HITS TO LTL-LEAGUE-HITS
MOVE WS-LEAGUE-AT-BATS TO LTL-LEAGUE-AT-BATS
MOVE WS-LEAGUE-AVERAGE TO LTL-LEAGUE-AVERAGE
MOVE LEAGUE-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED
MOVE WS-BLANK-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 1 LINES
ADD 1 TO LINES-PRINTED
MOVE ZEROS TO WS-LEAGUE-HITS
MOVE ZEROS TO WS-LEAGUE-AT-BATS
MOVE ZEROS TO WS-LEAGUE-AVERAGE.
400-TOTALS-ROUTINE.
IF LINES-PRINTED > 51
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-GRAND-HITS TO TL-GRAND-HITS
MOVE WS-GRAND-AT-BATS TO TL-GRAND-AT-BATS
MOVE WS-GRAND-AVERAGE TO TL-GRAND-AVERAGE
MOVE TOTALS-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED.
425-LOW-ROUTINE.
MOVE WS-LOWEST-AVERAGE TO TL-LOW-AVERAGE
MOVE LOW-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES.
450-HIGH-ROUTINE.
MOVE WS-HIGHEST-AVERAGE TO TL-HIGH-AVERAGE
MOVE HIGH-TOTALS TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT AFTER ADVANCING 2 LINES.
FIRST PAGE OF DESIRED OUTPUT:
ARE-THERE-MORE-RECORDS = 'NO' is still true from its use in the input procedure. At the beginning of the output procedure, insert MOVE 'YES' TO ARE-THERE-MORE-RECORDS. You also need to replace the READ BASEBALL-FILE-IN with RETURN SORT-FILE, add some fields to SORT-RECORD, and use those fields for the report.
Why do you have BASEBALL-FILE-UNSORTED-IN? It doesn't have any of the fields you need to move to SORT-RECORD.
If you want to use BASEBALL-FILE-UNSORTED-IN, then don't use an input procedure. Instead change the SORT statement from INPUT PROCEDURE 120-SORT-INPUT-PROCEDURE to USING BASEBALL-FILE-UNSORTED-IN. Do not OPEN or CLOSE the file. That will be done by the runtime. Remove the 120- and 130- paragraphs.
Comment everything associated with BASEBALL-FILE-IN, except 01 BASEBALL-RECORD-IN and its data items. That effectively allows the BASEBALL-RECORD-IN data definition to be used as a replacement for SORT-RECORD. That reduces the number of changes that are needed.
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.
I wonder, what do is wrong with my code because when I compile it the error in the following lines:
hello.cob: In paragraph 'DADOS':
hello.cob:25: Error: syntax error, unexpected '(', expecting WORD
hello.cob: In paragraph 'FIM':
hello.cob:31: Error: syntax error, unexpected '('
Here the source of my program:
IDENTIFICATION DIVISION.
PROGRAM-ID. TRIANG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 BASE PIC 9(04) VALUE ZEROS.
77 ALTURA PIC 9(04) VALUE ZEROS.
77 HAREA PIC 9(06) VALUE ZEROS.
SCREEN SECTION.
01 TELA.
02 BLANK SCREEN.
02 LINE 04 COLUMN 21 VALUE
"CALCULO DA AREA DE UM TRIANGULO".
02 LINE 06 COLUMN 15 VALUE
"AUTOR: Alexandre".
02 LINE 10 COLUMN 21 VALUE "ENTRE COM O VALOR DA ALTURA...".
02 LINE 12 COLUMN 21 VALUE "ENTRE COM O VALOR DA BASE...".
02 LINE 14 COLUMN 21 VALUE "ENTRE COM O VALOR DA AREA...".
PROCEDURE DIVISION.
INICIO.
DISPLAY TELA.
DADOS.
ACCEPT(10, 51) ALTURA.
ACCEPT(12, 51) BASE.
CALCULO.
MULTIPLY BASE BY ALTURA GIVING HAREA.
DIVIDE 2 INTO HAREA.
FIM.
DISPLAY(14, 51) HAREA.
DISPLAY(24, 31) "FIM DE PROGRAMA".
STOP RUN.
Thanks for the help.
I put this 2 lines in the code:
IDENTIFICATION DIVISION.
PROGRAM-ID. TRIANG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 BASE PIC 9(04) VALUE ZEROS.
77 ALTURA PIC 9(04) VALUE ZEROS.
77 HAREA PIC 9(06) VALUE ZEROS.
77 ESPERA PIC 9(01) VALUE ZEROS.
SCREEN SECTION.
01 TELA.
02 BLANK SCREEN.
02 LINE 04 COLUMN 21 VALUE
"CALCULO DA AREA DE UM TRIANGULO".
02 LINE 06 COLUMN 15 VALUE
"AUTOR: Alexandre".
02 LINE 10 COLUMN 21 VALUE "ENTRE COM O VALOR DA ALTURA... ".
02 LINE 12 COLUMN 21 VALUE "ENTRE COM O VALOR DA BASE... ".
02 LINE 14 COLUMN 21 VALUE "ENTRE COM O VALOR DA AREA... ".
PROCEDURE DIVISION.
INICIO.
DISPLAY TELA.
DADOS.
ACCEPT ALTURA AT LINE 10 COLUMN 51.
ACCEPT BASE AT LINE 12 COLUMN 51.
CALCULO.
MULTIPLY BASE BY ALTURA GIVING HAREA.
DIVIDE 2 INTO HAREA.
FIM.
DISPLAY HAREA LINE 14 COLUMN 51.
ACCEPT ESPERA AT LINE 0 COLUMN 0.
DISPLAY "FIM DE PROGRAMA" LINE 24 COLUMN 31.
STOP RUN.
Added
77 ESPERA PIC 9(01) VALUE ZEROS.
and
ACCEPT ESPERA AT LINE 0 COLUMN 0.
but the result is 000000
I got the program to work. Almost. I don't know how to keep the screen up when the program terminates, so the result is never visible, but at least it is possible to run the program and put in the first two numbers:
IDENTIFICATION DIVISION.
PROGRAM-ID. TRIANG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 BASE PIC 9(04) VALUE ZEROS.
77 ALTURA PIC 9(04) VALUE ZEROS.
77 HAREA PIC 9(06) VALUE ZEROS.
77 DUMMY PIC 9(01) VALUE ZEROS.
SCREEN SECTION.
01 TELA.
02 BLANK SCREEN.
02 LINE 04 COLUMN 21 VALUE
"CALCULO DA AREA DE UM TRIANGULO".
02 LINE 06 COLUMN 15 VALUE
"AUTOR: Alexandre".
02 LINE 10 COLUMN 21 VALUE "ENTRE COM O VALOR DA ALTURA...".
02 LINE 12 COLUMN 21 VALUE "ENTRE COM O VALOR DA BASE...".
02 LINE 14 COLUMN 21 VALUE "ENTRE COM O VALOR DA AREA...".
PROCEDURE DIVISION.
INICIO.
DISPLAY TELA.
DADOS.
ACCEPT ALTURA AT LINE 10 COLUMN 51.
ACCEPT BASE AT LINE 12 COLUMN 51.
CALCULO.
MULTIPLY BASE BY ALTURA GIVING HAREA.
DIVIDE 2 INTO HAREA.
FIM.
DISPLAY HAREA LINE 14 COLUMN 51.
DISPLAY "FIM DE PROGRAMA" LINE 24 COLUMN 31.
ACCEPT DUMMY AT LINE 1 COLUMN 1.
STOP RUN.
A much cleaner better version:
IDENTIFICATION DIVISION.
PROGRAM-ID. TRIANG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 BASE PIC 9(04) VALUE ZEROS.
77 ALTURA PIC 9(04) VALUE ZEROS.
77 HAREA PIC 9(07) VALUE ZEROS.
77 AGAIN PIC X VALUE 'N'.
SCREEN SECTION.
01 TELA.
02 BLANK SCREEN.
02 LINE 04 COLUMN 21 VALUE
"CALCULO DA AREA DE UM TRIANGULO".
02 LINE 06 COLUMN 15 VALUE
"AUTOR: Alexandre".
02 LINE 10 COLUMN 21 VALUE "ENTRE COM O VALOR DA ALTURA [____]".
02 LINE 10 COLUMN 50 PIC ZZZ9 Using ALTURA.
02 LINE 12 COLUMN 21 VALUE "ENTRE COM O VALOR DA BASE...[____]".
02 LINE 12 COLUMN 50 PIC ZZZ9 Using BASE.
02 LINE 14 COLUMN 21 VALUE " VALOR DA AREA..".
02 LINE 14 COLUMN 48 PIC ZZZZZZ9 From HAREA.
02 LINE 16 COLUMN 21 VALUE " FINIS...[N]".
02 LINE 16 COLUMN 50 PIC X Using AGAIN.
PROCEDURE DIVISION.
INICIO.
DISPLAY TELA.
PERFORM SCREENS UNTIL AGAIN = 'Y'
STOP RUN.
SCREENS.
ACCEPT TELA.
MULTIPLY BASE BY ALTURA GIVING HAREA.
DIVIDE 2 INTO HAREA.
DISPLAY TELA.
The reason your result is "00000" is because you are not validating the input.
As your program stands the user MUST enter four digits for each value, if only three digits are entered the calculation fails.
I am in the last course I will have for COBOL in college, and I have to write interacting programs that are supposed to keep track of inventory for a business. I have reached a few parts that I am having problems with. The first is verifying that the date is between the years 2011 and 2012, and the second is that the month and day numbers are between 1-12 and 1-31, respectively. When I run my program, it always says in the error report that the year is wrong, even when I put it in right. Here is my code for that part:
WORKING-STORAGE SECTION.
05 POLI-DATE-REQUESTED-S.
10 POLI-DATE-REQUESTED-S-1 PIC XX.
10 POLI-DATE-REQUESTED-S-2 PIC XX.
10 POLI-DATE-REQUESTED-S-3 PIC XX.
10 POLI-DATE-REQUESTED-S-4 PIC XX.
SCREEN SECTION.
01 SCREEN-IMAGE.
05 BLANK SCREEN
BACKGROUND-COLOR 0.
05 LINE 02 COLUMN 02 PIC X(8)
FROM TIME-HHMMSSXX-COLONS
FOREGROUND-COLOR 15.
05 LINE 02 COLUMN 25
VALUE 'Purchase Order Line Item Maintenance'
FOREGROUND-COLOR 14.
05 LINE 02 COLUMN 70 PIC X(8)
FROM DATE-MMDDYY-SLASHES
FOREGROUND-COLOR 15.
05 LINE 04 COLUMN 02 VALUE 'FUNCTION CODE:'
FOREGROUND-COLOR 10.
05 LINE 04 COLUMN 18 PIC X(3)
USING FUNCTION-CODE-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 04 COLUMN 23 VALUE '(ADD, CHG, DEL, INQ, END)'
FOREGROUND-COLOR 11.
05 LINE 07 COLUMN 23 VALUE 'NUMBER:'
FOREGROUND-COLOR 10.
05 LINE 07 COLUMN 50 PIC X(4)
USING POLI-VEND-NUMBER-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 08 COLUMN 23 VALUE 'ORDER ID:'
FOREGROUND-COLOR 10.
05 LINE 08 COLUMN 50 PIC X(8)
USING POLI-ORDER-ID-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 09 COLUMN 23 VALUE 'LINE ITEM:'
FOREGROUND-COLOR 10.
05 LINE 09 COLUMN 50 PIC X(4)
USING POLI-LINE-ITEM-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 10 COLUMN 23 VALUE 'ITEM ID:'
FOREGROUND-COLOR 10.
05 LINE 10 COLUMN 50 PIC X(10)
USING POLI-ITEM-ID-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 11 COLUMN 23 VALUE 'QUANTITY:'
FOREGROUND-COLOR 10.
05 LINE 11 COLUMN 50 PIC X(5)
USING POLI-QUANTITY-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 12 COLUMN 23 VALUE 'DATE REQUESTED (YYYYMMDD):'
FOREGROUND-COLOR 10.
05 LINE 12 COLUMN 50 PIC X(8)
USING POLI-DATE-REQUESTED-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 13 COLUMN 23 VALUE 'QUOTED COST:'
FOREGROUND-COLOR 10.
05 LINE 13 COLUMN 50 PIC X(7)
USING POLI-QUOTED-COST-S
FOREGROUND-COLOR 15 AUTO.
05 LINE 17 COLUMN 23 VALUE 'DATE ADDED:'
FOREGROUND-COLOR 10.
05 LINE 17 COLUMN 40 PIC X(10)
USING POLI-DATE-ADDED-S
FOREGROUND-COLOR 15.
05 LINE 18 COLUMN 23 VALUE 'DATE-CHANGED:'
FOREGROUND-COLOR 10.
05 LINE 18 COLUMN 40 PIC X(10)
USING POLI-DATE-CHANGED-S
FOREGROUND-COLOR 15.
05 LINE 23 COLUMN 23 PIC X(55)
FROM ERROR-MESSAGE-S
FOREGROUND-COLOR 12.
PROCEDURE DIVISION.
900-VALIDATE-THE-FIELDS.
IF POLI-DATE-REQUESTED-S-1 IS NOT = 20
MOVE 'Year must be 2011 OR 2012' TO ERROR-MESSAGE-S
GO TO 999-EXIT
END-IF
IF POLI-DATE-REQUESTED-S-2 IS NOT = 11 OR 12
MOVE 'Year Must Be 2011 Or 2012' TO ERROR-MESSAGE-S
GO TO 999-EXIT
END-IF
IF POLI-DATE-REQUESTED-S-3 IS < 1 OR > 12
MOVE 'Month Must Be 1 Through 12' TO ERROR-MESSAGE-S
GO TO 999-EXIT
END-IF
IF POLI-DATE-REQUESTED-S-4 IS < 1 OR > 31
MOVE 'Day Must Be 1 Through 31' TO ERROR-MESSAGE-S
GO TO 999-EXIT
END-IF.
Also, I have to make sure that a record in a field called POLI-ITEM-ID already exists in another indexed file called ITEM-MASTER. I am not exactly sure how to do this, but I assume that it involves temporarily opening the file and searching it. If anyone could show me how to do this I would be grateful, as these two things seem to be the only things holding me back today. I thank everyone for all the help in advance.
Edit: The input data is written on a screen image that is part of the program. Thus I know that what I put in in correct at the time of entry. If it helps, I have put the SCREEN SELECTION in the code, but I do not think it has any bearing on why my date entry is considered an error (i.e. I put in "2011" and it tells me on the screen "Year must be 2011 OR 2012").
05 POLI-DATE-REQUESTED-S.
10 POLI-DATE-REQUESTED-S-1 PIC 9999.
88 Year-Valid value 2011 thru 2012.
10 POLI-DATE-REQUESTED-S-2 PIC 99.
88 Month-Valid value 01 thru 12.
10 POLI-DATE-REQUESTED-S-4 PIC 99.
88 Day-Valid value 01 thru 31.
Try redefining your fields like this. Then you can do a simple test of the fields with:
IF not Year-Valid
MOVE 'Year must be 2011 OR 2012' TO ERROR-MESSAGE-S
Else
IF not Month-Valid
MOVE 'Month Must Be 1 Through 12' TO ERROR-MESSAGE-S
Else
IF not Day-Valid
MOVE 'Day Must Be 1 Through 31' TO ERROR-MESSAGE-S
END-IF
END-IF
END-IF
To deal with your lookup, do a direct read on the ITEM-MASTER file. That will involve something like this:
SELECT ITEM-MASTER ASSIGN TO "fname.txt"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS ITEM-MASTER-KEY.
and then do a direct read:
READ ITEM-MASTER
KEY IS POLI-ITEM-ID
INVALID KEY DISPLAY "error or something"
END-READ
Be careful - the accepted solution does not guarantee numeric values.
The following program illustrates the point:
PROGRAM-ID. EXAMPLE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TXT-VALUE PIC X(4).
01 NUM-VALUE PIC 9(4).
88 WS-VALID-NUM VALUE 2000 THRU 2999.
PROCEDURE DIVISION.
MOVE '21b1' TO TXT-VALUE
MOVE TXT-VALUE TO NUM-VALUE
DISPLAY 'NUM-VALUE: ' NUM-VALUE
IF WS-VALID-NUM
DISPLAY 'passed the range test.'
END-IF
IF NUM-VALUE IS NUMERIC
DISPLAY 'passed numeric test.'
ELSE
DISPLAY 'failed numeric test.'
END-IF
Which results in the following output:
NUM-VALUE: 21b1
passed the range test.
failed numeric test.
Lesson: Always validate numeric fields with an IS NUMERIC test and then a range test.
Furthermore, unless input data have been pre-edited for validity,
it is not a good idea to read external data directly into numeric
data types. Reading '1b' from an
input file directly into a PIC 9(2) data item yields the value 12 (in an ebcdic based
environment). This will now pass an IS NUMERIC test as well as range tests even though
the actual input data were not numeric. The reasons for the "automatic" conversion are
a bit beyond this discussion - lets just say data movement rules in COBOL are
much more complex than most people appreciate.
Joe Zitzelberger's post is the recommended and 'clean' way to do this.
I would just point out that the error in your original code was to mix up XX and numeric types. You should either have used character literals in your tests:
IF POLI-DATE-REQUESTED-S-1 IS NOT = '20'
or, better, defined your data values as numbers:
10 POLI-DATE-REQUESTED-S-1 PIC 99.
01 FILLER.
05 POLI-DATE-REQUESTED-S.
10 POLI-DATE-REQUESTED-S-1 PIC XXXX.
88 YEAR-VALID VALUE "2011" THRU "2012".
10 POLI-DATE-REQUESTED-S-2 PIC XX.
88 MONTH-VALID VALUE "01" THRU "12".
88 MONTH-IS-FEB VALUE "02".
88 MONTH-IS-30-DAYS VALUE "04" "06" "09" "11".
10 POLI-DATE-REQUESTED-S-4 PIC XX.
88 DAY-MAY-BE-VALID VALUE "01" THRU "31".
88 VALID-FEB-DAYS VALUE "01" THRU "28".
88 VALID-30-DAYS VALUE "01" THRU "30".
Then the "first cut", with a student who doesn't have to worry about the actual number of days a month has:
MOVE SPACE TO ERROR-MESSAGE-S
EVALUATE TRUE
WHEN NOT POLI-DATE-REQUESTED-S NUMERIC
MOVE 'DATE MUST ONLY BE NUMBERS'
TO ERROR-MESSAGE-S
WHEN NOT YEAR-VALID
MOVE 'YEAR MUST BE 2011 OR 2012'
TO ERROR-MESSAGE-S
WHEN NOT MONTH-VALID
MOVE 'MONTH MUST BE 01 THROUGH 12'
TO ERROR-MESSAGE-S
WHEN NOT DAY-MAY-BE-VALID
MOVE "DAY IS ZERO OR MORE THAN 31"
TO ERROR-MESSAGE-S
END-EVALUATE
And then amended later for the actual number of days.
MOVE SPACE TO ERROR-MESSAGE-S
EVALUATE TRUE
WHEN NOT POLI-DATE-REQUESTED-S NUMERIC
MOVE 'DATE MUST ONLY BE NUMBERS'
TO ERROR-MESSAGE-S
WHEN NOT YEAR-VALID
MOVE 'YEAR MUST BE 2011 OR 2012'
TO ERROR-MESSAGE-S
WHEN NOT MONTH-VALID
MOVE 'MONTH MUST BE 01 THROUGH 12'
TO ERROR-MESSAGE-S
WHEN NOT DAY-MAY-BE-VALID
MOVE "DAY IS ZERO OR MORE THAN 31"
TO ERROR-MESSAGE-S
WHEN ( MONTH-IS-FEB
AND NOT VALID-FEB-DAYS )
MOVE 'TOO MANY DAYS FOR FEBRUARY'
TO ERROR-MESSAGE-S
WHEN ( MONTH-IS-30-DAYS
AND NOT VALID-30-DAYS )
MOVE 'NO 31ST THIS MONTH'
TO ERROR-MESSAGE-S
END-EVALUATE
Hey all, I got one more assignment to complete for the quarter in COBOL and I am out. The thing is I am getting a syntax error at the ACCEPT SCREEN-IMAGE command and this program needs to have user input. I don't see what I am doing wrong so I am stuck. I believe that everything else is put in right so once this is figured out I am done. Here is the code:
SCREEN SECTION.
01 SCREEN-IMAGE.
05 BLANK SCREEN
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
05 LINE 02 COLUMN 02 PIC X(8)
FROM CURRENT-TIME.
05 LINE 02 COLUMN 26 PIC X(28)
FROM TITLE-LINE
FOREGROUND-COLOR 09.
05 LINE 02 COLUMN 40 PIC X(8)
FROM DATE-TODAY.
05 LINE 05 COLUMN 02
VALUE 'FUNCTION CODE:'
FOREGROUND-COLOR 09.
05 LINE 05 COLUMN 12 PIC X(3)
FROM CODE-SCREEN AUTO.
05 LINE 05 COLUMN 17
VALUE '<ADD, CHG, DEL, INQ, END>'.
05 LINE 09 COLUMN 17
VALUE 'REP CODE:'
FOREGROUND-COLOR 09.
05 LINE 09 COLUMN 29 PIC X(3)
FROM REP-SCREEN AUTO.
05 LINE 11 COLUMN 17
VALUE 'NAME:'
FOREGROUND-COLOR 09.
05 LINE 11 COLUMN 29 PIC X(3)
FROM NAME-SCREEN AUTO.
05 LINE 13 COLUMN 17
VALUE 'DISTRICT:'
FOREGROUND-COLOR 09.
05 LINE 13 COLUMN 29 PIC X(3)
FROM DIST-SCREEN AUTO.
05 LINE 15 COLUMN 17
VALUE 'COMMISSION RATE:'
FOREGROUND-COLOR 09.
05 LINE 15 COLUMN 29 PIC X(3)
FROM COM-SCREEN AUTO.
05 LINE 17 COLUMN 17
VALUE 'DATE ADDED:'
FOREGROUND-COLOR 09.
05 LINE 17 COLUMN 29 PIC X(10)
FROM ADD-DATE.
05 LINE 19 COLUMN 17
VALUE 'DATE CHANGED:'
FOREGROUND-COLOR 09.
05 LINE 19 COLUMN 29 PIC X(3)
FROM CHANGE-DATE.
05 LINE 24 COLUMN 17 PIC X(29)
FROM ERROR-DISPLAY.
PROCEDURE DIVISION.
100-MAIN.
OPEN I-O REP-MASTER-FILE
CALL 'DATETIME' USING DATE-TIME-PASS-AREA
MOVE DATE-MMDDYY-SLASHES TO DATE-TODAY
MOVE TIME-HHMMSSXX-COLONS TO CURRENT-TIME
PERFORM UNTIL CODE-SCREEN = 'END' OR 'end'
DISPLAY SCREEN-IMAGE
ACCEPT SCREEN-IMAGE
MOVE 0 TO ERROR-COUNT
PERFORM 150-CHECK-COM
PERFORM 140-CHECK-DIST
PERFORM 130-CHECK-NAME
PERFORM 120-CHECK-REP
PERFORM 110-CHECK-CODE
IF ERROR-COUNT = 0
PERFORM 200-PROCESS-ONE-RECORD
END-IF
END-PERFORM
CLOSE REP-MASTER-FILE
STOP RUN.
Any and all help will be appreciated.
#Gabe Contrary to what many people believe, a period (full stop) is not the only way to end a statement in COBOL.
Move A To B
Move C To D
is logically equivalent to
Move A To B.
Move C To D.
Where it gets squirrelly is
If A = B
Move C To D
Add 1 To E.
If I put a period after the D, 1 will be added to E unconditionally. The COBOL 85 standard added explicit scope terminators to many statements, so we got the more easily visually parsed construct
If A = B
Move C To D
Add 1 To E
End-If
Now if I put a period after the D I will get a compile error. Most COBOL programmers I know now use explicit scope terminators and only end paragraph names and paragraphs with a period, otherwise banishing them from the Procedure Division.
Maybe you need a few input and/or update fields on your screen in order to ACCEPT it? I think input fields have a TO phrase in their descriptions and update fields have a USING phrase. The only thing I see in your screen description are literals and FROM phrases. Basically, nothing to ACCEPT!