how to write cobol to sort in a table



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

how to write cobol to sort in a table

Postby cp_ur530 » Thu Apr 21, 2011 11:11 am

hello,
I have read the record in the file into a table , but the recrods are not in sequence on the key ,such as
01 record-table.
05 cust-mast-record occurs 500 times
ascending key is branch-number
indexed by cm-index.
10 branch-number pic 99.
10 salerep-number pic 99.


how to sort the table?
cp_ur530
 
Posts: 5
Joined: Wed Apr 20, 2011 6:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to write cobol to sort in a table

 

Re: how to write cobol to sort in a table

Postby NicC » Thu Apr 21, 2011 11:17 am

First you search the forum - someone else has asked this question within the last week. It is, presumably, a homework question as your table has exactly the same structure.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: how to write cobol to sort in a table

Postby BillyBoyo » Thu Apr 21, 2011 12:14 pm

cp_ur530 wrote:I have read the record in the file into a table , but the recrods are not in sequence on the key


Is there any reason you can't sort the input file into this order (with your system SORT as a seperate STEP/JOB), then store in your table?

If there is a reason, you might still be lucky.

You have branch-number and salerep-number. You have defined them as numeric, I don't know why since you are never going to do a calculation with them - so better as PIC XX.

Irrespective of that, if they genuninely are numeric:

Define a table of 10,000 items, let's do 10,000 flags, you'll know if you need to include more data.

Set all the flags off at before you read any records.

Make a number out of your branch/salesperson. Start off as usage Display. Then move the resulting number to a COMP PIC S9(4), because you are going to use it as a subscript.

Add one to the value of this subscript - this is to deal with the case 0000 if it can exist. If it can't logically exist, test for it in your program and behave appropriately.

Then, using the subscript you have created, set the appropriate flag in the table "on".

You can then interrogate the table as you need, by using the same technicque.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: how to write cobol to sort in a table

Postby cp_ur530 » Sat Apr 23, 2011 12:30 pm

NicC wrote:First you search the forum - someone else has asked this question within the last week. It is, presumably, a homework question as your table has exactly the same structure.


I had read that question and its replay ,but i think i didn't find the answer i want , i know i can write the sort algorithm by myself ,but i still want to know how to use "sort" in the COBOL program to sort in a table just like sort a file
cp_ur530
 
Posts: 5
Joined: Wed Apr 20, 2011 6:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to write cobol to sort in a table

Postby cp_ur530 » Sat Apr 23, 2011 12:38 pm

BillyBoyo wrote:Is there any reason you can't sort the input file into this order (with your system SORT as a seperate STEP/JOB), then store in your table?


read the records that not in sequence into a table ,just want to make it easy ,not really like that ,
the records are not in sequence ,because I add some records to the table from other file
cp_ur530
 
Posts: 5
Joined: Wed Apr 20, 2011 6:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to write cobol to sort in a table

Postby BillyBoyo » Sat Apr 23, 2011 12:48 pm

So, what about the suggested solution, which is to use a "sparsely populated" table and a subscript generated from your two key items.

If you want to know more than just the "existence", just include whatever it is in the table.

If you want the table "sorted", after you have loaded all the data, go through the table ignoring any which are not set, and moving each that is set to the highest available slot. But no real need. The table will work fine as long as you have the keys.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: how to write cobol to sort in a table

Postby Robert Sample » Sat Apr 23, 2011 6:11 pm

but i still want to know how to use "sort" in the COBOL program to sort in a table just like sort a file
The SORT verb requires using a file -- the sort file. So you could load the table, use SORT where the INPUT PROCEDURE moves the table entries to the SORT record and releases it, while the OUTPUT PROCEDURE reloads the table. If you expect to use SORT USING GIVING, then your expectation cannot be met, period. USING and GIVING only work with files.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post