Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sorted a COBOL array using Bubble sort

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 50
Location: London

PostPosted: Wed Jul 04, 2007 10:36 am    Post subject: Sorted a COBOL array using Bubble sort
Reply with quote

hi,

I have an array which occurs 5 times.
01 WS-ARRAY
02 WS-ARRAY1 occurs 5 times pic x(1).

values in array are
9
3
SPACE
1
4

Now i sorted that array using Bubble sort
after that i am getting the sorted array as follows
SPACE
1
3
4
9

but i want the space to be in last.i.e.
1
3
4
9
space

Please help me out in this

Thanks,
Sree
Back to top
View user's profile Send private message

murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Wed Jul 04, 2007 10:46 am    Post subject:
Reply with quote

Sree,

The hexa value of space is X'40' whereas for the numeric data hexa starts at X'F0'. That is the reason you are getting the array as -

Code:

b (SPACE)
1
3
4
9
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Wed Jul 04, 2007 4:16 pm    Post subject:
Reply with quote

Please see if this program meets your requirement. It uses alternate collating seqeunce "SORT-SEQ" so that 'space' comes after the numbers. Modify it as per your need.
Array-2 is your input array.

Good luck with your program. icon_smile.gif

Code:
IDENTIFICATION DIVISION.                     
PROGRAM-ID. TEST2.                           
ENVIRONMENT DIVISION.                         
CONFIGURATION SECTION.                       
OBJECT-COMPUTER. IBMMF.                       
SPECIAL-NAMES.                               
      ALPHABET SORT-SEQ IS "0123456789 ".   
INPUT-OUTPUT SECTION.                         
FILE-CONTROL.                                 
    SELECT SORT-FILE ASSIGN TO SORTFILE.     
DATA DIVISION.                               
FILE SECTION.                                 
SD SORT-FILE.                                 
01 ARRAY-1.                                   
   05 ELEMENT PIC X(01).                     
WORKING-STORAGE SECTION.                     
01 ARRAY-2 VALUE '93  654321'.               
   05 ELEMENT1 PIC X(01) OCCURS 10 TIMES.     
01 I PIC 99.                                             
PROCEDURE DIVISION.                                       
     DISPLAY 'IN THE PROGRAM'.                           
     SORT SORT-FILE ON ASCENDING KEY ELEMENT             
        COLLATING SEQUENCE IS SORT-SEQ                   
        INPUT PROCEDURE IS RELEASE-PARA                   
        OUTPUT PROCEDURE IS RETURN-PARA.                 
     DISPLAY SORT-RETURN.                                 
     DISPLAY 'SORTED ARRAY:' ARRAY-2.                     
     STOP RUN.                                           
RELEASE-PARA.                                             
     PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10           
       RELEASE ARRAY-1 FROM ELEMENT1(I)                   
     END-PERFORM.                                         
RETURN-PARA.                                             
     PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10           
       RETURN SORT-FILE RECORD  INTO ELEMENT1(I)         
        AT END DISPLAY 'SORT COMPLETED'                   
       END-RETURN                   
     END-PERFORM.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Jul 04, 2007 8:18 pm    Post subject:
Reply with quote

Isn't an external sort more efficient than an internal bubble sort?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Wed Jul 04, 2007 10:46 pm    Post subject:
Reply with quote

stodolas wrote:
Isn't an external sort more efficient than an internal bubble sort?

This has been debated many times before, please search the topics to get more information.
By the way, if you read the original question more carefully, you will see that it is not about FILE sorting.. icon_cool.gif
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jul 04, 2007 11:12 pm    Post subject:
Reply with quote

Hello,

The posted altseq may not work if the data contains other than the digits 0-9 and blank.

Should letters sort before or after numbers when they are part of the data? How should upper/lower case values be sorted?

Unless the number of values to be sorted is rather large, it will cost more system resources (cpu & i/o) to invoke the SORT than to just order the values in your code. The good news is that the SORT will always work and is easily modified if the sorting requirements change.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Thu Jul 05, 2007 11:30 am    Post subject:
Reply with quote

dick scherrer wrote:
The posted altseq may not work if the data contains other than the digits 0-9 and blank.

yes I am aware of that. icon_smile.gif
Please read my note for OP.
Quote:
Modify it as per your need.

I just tried to give direction towards the solution, as "special names" feature is seldomly used (Atleast in my shop) and many people don't know it actually.
Back to top
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 50
Location: London

PostPosted: Thu Jul 05, 2007 3:04 pm    Post subject: Re: Sorted a COBOL array using Bubble sort
Reply with quote

Hi all,

Thanks a lot for the replies.


Thanks,
Sree
Back to top
View user's profile Send private message
Sandy Zimmer

Active Member


Joined: 13 Jun 2007
Posts: 826
Location: Wilmington, DE

PostPosted: Sat Jul 07, 2007 2:30 am    Post subject:
Reply with quote

If your tiny-tiny table will always only occur 5 times, or is very limited, why not use Shell-Metzner? You did not indicate how the table is loaded? When loading it, always check for spaces - if spaces, move high values to the occurence before the sort. BTW - you are using a lot of system overhead for that tiny little array.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Innovations in Your Mainframe Sort Arun Raj PC Guides & IT News 4 Wed Mar 15, 2017 10:38 pm
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts SORT requirement sjiraga COBOL Programming 6 Thu Mar 09, 2017 9:11 pm
No new posts SORT to append Month and YEAR in MMYY... tisamf DFSORT/ICETOOL 1 Wed Mar 08, 2017 4:46 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us