       Identification Division.
       Program-ID. SORT0001.
       Data Division.
       Working-Storage Section.
       01  WORK-AREAS.
           05  SUB-03 PIC 9999 COMP.
           05  SUB-05 PIC 9999 COMP.
           05  SUB-99 PIC 9999.
           
       01  TABLE-01.
           03  TABLE-03 OCCURS 5 TIMES.
               05  TABLE-05 OCCURS 10 TIMES  ascending key key-var.
                   07  KEY-VAR PIC X(05).
                   07  SM-ELEM PIC X(04).
       Procedure Division.
      * Load the table with some data
       PERFORM VARYING SUB-03 FROM 1 BY 1 UNTIL SUB-03 > 5
         PERFORM VARYING SUB-05 FROM 1 BY 1 UNTIL SUB-05 > 10
           MOVE SUB-03 TO SUB-99
           MOVE SUB-99(2:3) TO KEY-VAR(SUB-03,SUB-05)(1:3)
           MOVE SUB-05 TO SUB-99
           MOVE SUB-99(3:2) TO KEY-VAR(SUB-03,SUB-05)(4:2)
           MOVE SPACES TO SM-ELEM(SUB-03,SUB-05)
         END-PERFORM
       END-PERFORM
    
      * Sort each instance of TABLE-05
      * I'm using DESCENDING to show that the SORT 
      * actually worked
       PERFORM VARYING SUB-03 FROM 1 BY 1 UNTIL SUB-03 > 5
         SORT TABLE-05 (SUB-03) ON DESCENDING KEY-VAR
       END-PERFORM
    
      * Display the data
       PERFORM VARYING SUB-03 FROM 1 BY 1 UNTIL SUB-03 > 5
         PERFORM VARYING SUB-05 FROM 1 BY 1 UNTIL SUB-05 > 10
           DISPLAY 'KEY-VAR(' SUB-03 ',' SUB-05 ') ' 
             KEY-VAR(SUB-03,SUB-05)
         END-PERFORM
       END-PERFORM
    
       GOBACK.
