View previous topic :: View next topic
|
Author |
Message |
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 -
|
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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.
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Isn't an external sort more efficient than an internal bubble sort? |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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.
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 |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi all,
Thanks a lot for the replies.
Thanks,
Sree |
|
Back to top |
|
|
Sandy Zimmer
Active Member
Joined: 13 Jun 2007 Posts: 826 Location: Wilmington, DE
|
|
|
|
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 |
|
|
|