|
Hello, Sharuti.
I don't have a compiler handy, but from what I've seen, everything can be done in one program using tables. If you have the same paragraph names in the main and nested program, the compiler may not be able to resolve the addresses; just rename the paragraphs, prefixing them with M in the main and S in the sub-program.
From what I can see, you are expecting 20 scores (with a divisor of 19 indicating that the lowest score has been dropped). The easiest way is with a sort using and giving, dumping the scores into a table from which you will list the top 19. A slightly more onerous way is with two swap tables, similar to a bubble sort.
No matter what, there should be a single field that holds all 9s. When you read a score, you check against that field. In all probability, the first score will be less than the initial field value. The score is then moved into the field. Without writing th entire program, this would appear in the working-storage section: 77 SCORE-FLAG PIC X VALUE "N". 77 LOW-SCORE PIC S9(7)v9(6) COMP-3 VALUE 9999999.999999. 77 LOW-SCORE-INDX PIC S9(4) COMP VALUE 1. 77 SCORE-INDX PIC s9(4) COMP. 77 SCORE-INDX-LIMIT PIC S9(3) COMP-3 VALUE 20. 01 SCORE-TABLE. 05 ST-SCORE OCCURS 20 TIMES PIC S9(7)v9(6) COMP-3. Start something like this: PROCEDURE DIVISION. M1-HOUSEKEEPING. MOVE "N" TO SCORE-FLAG. MOVE ZEROES TO SCORE-INDX. PERFORM UNTIL SCORE-INDX IS GREATER THAN SCORE-INDX-LIMIT MOVE ZEROES TO ST-SCORE (SCORE-INDX) END-PERFORM. OPEN INPUT SCORE-FILE. MOVE ZEROES TO SCORE-INDX. PERFORM M2-BUILD-TABLE UNTIL SCORE-FLAG IS EQUAL TO "Y". CLOSE SCORE-FILE. OPEN OUTPUT REPORT-FILE. MOVE "N" TO SCORE-FLAG. PERFORM N3-WRITE-REPORT UNTIL SCORE-FLAG IS EQUAL TO "Y". CLOSE REPORT-FILE. GOBACK.
M2-BUILD-TABLE. READ SCORE-FILE AT END MOVE "Y" TO SCORE-FLAG. IF SCORE-FLAG IS EQUAL TO "N" IF SCORE-INDX IS NOT GREATER THAN SCORE-INDX-LIMIT IF SCORE-FILE-SCORE IS LESS THAN LOW-SCORE MOVE SCORE-FILE-SCORE TO LOW-SCORE ADD 1 TO SCORE-INDX MOVE SCORE-INDX TO LOW-SCORE-INDX MOVE SCORE-FILE-SCORE TO ST-SCORE (SCORE-INDX) ELSE MOVE "Y" TO SCORE-FLAG. M2-EXIT.
At this point, all the scores are in the table and the lowest score has been selected. In addition, all 20 scores have been processed.
If you want to print the scores as they were entered, (for example, 80, 92, 87, 72, 65, 98), the lowest score in that list has an index of 5. Just bypass the fifth entry and print the scores. When printing the lowest score, use the LOW-SCORE-INDX to print the lowest entry.
The code above is the way I coded for 25 years; I don't use what's not necessary. The COBOL AND is the same thing as an IF within an IF. The COBOL OR is the same thing as IF-ELSE. If I don't have an else statement, I don't use ELSE. I also use flags (bits) that will be yes-no or on-off; that's the purpose of the SCORE-FLAG above.
See how this works. I never used nested programs, preferring separate sub-programs that could be used by other routines. One bad thing about writing in this is that there are no indents, so you'll have to reformat the code to match what you are doing. Also, the entire working storage section dealing with the front end can be coded in one level-01.
Good luck.
|