Even considering that in general I do not understand
Cobol, then this one has me puzzled.
How does one open a file with the filename being variable?
Docs says:
<quote>
On OpenVMS, if file-spec is not a literal, the compiler:
• Translates hyphens in the COBOL word to underline characters
• Treats the word as if it were enclosed in quotation marks
...
If you specify ASSIGN TO unquoted string, you need not specify this name
in the WORKING-STORAGE section. For example:
ASSIGN TO TEST1
This assignment would use "TEST1.DAT" on OpenVMS Alpha and I64.
On UNIX systems, you would specify:
ASSIGN TO "TEST1.DAT"
or:
ASSIGN TO TEST1
...
WORKING-STORAGE SECTION.
01 TEST1 PIC X(9) VALUE IS "TEST1.DAT".
</quote>
So easy to do in OSF/1 aka DUNIX aka Tru64, but how
does one do it on VMS??
Arne
On 12/21/23 06:54, Arne Vajhøj wrote:
Even considering that in general I do not understand
Cobol, then this one has me puzzled.
How does one open a file with the filename being variable?
The only way I've seen to make the filename in Cobol a variable is to
use a logical.
ASSIGN TO "TEST"
and before the program is run
$ DEFINE TEST PROD_DATA:MYFILE.DAT
On 12/21/2023 12:24 PM, jeffrey_dsi wrote:
On 12/21/23 06:54, Arne Vajhøj wrote:
Even considering that in general I do not understand
Cobol, then this one has me puzzled.
How does one open a file with the filename being variable?
The only way I've seen to make the filename in Cobol a variable is to
use a logical.
ASSIGN TO "TEST"
and before the program is run
$ DEFINE TEST PROD_DATA:MYFILE.DAT
Thanks.
Really weird.
I ended up with:
file-control.
select in-file assign to "INFNM" organization is line sequential.
...
working-storage section.
01 infnm pic x(5) value "INFNM".
01 cmd pic x(80).
01 cmdlen pic s9(8) comp.
01 tbl pic x(11) value "LNM$PROCESS".
...
procedure division.
main-paragraph.
call "lib$get_foreign" using by descriptor cmd, omitted, by
reference cmdlen
call "lib$set_logical" using by descriptor infnm, by descriptor cmd(1:cmdlen), by descriptor tbl
open input in-file
Even considering that in general I do not understand
Cobol, then this one has me puzzled.
How does one open a file with the filename being variable?
[snip]
On 22/12/23 01:54, Arne Vajhøj wrote:
Even considering that in general I do not understand
Cobol, then this one has me puzzled.
How does one open a file with the filename being variable?
By using that value of clause on the FD. Example:
identification division.
program-id. demo.
environment division.
input-output section.
file-control.
select in-file assign to junk
organization is line sequential.
data division.
file section.
fd in-file
value of id is file-name
record is varying in size.
01 inrec.
03 rec pic x(80).
working-storage section.
01 file-name pic x(20).
procedure division.
0-begin.
move "x.x" to file-name.
open input in-file.
read in-file at end continue.
display inrec.
0-end.
close in-file.
stop run.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 438 |
Nodes: | 16 (2 / 14) |
Uptime: | 236:46:26 |
Calls: | 9,145 |
Calls today: | 1 |
Files: | 13,432 |
D/L today: |
1 files (2,685K bytes) |
Messages: | 6,039,328 |