Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Sorting in Alphanumeric Items

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

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Sat Jan 05, 2008 3:04 pm    Post subject: Sorting in Alphanumeric Items
Reply with quote

Hi I have a requirement,

In My program i have an internal table that contains the tags:

This Tag ID is declared as PIC X(30) and it contains the following values

column1, column3 , column2, etc till column25. (name is as it appears)

They are all jumbled up inside the table

I would like to have it sorted as

column1 , column2, etc ... in an ascending order.

I did a bubble sort, but it appears like this

column1, column10, column11, column12, column2 etc

can anyone suggest how the sort can be accomplished. i would like the solution ASAP

thanks
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Sat Jan 05, 2008 3:19 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

You are getting what You asked for, exactly that ...
an alphanumeric sort

the reasonable expectation is to have the x picture fields filled with blanks x'40'

in the EBCDIC collating sequence the blanks(x'40') come before the alphanumeric chars

what You are asking for is not an alphanumeric sort, but some kind of tokenized sort

which means..
split the whole field in alphanumeric and numeric subfields properly aligned
and then carrying on the sort

in your sample means build an auxiliary array with

Code:
row   1 - "column" "001"
row   2 - "column" "002"
....
row  10 - "column" "010"
...
row nnn - "column" "nnn"
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Sat Jan 05, 2008 3:33 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

Heloo E.S,


I redefined the tag field as

Part 1 - Alphanumeric
Part2 - Numeric

and did the sort based on part 2. but it still doesnt work
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Sat Jan 05, 2008 3:38 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

redefine is not enough...

did You read carefully my answer with the sample

align align align icon_biggrin.gif
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Sat Jan 05, 2008 3:46 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

I am sorry e.s,

i did not catch by what you meant by aligning
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Sat Jan 05, 2008 3:51 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

Quote:
I am sorry e.s,


nothing to be sorry icon_biggrin.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10327
Location: italy

PostPosted: Sat Jan 05, 2008 10:18 pm    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

the align/justify term means just ...
to put the spaces/blanks were they belong ( by convention/habit)

the alphabetic/alphanumeric fields ( letters and numbers used as characters )
are left aligned/justified ( filled to the right with spaces/blanks )

the numeric fields ( numbers used as numbers - let's not consider the signedness )
are right aligned/justified , filled to the left with spaces/zeroes

this is quite a rough approach...

for the sample You posted anyway the right sorted sequence is
- for the definition of alphanumeric sort and
- for the definition of a single "x pic" field
the one You got to start with

the issue is with the way our brain works ( very fast to associate/disassociate things )
it' s more natural to view as a sorted sequence "column1 ","column2 ","column11"
rather then the sortwise exact sequence "column1 ","column11",column2 "
( note the space at the end of the shorter string )

to be picky ( point out every little thing )
if You want to parse the data the way You asked
the field definition is not adequate
it should be really two fields, a char and a proper numeric
Back to top
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Tue Jan 08, 2008 11:35 am    Post subject: Reply to: Sorting in Alphanumeric Items
Reply with quote

Hi E.S,

thanks for showing the error.

Since according to the project requirement I was not suppsoed to change the declaration, I had to think in another way - like how you had suggested ... about aligning the variables correctly without spaces and so on.

I used a temp numeric variable.

Tag ID is defined as X(30)

Part 2 of TAG ID is numeric 1,2,3 etc

so took Part 2 of Tag ID stripped it of its spaces and moved it to another numeric variable

Now did a sort based on this numeric variable and it worked fine.

Here's the pseudocode

Code:

ARRAY OF TAGS Indexed by IDX
TAG-ID                           PIC X(30)
TAG-ID-SPLIT redefines TAG-ID
TAG-ID-TEXT                   PIC X(20)
TAG-ID-NUM                    PIC X(10)

TEMP-NUM-1                      PIC 9(10)
TEMP-NUM-2                      PIC 9(10)

----------------------------

Procedure Division

Unstring TAG-ID-NUM(IDX) Delimited by spaces into
TEMP-NUM-1
Unstring TAG-ID-NUM(IDX + 1 ) Delimited by spaces into
TEMP-NUM-2


Bubble Sort based on TEMP-NUM-1 and TEMP-NUM-2
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 Sorting on text - but in non-alphabet... Roy Ware SYNCSORT 5 Wed Aug 23, 2017 9:15 pm
No new posts INREC PARSING and dictionary items migusd SYNCSORT 6 Fri Jun 02, 2017 8:02 pm
No new posts Sorting of hex values Saurabh_mi DFSORT/ICETOOL 11 Thu May 25, 2017 3:49 pm
No new posts Sorting group data rajella DFSORT/ICETOOL 4 Sun Jan 22, 2017 11:32 pm
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us