IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Sorting in Alphanumeric Items


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Jan 05, 2008 3:19 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Jan 05, 2008 3:38 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Jan 05, 2008 3:51 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Jan 05, 2008 10:18 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts Sorting a record spanned over multipl... DFSORT/ICETOOL 13
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
No new posts Packed decimal to Alphanumeric COBOL Programming 2
No new posts Creating additional seqnum/Literal wh... DFSORT/ICETOOL 4
Search our Forums:

Back to Top