Hello
this link helped me to sort the problem
http://home.att.net/~arnold.trembley/svalgard.htm
Fredrik
----------------------------------------------------------------------------------------------------
Fredrik Lundberg, Systemutvecklare
Direkt: 08-613 38 33
E-post: Fredrik.Lundberg@xxxxx
KP PENSION & FÖRSÄKRING, Box 2207, 103 15 Stockholm
Besöksadress: Stora Nygatan 27
Växel: 08-613 37 00
http://www.kp.se
RMiklos@xxxxxx
Sänt av:
cobol400-l-bounce Till
s@xxxxxxxxxxxx COBOL Programming on the
iSeries/AS400
<cobol400-l@xxxxxxxxxxxx>
2008-06-06 11:07 Kopia
Ärende
Sänd svar till Re: [COBOL400-L] Sorting A Table
COBOL Programming
on the
iSeries/AS400
<cobol400-l@midra
nge.com>
If you want to sort an internal table, you can use any sorting algorithm.
Here is an exaple code:
Given is an internal table
01 FOUND-DATA-TABLE.
05 FOUND-TABLE-ENTRIES OCCURS 89 TIMES.
10 TAB-EL.
15 TAB-OBEC PIC X(42) VALUE SPACES.
15 TAB-POCET PIC 9(2) VALUE 0.
The table should be sorted according to field TAB-OBEC.
So here is an COBOL-Code for the simple sorting procedure for the above
table
SORT-THE-TABLE SECTION.
*** BubbleSort Algorithm
B-SORT01.
MOVE ZERO TO SC-SORT.
COMPUTE J-MAX = TAB-SIZE-INDEX - 1.
B-SORT10.
PERFORM VARYING J FROM 1 BY 1 UNTIL J > J-MAX
IF TAB-OBEC (J) > TAB-OBEC (J + 1)
PERFORM AUSTAUSCH
END-IF
END-PERFORM.
B-SORT80.
*** Check, if the change of elements was done
IF SC-SORT = '1'
GO TO B-SORT01
END-IF.
B-SORT90.
EXIT.
*** Change the two adjacent elements *********
AUSTAUSCH SECTION.
AUST01.
MOVE TAB-EL (J + 1) TO TEMP-EL.
MOVE TAB-EL (J) TO TAB-EL (J + 1).
MOVE TEMP-EL TO TAB-EL (J).
MOVE '1' TO SC-SORT.
AUST90.
EXIT.
And now you only need to call the above procedure elsewhere in your
program with
PERFORM SORT-THE-TABLE
Robert Munday <rwmunday@xxxxxxxxxxxxx>
Sent by: cobol400-l-bounces@xxxxxxxxxxxx
05.06.2008 23:22
Please respond to
COBOL Programming on the iSeries/AS400 <cobol400-l@xxxxxxxxxxxx>
To
COBOL <cobol400-l@xxxxxxxxxxxx>
cc
Subject
[COBOL400-L] Sorting A Table
I need to sort a table by one of its elements which should be easy enough.
There are no experienced COBOL programmers in this shop and my only book
example is non-iSeries. SEU is hanging up on my sort statement.
Here is what I have:
01 SL415-CB-Work-Table.
04 CB-Table-Ctr Pic 99 Value Zero.
04 CB-Work-Table-Entry
Occurs 50
Ascending Key Is CB-Past-Due
Indexed By CB-Index.
06 CB-Past-Due Pic X(3).
06 CB-SSN Pic X(9).
06 CB-Ln-Num Pic XX.
06 CB-Account-Status Pic XX.
The editor chokes on this:
Sort CB-Work-Table-Entry On Ascending Key CB-Index.
What to do? I'd buy an iSeries COBOL book but I'm outahere at the end of
the month. I could also do this in SQL if I knew how.
Thanks,
Robert Munday
Munday Software Consultants
Montgomery, AL
on assignment in Columbia, SC
--
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
list
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/cobol400-l
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/cobol400-l.
Mgr. Ing. Roman MIKLÓŠ
Prvá stavebná sporiteľňa a.s.
Bajkalská 30, P. O. Box 48
829 48 Bratislava 25
Tel.: +421/ 2 / 582 31 174
Fax: +421/ 2 / 582 31 109
--
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
list
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/cobol400-l
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/cobol400-l.
As an Amazon Associate we earn from qualifying purchases.