Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a TSQ 1

Status
Not open for further replies.

vinodknv

Programmer
Apr 10, 2007
3
US
Could someone help me out in sorting a TSQ in COBOL/CICS?
 
Unless someone has a better option, usually the thing that's done is to pull it into memory, sort it there, and then write the TSQ back out.

The first question, perhaps, is how big is this TSQ, and what is it being used for? Perhaps there's a better option out there?

Of course, the best way to do it is something that's a definite question in my mind. But depending on what you need, it could be done.
 
I'm expecting around 400 entries to be present in the TSQ.
 
When I asked the "how big is the TSQ" question, I was thinking more along the lines of memory size more than number of entries. And the "what it is being used for" question is rather important. If this is a disk TSQ that needs sorted periodically, perhaps it might be better to set up a batch process using a sorting tool. If it's a temporary memory TSQ, you could always pull it in, sort it, and then rewrite it. But the best answer to this question really depends on where the data came from to begin with. But for the memory sort, this should give you a decent start:

Code:
        CBL NOSSRANGE
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SEDET003.
   *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * COMB SORT WITH INDEXES
      * By Glenn9999@tek-tips.com      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      
       01  SORT-TABLE-ITEMS.
           04  SORT-TABLE PIC 9(5) OCCURS 1    TIMES
                          INDEXED BY I
                                     SWAP-NUMBER.
      
       01  TEST-VARS.
           04  IN-TIME          PIC 9(8).
           04  GEN-COUNTER      PIC S9(5) COMP-3.
           04  COUNTER-1        PIC S9(5) COMP-3.
           04  COUNTER-2        PIC S9(5) COMP-3.
      
       01  SORT-PROC-VARS.
           04  SWAP-VALUE        PIC 9(5).
           04  JUMP-SIZE         PIC S9(5) COMP-3.
           04  TABLE-SIZE        PIC S9(5) COMP-3.
           04  UPPER-LIMIT       PIC S9(5) COMP-3.
           04  TABLE-RIGHT       PIC S9(5) COMP-3 VALUE 1000.
           04  SWAP              PIC X.         
       
      *----------------------------------------------------------------
       PROCEDURE DIVISION.
       0000-START-SECTION.
           ACCEPT IN-TIME FROM TIME.
           DISPLAY "BEFORE: " IN-TIME.
           PERFORM VARYING GEN-COUNTER FROM 1 BY 1 UNTIL GEN-COUNTER > 1   
              MOVE 1 TO COUNTER-1
              PERFORM VARYING COUNTER-2 FROM 1   
                     BY -1 UNTIL COUNTER-2 < 1
                 MOVE COUNTER-2 TO SORT-TABLE (COUNTER-1)
                 ADD 1 TO COUNTER-1
              END-PERFORM
              PERFORM 1000-QUICKSORT
           END-PERFORM.
           ACCEPT IN-TIME FROM TIME.
           DISPLAY "AFTER: " IN-TIME.
      *    PERFORM 0600-DISPLAY.
           GOBACK.
      
       0600-DISPLAY SECTION.
           PERFORM VARYING GEN-COUNTER FROM 1 BY 1 UNTIL GEN-COUNTER > 1   
              DISPLAY GEN-COUNTER ': ' SORT-TABLE (GEN-COUNTER)
           END-PERFORM.
      
       1000-QUICKSORT SECTION.
           MOVE TABLE-RIGHT TO TABLE-SIZE.
           MOVE TABLE-SIZE TO JUMP-SIZE.
           PERFORM 1100-SORT-1 UNTIL (SWAP = 'Y') AND (JUMP-SIZE < 2).
           
       1100-SORT-1 SECTION.
           COMPUTE JUMP-SIZE = (10 * JUMP-SIZE + 3) / 13.
           COMPUTE UPPER-LIMIT = TABLE-SIZE - JUMP-SIZE.
           MOVE 'Y' TO SWAP.
           PERFORM 2000-SORT-2 VARYING I FROM 1 BY 1
                   UNTIL I > UPPER-LIMIT.
      
       2000-SORT-2 SECTION.
           SET SWAP-NUMBER TO I.
           SET SWAP-NUMBER UP BY JUMP-SIZE.
           IF SORT-TABLE (I) > SORT-TABLE (SWAP-NUMBER)
               MOVE SORT-TABLE (I) TO SWAP-VALUE
               MOVE SORT-TABLE (SWAP-NUMBER) TO SORT-TABLE (I)
               MOVE SWAP-VALUE TO SORT-TABLE (SWAP-NUMBER)
               MOVE 'N' TO SWAP
           END-IF.
 
Thank you!

I'll be using temporary memory TSQ. Help provided by you will do the job for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top