Want to sort cursor on a table



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Want to sort cursor on a table

Postby vegafacundodaniel » Fri Oct 29, 2010 4:58 pm

Hi,

A question please.

I have a cursor on a table and I'd want to sort it according to a criteria on a field. This criteria is not alphanumeric. It is a "special" criteria.

Example :
Field-A Field-B
-------- ----------
A 1
B 2
B 3
C 4
D 5
E 6

I'd want to sort that cursor with this criteria below :

Field-A Field-B
-------- -----------
B 2
B 3
D 5
A 1
C 4
E 6

i.e first records "B", second records "D", third records "A" and so on...

Thanks in advance !!!
vegafacundodaniel
 
Posts: 61
Joined: Tue Jul 20, 2010 4:27 pm
Has thanked: 1 time
Been thanked: 0 time

Re: SORT

Postby enrico-sorichetti » Fri Oct 29, 2010 5:03 pm

any transformation must be capable of being described by an algorithm
otherwise it might be difficult/impossible to implement it in a programming language

describe the logic please ...
given a <key> what is the relation with the preceding and the subsequent keys

from the input and output You posted it is awkward to infer the algorithm
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: SORT

Postby vegafacundodaniel » Fri Oct 29, 2010 5:11 pm

Sorry, but there is not a "logic criteria" to do it....

The criteria is what I am saying.

first records "B", second records "D", third records "A" and so on...

Thanks !!
vegafacundodaniel
 
Posts: 61
Joined: Tue Jul 20, 2010 4:27 pm
Has thanked: 1 time
Been thanked: 0 time

Re: SORT

Postby enrico-sorichetti » Fri Oct 29, 2010 5:16 pm

we are just wasting time here :evil:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: SORT

Postby Robert Sample » Fri Oct 29, 2010 5:21 pm

Sorry, but there is not a "logic criteria" to do it....
If this is true, how do you "know" to put the B records first? Putting the B record first is a logic criterion -- and not one you have explained in any way.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: SORT

Postby dick scherrer » Fri Oct 29, 2010 11:39 pm

Hello,

You have started a topic about "SORT" in the COBOL part of the forum and then mention a cursor.

Suggest someone consider changing what the values represent so that they are more easily managed.

Or add another column that contains a "sequence code" that can be ordered by - a rather awful approach, but if the design cannot be corrected . . . :(
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Want to sort cursor on a table

Postby GuyC » Tue Nov 02, 2010 4:19 pm

somehow you'll have to document the required sequence in DB2.
This can be a code table with which you join
or a transformation you write in your sql.

select *
from tab1
order by
  case field-A
  when 'B' then 1
  when 'D' then 2
  when 'A' then 3
  when 'C' then 4
  when 'E' then 5
  else 99
  end
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post