• VMS Cobol filename issue

    From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Thu Dec 21 09:54:04 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jeffrey_dsi@21:1/5 to All on Thu Dec 21 09:24:25 2023
    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?

    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




    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Thu Dec 21 13:19:23 2023
    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

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Thu Dec 21 13:32:07 2023
    On 12/21/2023 1:19 PM, Arne Vajhøj wrote:
    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

    tbl is not necessary - LNM$PROCESS is default.

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jim Duff@21:1/5 to All on Fri Dec 22 09:36:17 2023
    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?

    [snip]


    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.

    Jim
    --
    https://www.eight-cubed.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Jim Duff on Thu Dec 21 18:54:26 2023
    On 12/21/2023 5:36 PM, Jim Duff wrote:
    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.

    That is way nicer than lib$set_logical.

    Thanks.

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)