HP3000-L Archives

October 2002, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Michael Berkowitz <[log in to unmask]>
Reply To:
Michael Berkowitz <[log in to unmask]>
Date:
Thu, 3 Oct 2002 12:22:09 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (74 lines)
Raghu Rao writes

Hi all,

Is there anyway that I can SORT a RECORD in a COBOL program (without using a
FILE).

I have a working storage record BUFFER-DATA of 160 bytes which occurs 1000
times as an array. I have my key values as Account (first 12 char) and
Invoice (next 10 Char). I am reading my data from database through DBGET,
processing it and moving it into buffer. This data is not sorted. I would
like to sort it based on Account and then on Invoice.

How do I sort this BUFFER-DATA ? Any idea ?
----------------------------------------------------
Well you could use a COBOL 2002 compliant compiler with a built in bubble
sort, or use this bubble sort logic I got at
http://www.softechsolutions.com/techtips/ttipsort.htm

   Working Storage Entries:

       01  WS-BANKBRCH-TABLE.
           05  WS-BANKBRCH-ENTRY                   OCCURS 1000 TIMES
                                                   INDEXED BY
                                                   X-WS-BB.
               07  WS-BANKBRCH-9-16    PIC 9(16).
               07  WS-BANKBRCH-9-16-R      REDEFINES WS-BANKBRCH-9-16.
                   09  WS-BANKBRCH-FR  PIC 9(08).
                   09  WS-BANKBRCH-FR-R    REDEFINES WS-BANKBRCH-FR.
                       11  WS-BANK-FR  PIC 9(04).
                       11  WS-BRCH-FR  PIC 9(04).
                   09  WS-BANKBRCH-TO  PIC 9(08).
                   09  WS-BANKBRCH-TO-R    REDEFINES WS-BANKBRCH-TO.
                       11  WS-BANK-TO  PIC 9(04).
                       11  WS-BRCH-TO  PIC 9(04).
       01  WS-BUBBLE-SORT-WORK.
           05  WS-TIMES                PIC S9(04)      COMP VALUE ZEROS.
           05  WS-NBR-TIMES            PIC S9(04)      COMP VALUE ZEROS.
           05  WS-HOLD-ENTRY           PIC X(16)       VALUE LOW-VALUES.
           05  WS-SWAP-OCCURRED        PIC X(01)       VALUE SPACE.

   Procedure Code

           MOVE 1                   TO WS-TIMES.
           MOVE 'Y'                 TO WS-SWAP-OCCURRED.
           PERFORM UNTIL WS-SWAP-OCCURRED = 'N'
              SET X-WS-BB           TO 1
              MOVE 'N'              TO WS-SWAP-OCCURRED
              COMPUTE WS-NBR-TIMES = 1000 - WS-TIMES
              PERFORM WS-NBR-TIMES TIMES
                 IF WS-BANKBRCH-9-16 (X-WS-BB + 1) NOT = ZEROS
                    IF WS-BANKBRCH-FR (X-WS-BB) GREATER THAN
                                   WS-BANKBRCH-FR (X-WS-BB + 1)
                    OR WS-BANKBRCH-9-16 (X-WS-BB) = ZEROS
                       MOVE WS-BANKBRCH-ENTRY (X-WS-BB)
                                   TO WS-HOLD-ENTRY
                       MOVE WS-BANKBRCH-ENTRY (X-WS-BB + 1)
                                   TO WS-BANKBRCH-ENTRY (X-WS-BB)
                       MOVE WS-HOLD-ENTRY TO
                                   WS-BANKBRCH-ENTRY (X-WS-BB + 1)
                       MOVE 'Y'    TO WS-SWAP-OCCURRED
                    END-IF
                 END-IF
                 SET X-WS-BB       UP BY 1
              END-PERFORM
              ADD 1                TO WS-TIMES
           END-PERFORM.

Mike Berkowitz
Guess? Inc.

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2