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

SORTING array which has values from database


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Tue Mar 31, 2009 9:49 pm
Reply with quote

Hi,

I have an array with below structure

01 WRK-CLOTHES OCCURS 10 TIMES
05 WRK-CLOTH PIC X(4)
05 WRK-VALUE PIC S9(3)V9(2)

I have filled the array already with values from database, now i want sort above array and fill the data in the below array

01 YRK-CLOTHES OCCURS 10 TIMES
05 YRK-CLOTH PIC X(4)
05 YRK-VALUE PIC S9(3)V9(2)

the different type of WRK-CLOTH are 'A001' 'A002' 'C001' 'C002' and few other values that start with 'B' or 'D'. Now i want sort the array such a way that first it should fill A001 and A002 and then that starts with 'B' or 'D' by highest WRK-VALUE to lowest WRK-VALUE and then C001 and C002. i may or may not gey A001, A002, C001, C002. Some timesi get one of this or two of this. its like depends. But the if it there then it should follow the order for SORTING.

Here is the eg:

A001 01020
B001 01030
B003 10400
B005 60500
C001 00920

My sorted array shoul be like this

A001 01020
B005 60500
B003 10400
B001 01030
C001 00920

Can someone provide me sample code for this. so that i will develop as per my values.

Thanks in advance,
Anand
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 01, 2009 12:07 am
Reply with quote

Hello,

You need to post a more complete set of example data. SHow multiple A, C, and D entries in both the input and output.

An easy thing for you to do would be to use an SD and an internal SORT to arrange the data in the order you want.
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 01, 2009 12:13 am
Reply with quote

i gave simple example which solves my problem also. what is SD? i dont understand that. And internal SORT?? can someone provide me some sample code??
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 01, 2009 12:18 am
Reply with quote

If you have an A001 and A002, what order to you expect them in the output? Ditto for C001 and C002? You did not provide any explanation in your sample as to what to do in these cases.

There's a link at the top of the page to manuals -- the COBOL Language Reference and Programming Guide have details about using the SORT verb in COBOL to do an internal SORT using the SD file definition clause, which is used instead of FD for sorts. You can also find out about INPUT PROCEDURE and OUTPUT PROCEDURE which gives even more control over the sort.
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 01, 2009 12:29 am
Reply with quote

if its A001 or A002, then it can be filled immediatly, no need to check the balances, but begingin of the array. Like that C001 and C002, but at end of the array. only for 'B' or 'D' series we need check value variable and fill from highest to lowest inbetween A and C series. If there is no A series means then it will start with E series and C series always end. And if there is not A and C series means then only E series with sorted order. hope i am clear here.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 01, 2009 12:35 am
Reply with quote

What you are saying is not clear to me. Are you stating that there will only be one A record? If this is not what you are saying, do you care if the order is A002 A001 ... versus A001 A002? The same applies for the C records -- is there only ever one? If there is more than one, do you care which order they come out in?
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 01, 2009 12:44 am
Reply with quote

Hai Robert,

here is the example...

First array

A001 01020
C001 00920
C002 00890
B001 01030
B003 10400
B005 60500
C001 00920

My SORTED array should be

A001 01020
B005 60500
B003 10400
B001 01030
C001 00920
C002 00890

We are not sure i always receieve A001 and A002. sometime i receieve both and sometimes only one and sometimes none from A series. Like that C series also. E series should be sorted based on VALUES and should be inbwteen A and C series.
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 01, 2009 12:46 am
Reply with quote

Hai Robert,

here is the example...

First array

A001 01020
C001 00920
C002 00890
B001 01030
B003 10400
B005 60500

My SORTED array should be

A001 01020
B005 60500
B003 10400
B001 01030
C001 00920
C002 00890

We are not sure i always receieve A001 and A002. sometime i receieve both and sometimes only one and sometimes none from A series. Like that C series also. E series should be sorted based on VALUES and should be inbwteen A and C series.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 01, 2009 12:47 am
Reply with quote

Hello,

Quote:
i gave simple example which solves my problem also.
No, it actually doesn't. . . It is incomplete. When you implement code, the code will not know what you know and must be written for any and all things mentioned in "the rules".
Quote:
What you are saying is not clear to me
Mee too. . . What you are saying is only to clear to you. Keep in mind that while your situation/requirement is completely clear to you, it possibly is not to everyone who reads it.
Quote:
And internal SORT??
As suggested - use the "IBM Manuals" link at the top of the page and select the Language Reference for the version of cobol your system uses. As Robert mentioned, you want INPUT PROCEDURE/OUTPUT PROCEDURE processing.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 01, 2009 1:04 am
Reply with quote

Until you put this up
Quote:
First array

A001 01020
C001 00920
C002 00890
B001 01030
B003 10400
B005 60500

My SORTED array should be

A001 01020
B005 60500
B003 10400
B001 01030
C001 00920
C002 00890
The simplest solution to your requirement was to just do
Code:
SORT FIELDS=(1,1,CH,A,2,4,CH,D)
but that won't work with what you've posted.

You need to create an extra field on your record (through COBOL for example) where if the first character is B or D move the next three bytes to the extra field, otherwise move 999 - the next three bytes to the extra field. Then sort on 1,1,CH,A and the extra field descending. That will put the data in the sequence your last post indicated. Once the sort is done you do not need the extra field.
Back to top
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 01, 2009 7:21 am
Reply with quote

I have to do it in COBOL. Not in JCL SORTCARD. in comes in mid of the program.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 01, 2009 8:01 am
Reply with quote

Not a big deal -- the sort SD can be any layout you want. Define the SD 01 as
Code:
01  SD-RECORD.
    05  SD-EXTRA-FIELD     PIC 9(03).
    05  SD-DATA-RECORD.
        10  SD-FIRST-CHAR  PIC X(01).
        10  FILLER                PIC X(...).
Code your sort statement in the PROCEDURE DIVISION as
Code:
SORT SORT-FILE
    ASCENDING KEY SD-FIRST-CHAR
    DESCENDING KEY SD-EXTRA-FIELD
and use INPUT PROCEDURE to set the extra field as I discussed earlier.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 01, 2009 8:08 am
Reply with quote

Hello,

Quote:
I have to do it in COBOL. Not in JCL SORTCARD. in comes in mid of the program.
Understood.

Have you done an experiment with the internal sort? If not, do so now. . .
From the COBOL manual - the SORT statement:
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3lr40/6.2.34?

All you have to do is a SELECT, an SD with the appropriate sort keys defined, a SORT statement in the cobol code and use the INPUT PROCEDURE and OUTPUT PROCEDURE to RELEASE info to the sort and RETURN info from the sort.

This is an example from the Programming Guide:
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3pg40/1.12.10.2?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 01, 2009 8:13 am
Reply with quote

Hi Robert,

I believe the sort needs 3 sort keys (one for the first byte, one for those that are ascending and another for descending) and the code needs to use one or the other of the a/d sort keys depending on the first byte.

If i've not misunderstood something. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 01, 2009 4:38 pm
Reply with quote

Dick: if the first character of the record is B or D, I recommended in my earlier post moving the value to the sort extra field, otherwise setting the sort extra field to 999 minus the value. That way, using my suggested sort, the record is sorted on the first byte, then ascending on the next three bytes if the first byte is A, C, E but descending for B and D.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 01, 2009 8:13 pm
Reply with quote

Yup, saw that earlier, but didn't see it in the code snippet.

Then i got to thinking (probably not a good thing icon_wink.gif ) that having an asecnding field and a descending field might be easier for some to handle than inverting the number. . .

Maybe we'll hear back on what progress has been made. . .

d
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
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts What database does Jobtrac use CA Products 4
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
Search our Forums:

Back to Top