Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting from a file and producing a second file for the sorted data.

Status
Not open for further replies.

spyderman

Programmer
Apr 8, 2001
4
AU
I am un-experienced with the SORT, but I need to create a program that sorts on three fields. The sort staements must produce a file of records for students enrolled in a particular course. The partucular course e.g., TEACHING is obtained via the keyboard. The name of the sorted file e.g., teaching.srt, is created with the program by concatenating the course mane with the file extension ".srt"

I know I need to use a string to do this but, mind is running in circles trying to get my mind around it.

Thankyou to anyone who can help.

-Spyd
 
Hi spyderan,
try this...

working-storage section.
01 w-course pic x(15).
01 w-file-extension pic x(4) value ".srt".
01 w-file-name pic x(19).

procedure division.

STRING W-COURSE DELIMITED BY " "
W-FILE-EXTENSION DELIMITED BY SIZE
INTO W-FILE-NAME

i'm not sure how you would get rid of any trailing spaces in w-file-name though, doh! urm i'll have a think and get back to you.

jimlee
 
I noticed the same thing, Thansk a lot for your help.
 
You may not need to get rid of the trailing spaces, depending on your compiler. Some will accept it with the trailing spaces and some require a null character to delimit the string, which you can get by stringing in a LOW-VALUE as the last operand in the STRING. There may be other ways, but I've seen both of these used in several different implementations. If you write what compiler you're using, I or someone else on this forum may be able to give you an answer off the top of our heads. Betty Scherber
Brainbench MVP for COBOL II
 
All,

producing a string like that is all fine and dandy, but i yet fail to see how Spyderman is going to assign that file name to his output file; are identifiers allowed in the file control, like:

FILE-CONTROL.

SELECT SORT-FILE ASSIGN TO W-FILE-NAME.

??? I don't think so !

Ronald.
 
p.s.
ronald,

yes,you can do exactly that with my compiler! jimlee
 
Its fine Ronald, you can do that.

The compiler im using is, ACU COBOL-85.

Thanks Jimlee and Betty.

 
All,

there you have it again: one is never too old to learn. Thank you for this wise lesson !!!

Regards,
Ronald.

P.S. I'm not that old, but that's how the saying goes ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top