title: How to sort a table in COBOL?
body: <p>I am learning COBOL, and I am having difficulty trying to figure out how to sort this table. I don't think I am even implementing this table correctly, so any help on how to improve this code would be great. I am lost and confused. </p>
  
  <pre><code>IDENTIFICATION DIVISION.
  PROGRAM-ID. STUDENT.
  
  DATA DIVISION. 
  WORKING-STORAGE SECTION.
  01 CLASSROOM-TABLE.
      05 STUDENT OCCURS 5 TIMES. 
          10 STUDENT1.
              15 STUDENT1-N PIC A(25).
              15 STUDENT1-A PIC 99. 
          10 STUDENT2.
              15 STUDENT2-N PIC A(25).
              15 STUDENT2-A PIC 99. 
          10 STUDENT3.
              15 STUDENT3-N PIC A(25).
              15 STUDENT3-A PIC 99. 
          10 STUDENT4.
              15 STUDENT4-N PIC A(25).
              15 STUDENT4-A PIC 99. 
          10 TEMP-STUDENT.
              15 STUDENT-N PIC A(25).
  FIND.
  
  END-METHOD.
              15 STUDENT-A PIC 99. 
  01 I PIC 9 VALUE 0. 
  01 J PIC 9 VALUE 1.
  
  PROCEDURE DIVISION. 
  MAIN-PARA.
      MOVE "MICHAELA" TO STUDENT (1) (1:25).
      MOVE 21 TO STUDENT (1) (26:2).
      MOVE "KEVIN" TO STUDENT (2) (1:25).
      MOVE 25 TO STUDENT (2) (26:2).
      MOVE "KENNY" TO STUDENT (3) (1:25).
      MOVE 16 TO STUDENT (3) (26:2). 
      MOVE "ANDREA" TO STUDENT (4) (1:25).
      MOVE 18 TO STUDENT (4) (26:2). 
  
      PERFORM PUT-ORDER.
      PERFORM PRINT.
  STOP RUN. 
  
  PUT-ORDER.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I &gt; 4
      ADD 1 TO J  
      IF STUDENT(I)(26:2) &gt; STUDENT(J)(26:2)
          ADD 1 TO I
          DISPLAY "INSIDE SORT"
          MOVE STUDENT(I)(26:2) TO STUDENT(5)(26:2)
          MOVE STUDENT(J)(26:2) TO STUDENT(I)(26:2)
          MOVE STUDENT(5)(26:2) TO STUDENT(J)(26:2)
      END-IF
  END-PERFORM.
  
  DISPLAY "SORT IS DONE".
  
  END-METHOD.
  
  PRINT.
      DISPLAY STUDENT (1).
      DISPLAY STUDENT (2).
      DISPLAY STUDENT (3).
      DISPLAY STUDENT (4).
      END-METHOD.
  </code></pre>
  
  <p>I know that the code is getting to the sort, since it prints both inside sort and sort is done. But when it prints the table again, everything is the same. I don't think I'm iterating through the table correctly, but all other ways I've tried gives me errors. </p>