Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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


Report this thread to moderator Post Follow-up to this message
Old Post
Apokrif
10-22-06 11:55 PM


Re: Set a file variable to another
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
10-22-06 11:55 PM


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

Report this thread to moderator Post Follow-up to this message
Old Post
CG
10-23-06 02:55 AM


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

Report this thread to moderator Post Follow-up to this message
Old Post
Louis Krupp
10-23-06 08:55 AM


Re: Set a file variable to another

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

Report this thread to moderator Post Follow-up to this message
Old Post
shaky knees
10-23-06 08:55 AM


Re: Set a file variable to another
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.



Report this thread to moderator Post Follow-up to this message
Old Post
HeyBub
10-23-06 11:55 PM


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

Report this thread to moderator Post Follow-up to this message
Old Post
Frederico Fonseca
10-23-06 11:55 PM


Re: Set a file variable to another
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.



Report this thread to moderator Post Follow-up to this message
Old Post
HeyBub
10-23-06 11:55 PM


Re: Set a file variable to another
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.[/colo
r]

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


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
10-24-06 02:55 AM


Re: Set a file variable to another
I don't remember if the OP talked about their environment, but I know that a
t
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 directiv
e
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 compile
rs)
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



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
10-24-06 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.