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

How to sort an array in COBOL


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

New User


Joined: 27 Dec 2007
Posts: 2
Location: kolkata

PostPosted: Fri Jun 06, 2008 5:25 pm
Reply with quote

Hi all,
How to sort an array?
My problem is :
There is an one dim array,
01 ITEM-VAR.
05 ITEM OCCURS 150 TIMES.
10 DEL-DATE PIC S9(09) COMP-3.
10 DEPT-NEBR PIC S9(04) COMP-3.
10 DISP PIC X(01).

I want to sort this table by DEL-DATE and then within a date by DISP.

If my input array is :

30/06/07 20 R
10/06/07 30 S
20/06/07 30 R
30/06/07 20 A
10/06/07 30 R
30/06/07 40 S
30/06/07 20 R

Then output array will be

10/06/07 30 R
10/06/07 30 S
20/06/07 30 R
30/06/07 20 A
30/06/07 20 R
30/06/07 20 R
30/06/07 40 S


Thanks,
Rajiv
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jun 06, 2008 5:32 pm
Reply with quote

What is the date format, I can see that it is COMP-3 is it in yyyymmdd format or mmddyyyy or ddmmyyyy?
Back to top
View user's profile Send private message
Rajiv Lochan De

New User


Joined: 27 Dec 2007
Posts: 2
Location: kolkata

PostPosted: Fri Jun 06, 2008 5:36 pm
Reply with quote

Date format is yyyymmdd
Back to top
View user's profile Send private message
itdsen

New User


Joined: 20 Sep 2006
Posts: 23
Location: Chennai

PostPosted: Wed Jun 11, 2008 7:29 pm
Reply with quote

Is it possible declare date field in comp3.

comp3 only used only with numeric.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 11, 2008 8:11 pm
Reply with quote

itdsen wrote:
Is it possible declare date field in comp3.

comp3 only used only with numeric.


You don't declare a date as comp-3, you declare a field as comp-3 and use it store a numeric value representing a date. 20080611 will fit into a pic s9(9) comp-3 field with no problems, COBOL doesn't know it's a date but the programmers do.
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 Jun 11, 2008 8:42 pm
Reply with quote

In batch you can invoke the system sort via the SORT verb -- see manual for SD and so forth needed. Or, you can implement a sort algorithm from any college text book in your code.

In CICS you don't have access to system sort so you'll have to implement a sort algorithm against the array.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 11, 2008 8:46 pm
Reply with quote

Use this piece of code ....

Code:


01 SAVE-CODE1    PIC 9(9)  VALUE SPACES.
01 SAVE-CODE2    PIC S9(9) VALUE SPACES.
01 SAVE-CODE3    PIC X     VALUE SPACES.
01 S1           PIC S9(4) COMP VALUE 0.
01 S2           PIC S9(4) COMP VALUE 0.


01 ITEM-VAR.
    05 ITEM OCCURS 150 TIMES.
       10 DEL-DATE     PIC S9(09) COMP-3.
       10 DEPT-NEBR    PIC S9(04) COMP-3.
       10 DISP PIC     X(01).


PERFORM VARYING S1 FROM 1 BY 1 UNTIL S1 = 150
        PERFORM VARYING S2 FROM S1 BY 1 UNTIL S2 > 150
                IF DEL-DATE(S2) < DEL-DATE(S1)
                     MOVE DEL-DATE(S1)  TO SAVE-CODE1
                     MOVE DEL-DATE(S2)  TO DEL-DATE(S1)
                     MOVE SAVE-CODE1     TO DEL-DATE(S2)
                END-IF
        END-PERFORM
END-PERFORM.



this will sort del-date ... now perform for next variable or else treat the entire ITEM as a single string and sort .... as per ur requirement ...
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 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top