View previous topic :: View next topic
|
Author |
Message |
Rajiv Lochan De
New User
Joined: 27 Dec 2007 Posts: 2 Location: kolkata
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
Rajiv Lochan De
New User
Joined: 27 Dec 2007 Posts: 2 Location: kolkata
|
|
|
|
Date format is yyyymmdd |
|
Back to top |
|
|
itdsen
New User
Joined: 20 Sep 2006 Posts: 23 Location: Chennai
|
|
|
|
Is it possible declare date field in comp3.
comp3 only used only with numeric. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
|