Warning: I have limited knowledge of tables!
I have a COBOL program that calculates GPAs on the fly in the OUTPUT section of the program. I have to store these on-the-fly GPAs in a table, and then sort them by school, grade level, GPA total, then student id. I can load my table, but I am not sorting it.
01 GPATBL. 03 GPAENTRY OCCURS 5000 TIMES ASCENDING KEYS GPACT1 GPAGRD GPATOTAL INDEXED BY GPA1 GPA2. 05 GPASCHOOL PIC X(04). 05 GPAGRADE PIC X(02). 05 GPATOTAL PIC S9(01)V9999. 05 GPASTUDENT PIC X(10). 05 GPANAME PIC X(33).
I load the table right after the GPA is calculated on-the-fly. The program is already sorting the basic data that was gathered in the INPUT section (school, grade, student number, and name (GPA is calculated on-the-fly in the OUTPUT section). So my table is being loaded by school, grade level, student id as the data is released from the sort record in the OUTPUT section.
How do I sort my table by school, grade level, GPA, then student number? I've looked at other forums and read about bubble sorts, sort verb, etc, but none of it makes any sense to me. I have read two COBOL books with chapters on tables and sorting. I think I need to do the "bubble sort", but I dont know where to begin. I follow the logic behind it (ascending key): store the 1st value, then check the 2nd value to see if its great than the 1st stored value, if it is, move 2nd value into table slot 2 else move 1st value to table slot 2 and store 2nd value in table slot 1.
iSeries Pwr6, IBM COBOL/400 compiler
February 18, 2011 9:38 PM
March 2, 2011 3:17 PM