For Programmers: Free Programming Magazines  


Home > Archive > Cobol > June 2004 > Sort file by computed field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Sort file by computed field
Sally Pascoe

2004-06-13, 8:55 am

I want to sort records for a report in descending order of a computed
field.

How do I sort records in a file based on a computed field based on two
fields in that file but the computed field is not in the file?

Even a keyword for the command so I had something to look for would be
a help.

Thank you
Robert Wagner

2004-06-13, 8:55 am

Sally Pascoe <sallypascoe@hotmail.com> wrote:

>I want to sort records for a report in descending order of a computed
>field.
>
>How do I sort records in a file based on a computed field based on two
>fields in that file but the computed field is not in the file?
>
>Even a keyword for the command so I had something to look for would be
>a help.


You use the SORT verb. The INPUT PROCEDURE computes the sort key, which is in
the SD file. The OUTPUT PROCEDURE prints the report.
JerryMouse

2004-06-13, 8:55 am

Sally Pascoe wrote:
> I want to sort records for a report in descending order of a computed
> field.
>
> How do I sort records in a file based on a computed field based on two
> fields in that file but the computed field is not in the file?
>
> Even a keyword for the command so I had something to look for would be
> a help.


The short answer is that you can't sort on something you do not have.

The sort routine is a black box. You give it stuff, it sorts the stuff and
gives it back. The black box has no notion of values outside of that which
is given to it.

So, to accomplish your task, you'll do something like this:

01 INPUT-REC PIC X(80).

01 SORT-REC.
02 SORT-KEY PIC 9(9).
02 SORT-DATA PIC X(80).

01 OUTPUT-REC PIC X(80).

SORT SORT-WORK ON ASCENDING SORT

(LOOP)
READ INPUT-REC INTO SORT-DATA
COMPUTE SORT-KEY = (something)
RELEASE SORT-REC

(LOOP2)
RETURN SORT-WORK
MOVE SORT-DATA TO OUTPUT-REC



JerryMouse

2004-06-13, 8:55 am

JerryMouse wrote:
(mumble, mumble, hit the send key before finished...)

01 INPUT-REC PIC X(80).

01 SORT-REC.
02 SORT-KEY PIC 9(9).
02 SORT-DATA PIC X(80).

01 OUTPUT-REC PIC X(80).

SORT SORT-WORK ON ASCENDING SORT-KEY
INPUT PROCEDURE IS LOOP
OUTPUT PROCEDURE IS LOOP2

(LOOP)
READ INPUT-REC INTO SORT-DATA
COMPUTE SORT-KEY = (something)
RELEASE SORT-REC

(LOOP2)
RETURN SORT-WORK
MOVE SORT-DATA TO OUTPUT-REC


Warren Simmons

2004-06-14, 3:55 am

Sally,

You say that you are to sort on a computed field that is not in the
record.

One guess would be, do the computation, and add the value of that
result to a field you place in the interium file (first pass of the
sort).

Then it seems that it would be possable to sort the records on that
added field, and create what ever resulting record layout you need
for the output in the Last pass own code. As it stands it looks like
you are grouping something by value.

All the 100, 200, 300, etc. BTW, I mean the first record with no value
would appear as the first record of the output file along with all the
other records with no value. If that group has a name, it might be
something like all between one value and the next group minus one.
\
You will probably get other opinions.

Warren Simmons

Sally Pascoe wrote:
> I want to sort records for a report in descending order of a computed
> field.
>
> How do I sort records in a file based on a computed field based on two
> fields in that file but the computed field is not in the file?
>
> Even a keyword for the command so I had something to look for would be
> a help.
>
> Thank you

Howard Brazee

2004-06-14, 3:55 pm


On 13-Jun-2004, Sally Pascoe <sallypascoe@hotmail.com> wrote:

> I want to sort records for a report in descending order of a computed
> field.
>
> How do I sort records in a file based on a computed field based on two
> fields in that file but the computed field is not in the file?
>
> Even a keyword for the command so I had something to look for would be
> a help.


Seeing that this is a COBOL newsgroup - how about using a COBOL sort? That is
precisely the reason to use an internal sort.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com