View previous topic :: View next topic
|
Author |
Message |
simha_it
New User
Joined: 05 May 2005 Posts: 30
|
|
|
|
Hi,
I have a table consists of 48 records which will be populated in an asencding order. I want to sort that data in a descending order.
But the table has a Index variable. Can i use the subscript inorder to sort the data in that table?
for ex: 05 TABLE OCCURS 48 TIMES INDEXED BY A1
10 EMPNO PIC X(02)
10 EMPNAME PIC X(19)
10 SUBJECT PIC x(03)
and I have 48 records in ascending order (based on EMPNO). Now i want to sort the data in descending order. I can sort the by using subscripts.
PERFORM WI-MIN VARYING FROM 1 BY 1
UNTIL WI-MIN > TOTAL ROWS/2
MOVE TABLE (WI-MIN) TO WS-TEMP-REC
MOVE TABLE (WI-MAX) TO TABLE (WI-MIN)
MOVE WS-TEMP-REC TO TABLE (WI-MAX)
END-PERFORM
Is it possible to use the subscripts here? DO YOU HAVE ANY OTHER SOLUTION? Please assist me in this regards.
Thanks in advance
Narsimha |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Yes you can use subscripts or you can define additional indexes. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Quote: |
DO YOU HAVE ANY OTHER SOLUTION? |
You can access the array in reverse direction, for example-
Code: |
PERFORM VARYING A1 FROM 48 BY -1...... |
This is not sorting but it should serve the purpose of getting the values in reverse order. |
|
Back to top |
|
|
simha_it
New User
Joined: 05 May 2005 Posts: 30
|
|
|
|
agkshirsagar wrote: |
Quote: |
DO YOU HAVE ANY OTHER SOLUTION? |
You can access the array in reverse direction, for example-
Code: |
PERFORM VARYING A1 FROM 48 BY -1...... |
This is not sorting but it should serve the purpose of getting the values in reverse order. |
I have to replace the existing data as some other programs uses that data later. |
|
Back to top |
|
|
rag swain
New User
Joined: 17 Dec 2007 Posts: 33 Location: pune,INDIA
|
|
|
|
Try using a SORT file with INPUT PROCEDURE and OUTPUT PROCEDURE after unloading the data from the table. And ofcourse you can use subscript in stead of using index. |
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
A few months ago I posted copybooks to sort a table. Give them a try. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
Back to top |
|
|
|