Hi guys,
I have a program that has 5 keys. When i run using a certain key.. would be nice to name the output file to reflect that key. instead of the generic name in the Assign clause. Is there a way for me to reassign the file name from within the program? I sure could not find it in the manuals.
Thank you,
Steve
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can adjust the filename at runtime (read during OPEN) by using either a variable name in the ASSING clause (this is the common option) instead of a literal, or by using a literal and set DD_assignname in the environment, for example by SET ENVIRONMENT - but the ASSIGN TO variable-name is much more clear, especially when adjusting within the program.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
IF, I am reading this correctly you have a ISAM file with four alternative keys defined in addition to the primary one so that you can select which one to use at any one point ?
If so, then there is no nead to change the file name as all five key indexes are linked to the one file i.e., using BDB this creates the primary file plus one key file for each of the alternate keys.
For example :
Customers.dat
Customers.dat.1
Customers.dat.2
thru to :
Customers.dat.4
The first holds the data and the primary keys and the other four hold each alternate key set.
So doing a READ with one of the KEYS selected does the job.
In the Proc. Div a routine in a specific F.H. (File Handler) that handles the processing for this file is called as needed with the following code within :
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2021-09-14
Hi Vince (or is it Bryan?),
No.. I am good with the files themselves.. Just want the flexibility of
assigning output a unique name depending on the key I use.
I built a parmfile that I use for the run.. and in it I choose the Key and
provide some starting values for the lookups, for each key.
What I would like, ideally, is the means to say.. if (for example) I am
reading the Transaction file by date.. my output file (currently Acct.rpt)
might be called Acct_Date.rpt,
and lookup by Name might be Acct_Name.rpt and so on.
I have never seen a means of dynamically assigning a file name from within
a program but hoped one of smart contributors to this page have done it.
Thank you,
Steve
Mod edit to remove reply-to
Last edit: Simon Sobisch 2021-09-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Vince (or is it Bryan?),
Thought I had replied; but dont see it here. No, what I was asking about Simon and Laszlo answered. A way to dynamically assign a name to files (in this case.. based on the keys I am using.
I have an external parmfile and in it I specify keys for the run and starting values. I can use it to pass a file name too, if I didnt want to set it within the program.
Everything is fitting together well. Still working on the online maintenance program and working out the bugs.
Thanks again for your help.
Steve
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your post got to moderation as you were note signed in / answered from an address that does not match your SF user profile.
I've found 5 spare minutes to work through the moderation que and it now is in.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
to anonymous if you are still there.
Here is a small program that reads 3 of 6 possible input files and writes one of two possible output files. A command line switch/argument dictate which files to read and write. Your parm file could supply the file names. The key lies in the assign clause and the associated working storage identifier it points to.
The important parts are attached.cob. The compile list is also attached. The program has a lot of copy books, so it won't compile, but they are not relevant to your question of how to dynamically assign a file name.
Michael
Thank you Mike. . I did get it solved some time ago; but appreciate you taking the time to respond. Hopefully it will help others who are trying to set their file names externally, eliminating the need to recompile everytime the file name might change.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi guys,
I have a program that has 5 keys. When i run using a certain key.. would be nice to name the output file to reflect that key. instead of the generic name in the Assign clause. Is there a way for me to reassign the file name from within the program? I sure could not find it in the manuals.
Thank you,
Steve
You can adjust the filename at runtime (read during
OPEN
) by using either a variable name in theASSING
clause (this is the common option) instead of a literal, or by using a literal and setDD_assignname
in the environment, for example bySET ENVIRONMENT
- but theASSIGN TO variable-name
is much more clear, especially when adjusting within the program.Nice. That is what I will do.. Thank you!!
Here is an example with variable:
https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk/samples/prothsearch/prothtest.cob
László
That is perfect! Thank you, Laszlo!!
IF, I am reading this correctly you have a ISAM file with four alternative keys defined in addition to the primary one so that you can select which one to use at any one point ?
If so, then there is no nead to change the file name as all five key indexes are linked to the one file i.e., using BDB this creates the primary file plus one key file for each of the alternate keys.
For example :
Customers.dat
Customers.dat.1
Customers.dat.2
thru to :
Customers.dat.4
The first holds the data and the primary keys and the other four hold each alternate key set.
So doing a READ with one of the KEYS selected does the job.
Small example:
In WS
...... rest cut ....
In the Proc. Div a routine in a specific F.H. (File Handler) that handles the processing for this file is called as needed with the following code within :
Hi Vince (or is it Bryan?),
No.. I am good with the files themselves.. Just want the flexibility of
assigning output a unique name depending on the key I use.
I built a parmfile that I use for the run.. and in it I choose the Key and
provide some starting values for the lookups, for each key.
What I would like, ideally, is the means to say.. if (for example) I am
reading the Transaction file by date.. my output file (currently Acct.rpt)
might be called Acct_Date.rpt,
and lookup by Name might be Acct_Name.rpt and so on.
I have never seen a means of dynamically assigning a file name from within
a program but hoped one of smart contributors to this page have done it.
Thank you,
Steve
Mod edit to remove reply-to
Last edit: Simon Sobisch 2021-09-14
Hi Vince (or is it Bryan?),
Thought I had replied; but dont see it here. No, what I was asking about Simon and Laszlo answered. A way to dynamically assign a name to files (in this case.. based on the keys I am using.
I have an external parmfile and in it I specify keys for the run and starting values. I can use it to pass a file name too, if I didnt want to set it within the program.
Everything is fitting together well. Still working on the online maintenance program and working out the bugs.
Thanks again for your help.
Steve
Your post got to moderation as you were note signed in / answered from an address that does not match your SF user profile.
I've found 5 spare minutes to work through the moderation que and it now is in.
Solved, thanks to input from Simon and Laszlo. Much appreciated.
to anonymous if you are still there.
Here is a small program that reads 3 of 6 possible input files and writes one of two possible output files. A command line switch/argument dictate which files to read and write. Your parm file could supply the file names. The key lies in the assign clause and the associated working storage identifier it points to.
The important parts are attached.cob. The compile list is also attached. The program has a lot of copy books, so it won't compile, but they are not relevant to your question of how to dynamically assign a file name.
Michael
Thank you Mike. . I did get it solved some time ago; but appreciate you taking the time to respond. Hopefully it will help others who are trying to set their file names externally, eliminating the need to recompile everytime the file name might change.