View previous topic :: View next topic
|
Author |
Message |
cheethra
New User
Joined: 20 Jan 2007 Posts: 6 Location: India
|
|
|
|
Hi All,
We have a requirement in which we cant go in for SORT PROCEDURE in COBOL using sort work files.
Is there any way to sort the records in the internal table in A/D order based on the key of certain bytes in the records.
Requirement is to similar to the Sort card we use for SYNCSORT.
Thanks in Advance.
Regards |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
I don't know about your "sort card", but you can internally sort tables in various ways, give a look at this Bubble Sort...... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
cheethra, I would suggest you start with the Bubble Sort link provided by CICS_Guy.
you will always need a third area/field to save one of the items during the switch of the lesser and the greater. |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Small correction,
Use below code for SORTING
---------------------------------------
WORKING STORAGE SECTION.
01 WS-NUMBERS.
10 WS-NUM PIC 999 OCCURS 10 TIMES.
01 WS-I PIC 99.
01 WS-J PIC 99.
01 WS-K PIC 99.
01 WS-TEMP PIC 999.
PROCEDURE DIVISION.
0000-MAIN.
PERFORM 1000-READ VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 10.
1000-READ.
COMPUTE WS-J = WS-I + 1.
PERFORM 2000-COMPARE
VARYING WS-K FROM WS-J BY 1 UNTIL WS-K >= 10.
2000-COMPARE.
*********************************************************
* LOGIC FOR ORDERING NUMBERS IN ASC
*********************************************************
IF WS-NUM(WS-I) > WS-NUM(WS-K)
MOVE WS-NUM(WS-I) TO WS-TEMP
MOVE WS-NUM(WS-K) TO WS-NUM(WS-I)
MOVE WS-TEMP TO WS-NUM(WS-K)
ELSE
CONTINUE
END-IF.
.
.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
2000-COMPARE.
*********************************************************
* LOGIC FOR ORDERING NUMBERS IN DESC
*********************************************************
IF WS-NUM(WS-I) > WS-NUM(WS-K)
CONTINUE
ELSE
MOVE WS-NUM(WS-I) TO WS-TEMP
MOVE WS-NUM(WS-K) TO WS-NUM(WS-I)
MOVE WS-TEMP TO WS-NUM(WS-K)
END-IF.
.
.
Use above pseudo code....
Regards,
Raghavendra |
|
Back to top |
|
|
cheethra
New User
Joined: 20 Jan 2007 Posts: 6 Location: India
|
|
|
|
Hi All,
Thanks for your replies.
Let me explain what i wanted to do.
Assume there are five records of length 80 in a table, i wanted to pick few fields from each record and form a key, with this key i wanted to sort the records.
Thanks, |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
cheethra wrote: |
Assume there are five records of length 80 in a table, i wanted to pick few fields from each record and form a key, with this key i wanted to sort the records.
|
Cheetra,
We can use same logic which i gaven before provided the fields should be present in same columns(Key fields)
ex;
AAAAAAAAAAAA1234BBBBBB0000CCCCCCC
AAAAAAAAAAAA2344BBBBBB1111CCCCCCC
AAAAAAAAAAAA2345BBBBBB3333CCCCCCC
The Keys in the above example are
1234 and 0000 in first row
2344 and 1111 in second row
2345 and 3333 in third row
Use Referance modification concept for this
Regard's
Raghavendra |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Use Referance modification concept for this
|
If you want to write assembler, write assembler.
But if you are writing COBOL, properly define your data in working storage.
If indeed the keys fields in the OP's record are not contiguous, the IF statements for multiple reference modifications will be difficult to read, understand and debug.
sub-define your item properly and refer to the key fields as data elements without the reference modification so that someone else can read your code and understand what is/was being done. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
FWIW, it is "your" code and "your" ws definitions. You can control how it is implemented.
If this was my requirement, i'd add my own first field (group with the "key" components beneath it) and make it the "key". Sorting and searching would both be much easier to understand and work with.
Again, this is just IMHO. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Mixing reference modification with subscripting/indexing gets very hard to read. Add it the complex IF/OR/AND that is needed to handle a multiple part key and it will end an unreadable/unmaintainable mess.
Which comes first with a subscripted field with reference modification the subscript or the reference modification? |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Craq Giegerich wrote: |
Which comes first with a subscripted field with reference modification the subscript or the reference modification? |
I can never remember, but the compiler will let you know if you have it backward..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Which comes first with a subscripted field with reference modification the subscript or the reference modification? |
Subscript first, then reference modification. I.e.
Code: |
MOVE DTL-RX-REFILL(1) (2:1) TO RE-NO. |
|
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
And the duplicate name qualifier?..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
As you mentioned some time ago. . . .
"We don' need no steenkin'" duplicate names. . . |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Hi all,
Just to add thoughts,
As per my knowledge, we can approach in other way also.
Consider a table having structure
Quote: |
AAAAAAAAAAAA1234BBBBBB0000CCCCCCC
AAAAAAAAAAAA2344BBBBBB1111CCCCCCC
AAAAAAAAAAAA2345BBBBBB3333CCCCCCC |
Declare in Working storage section as a Group items
say
01 ws-table.
05 ws-tab occurs 10 times.
10 ws-a pic x(10).
10 ws-b pic x(20). <-- Let it be Key>
10 ws-c pic x(30).
10 ws-d pic x(10). <----- Let it be another Key>
Use declared items as array type
Say IF WS-B(1) .....
.....
Any suggestionis welcomed
Regards,
Raghavendra |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Say IF WS-B(1) ..... |
This will still require "sorting" and "searching" on a multiple field "key". As has been mentioned previously, working with the compound key increases the amount of work needed.
To clarify, idf this were my requirement, i would define the array with a multi-field (group) key and have all of the detail fields named in the array. This way i could work with somple compares and not need to use reference modification. As was also mentioned, combining array processing and reference modification will tent to make the code harder to read/maintain. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
cheethra wrote: |
We have a requirement in which we cant go in for SORT PROCEDURE in COBOL using sort work files. |
Using an internal call to Syncsort for that few records does not require 'sort work files'...
Quote: |
Requirement is to similar to the Sort card we use for SYNCSORT. |
Since the Assembler to Syncsort call looks standard, I'd bet you could call it from COBOL and yes, you could point to the sort cards you use for Syncsort....
A rather long trip for a half dozen records...... |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Dear DICK,
Quote: |
working with the compound key increases the amount of work needed |
Could you explain me how amount of work will increasing
<As per my knowledge, MAIN MEMORY will contribute space for to store ARRAY-Internal array. Either, we declare Data item as a type of GROUP ITEM or As a type of INDEPENDENT ITEM(Variable)>
More over requirement is like that
Quote: |
Assume there are five records of length 80 in a table, i wanted to pick few fields from each record and form a key, with this key i wanted to sort the records. |
Just i am giving approach
This is just for clarification
after all we are learner, right. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Could you explain me how amount of work will increasing |
"Sorting" the table/array and searching the array will be more complex using multiple fields for "the key" - hence more work.
It may also lead to longer development time and errors depending on the skill of the coder. |
|
Back to top |
|
|
|