For Programmers: Free Programming Magazines  


Home > Archive > Cobol > October 2006 > Set a file variable to another









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 Set a file variable to another
Apokrif

2006-10-22, 6:55 pm

Hi,

in C you can say:
FILE *current, *g;
current=g;

Or in Pascal:

var current,g:^text;
begin
f=g;
end;

This is, for instance, if you want to read several input files (g,h...)
but only perform the fgets or readln operations
on a single "current" file variable (for some reason, calls to fgets or
readln are in a part of the source code you cannot change, or don't
want to change so that you have a generic reading operation). I'd like
to know how to do it in Cobol: would

fd foo.
fd bar.
and then:
move foo too bar

be correct ?

Thanks.

Richard

2006-10-22, 6:55 pm


Apokrif wrote:
> Hi,
>
> in C you can say:
> FILE *current, *g;
> current=g;
>
> Or in Pascal:
>
> var current,g:^text;
> begin
> f=g;
> end;
>
> This is, for instance, if you want to read several input files (g,h...)
> but only perform the fgets or readln operations
> on a single "current" file variable (for some reason, calls to fgets or
> readln are in a part of the source code you cannot change, or don't
> want to change so that you have a generic reading operation). I'd like
> to know how to do it in Cobol: would


You can't, Cobol is not C.

You can open diferent disk files with one FD, one at a time, because
the ASSIGN can be of different names, but the organization and record
sizing must be identical. In C this is trivial because all buffered
files are the same organization.

> fd foo.
> fd bar.
> and then:
> move foo too bar
>
> be correct ?


No.

CG

2006-10-22, 9:55 pm

Richard wrote:
> Apokrif wrote:
>
> You can't, Cobol is not C.
>
> You can open diferent disk files with one FD, one at a time, because
> the ASSIGN can be of different names, but the organization and record
> sizing must be identical. In C this is trivial because all buffered
> files are the same organization.
>
>
> No.
>

You can add PL/I to the list of languages that can easily do this. No
way in COBOL that I know of.
Carl
Louis Krupp

2006-10-23, 3:55 am

Apokrif wrote:
> in C you can say:
> FILE *current, *g;
> current=g;
>
> Or in Pascal:
>
> var current,g:^text;
> begin
> f=g;


Do you mean "current=g"?

> end;
>
> This is, for instance, if you want to read several input files (g,h...)
> but only perform the fgets or readln operations
> on a single "current" file variable (for some reason, calls to fgets or
> readln are in a part of the source code you cannot change, or don't
> want to change so that you have a generic reading operation). I'd like
> to know how to do it in Cobol: would
>
> fd foo.
> fd bar.
> and then:
> move foo too bar
>
> be correct ?


A couple of off-the-wall ideas:

1. If your system allows you to set a file name at run-time, you could
do that and open the right file as part of your generic reading routine.

2. If your input data needs to be sorted, call SORT using an input
procedure that will read the right file and do the generic processing in
the output procedure. If your input data doesn't need to be sorted but
just read in its current order, sort it anyway; start your sort record
with a record counter that you would use as the sort key, have your
input procedure read the file of your choice and move the incremented
counter and the input record to the sort record, and have your output
procedure return the sorted records, do something with the input data,
and ignore the key.

Louis
shaky knees

2006-10-23, 3:55 am



> fd foo.
> fd bar.
> and then:
> move foo too bar

HeyBub

2006-10-23, 6:55 pm

Apokrif wrote:
> Hi,
>
> in C you can say:
> FILE *current, *g;
> current=g;
>
> Or in Pascal:
>
> var current,g:^text;
> begin
> f=g;
> end;
>
> This is, for instance, if you want to read several input files
> (g,h...) but only perform the fgets or readln operations
> on a single "current" file variable (for some reason, calls to fgets
> or readln are in a part of the source code you cannot change, or don't
> want to change so that you have a generic reading operation). I'd like
> to know how to do it in Cobol: would
>
> fd foo.
> fd bar.
> and then:
> move foo too bar
>
> be correct ?
>


"too" is a C command?

A COBOL program can use the same procedure to read multiple physical files.
Typically:

SELECT Input-File assign to DATA-NAME (this construct varies by compiler)


MOVE "INPUT-A" to DATA-NAME
PERFORM Read-Input
MOVE "INPUT-B" to DATA-NAME
PERFORM Read-Input
etc.


Read-Input
OPEN Input Input-File
Read Input-File
PERFORM UNTIL Input-FS not = '00'
(process input record)
READ Input-file
END-PERFORM
CLOSE Input-File.


Frederico Fonseca

2006-10-23, 6:55 pm

On Mon, 23 Oct 2006 09:14:40 -0500, "HeyBub" <heybubNOSPAM@gmail.com>
wrote:

>Apokrif wrote:
>
>"too" is a C command?
>
>A COBOL program can use the same procedure to read multiple physical files.
>Typically:
>
>SELECT Input-File assign to DATA-NAME (this construct varies by compiler)
>
>
>MOVE "INPUT-A" to DATA-NAME
>PERFORM Read-Input
>MOVE "INPUT-B" to DATA-NAME
>PERFORM Read-Input
>etc.
>
>
>Read-Input
> OPEN Input Input-File
> Read Input-File
> PERFORM UNTIL Input-FS not = '00'
> (process input record)
> READ Input-file
> END-PERFORM
> CLOSE Input-File.
>

this only works if the files have the same structure.
e.g. if they are indexed they MUST have the same record size, and
exactly the same keys on the same order and same definition.




Frederico Fonseca
ema il: frederico_fonseca at syssoft-int.com
HeyBub

2006-10-23, 6:55 pm

Frederico Fonseca wrote:
> On Mon, 23 Oct 2006 09:14:40 -0500, "HeyBub" <heybubNOSPAM@gmail.com>
> wrote:
>
> this only works if the files have the same structure.
> e.g. if they are indexed they MUST have the same record size, and
> exactly the same keys on the same order and same definition.
>
>

Well, sure. Since the OP wanted to read "several input files," I presumed
the input files were physically identical.

Then, again, his motive may have been to brag about the wonderfullness of C.


Richard

2006-10-23, 9:55 pm


HeyBub wrote:

> Well, sure. Since the OP wanted to read "several input files," I presumed
> the input files were physically identical.


In C the files are all just streams of bytes so he may not understand
the concept of 'organization'.

> Then, again, his motive may have been to brag about the wonderfullness of C.


No, it is probably all he knows and so is having difficulty in working
out how to write C programs in COBOL.

William M. Klein

2006-10-24, 3:55 am

I don't remember if the OP talked about their environment, but I know that at
least one response to this thread has mentioned the Micro Focus "EXTFH"
interface.

I thought that I would also mention the Micro Focus FCDREG compiler directive
and related
- FH--FCD
and
- FH--KEYDEF

special registers. If anyone is (OP or otherwise) is interested in getting more
information on how these can be used in Micro Focus (NOT other COBOL compilers)
to accomplish "run-time file switching", let me know and I anc provide some
references (or you can find these items in the online documentation).

--
Bill Klein
wmklein <at> ix.netcom.com


Sponsored Links







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

Copyright 2008 codecomments.com