Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageApokrif 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.
Post Follow-up to this messageRichard 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
Post Follow-up to this messageApokrif 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
Post Follow-up to this message> fd foo. > fd bar. > and then: > move foo too bar
Post Follow-up to this messageApokrif 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.
Post Follow-up to this messageOn 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
Post Follow-up to this messageFrederico 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.
Post Follow-up to this messageHeyBub 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.
Post Follow-up to this messageI 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.