Menu

#248 Clarification sought for: VALUE OF FILE-ID data-name

unclassified
closed
nobody
6
2024-01-30
2014-07-01
Joe Robbins
No

I believe "VALUE OF FILE-ID data-name-1" in the FD to be a MicroFocus extension. MF says: "The character-string specified in literal-1 or data-name-1 is taken as the external file-name."

I can find no explicit rule in the MF manual that states data-name-1 must be declared (in W-S). Indeed GNU COBOL does NOT fail compile if data-name-1 is undeclared. It is as if data-name-1 is a reference to a long string - but not initialised with any meaningful value.

(COBOL-IT is similar but initialises data-name-1 to "data-name-1" i.e. the internal name of the field itself. So if VALUE OF FILE-ID ws-fid then OPEN OUTPUT generates a file named "ws-fid" in the COB_FILE_PATH directory. Extremely confusing.)

My first question is should GNU-COBOL throw a compile-time error (or at least a warning) if data-name-1 is not declared? My second question is how does the latest version of GNU-COBOL behave at run-time?

The issue I have with the "implicit" declaration of data-name-1 is (like all languages based on implicit declarations) it makes typos extremely difficult to spot. For example:

::cobolfree
FD file1 value of file-id ws-fid1.
1  file1-rec.

WORKING-STORAGE.
1  ws-fid pic x(249) value "my-file-name".

will ignore (typo) "ws-fid" and use empty "ws-fid1", which is not what was intended.

Please try this program: (I think GNU-COBOL will attempt to open a file with an external name of SPACES)

::cobol
       IDENTIFICATION DIVISION.
       PROGRAM-ID. prog.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT file1.
       DATA DIVISION.
       FILE SECTION.
       FD file1 VALUE OF FILE-ID file1-xname.
       1  file1-rec pic x.
       WORKING-STORAGE SECTION.
       1  file1-yname pic x(7) VALUE "./fileY".
       PROCEDURE DIVISION.
           DISPLAY "FID INTENDED [" file1-yname "]".
           DISPLAY "FID ACTUAL   [" file1-xname "]".
           OPEN OUTPUT file1.      
           CLOSE file1.
           DISPLAY "FID USED     [" file1-xname "]".
           STOP RUN.

Discussion

  • Simon Sobisch

    Simon Sobisch - 2014-07-01

    I wasn't aware of this extension and have to lookup it. If I understood it correctly so far it's about setting the file name within the FD paragraph instead of ASSIGN clause in SELECT.

    As there is no test case for it, it is not taken care for, not tested in further development and, as a result from the two reasons before: recently broken (because of the changes that were done because of your [patch#12]) in [r310] :-).
    Is the sample you provided 100% correct? If yes I'll add it to the file tests (and likely will change typeck.c to be more like your original patch, checking assign after FD parsing).

    Just to document my the first try to find out "whom does that extension belong to":

    ::bash
    $ cd config
    $ grep value-of-clause *
    bs2000.conf:value-of-clause:                    obsolete
    cobol2002.conf:value-of-clause:                 unconformable
    cobol85.conf:value-of-clause:                   obsolete
    default.conf:value-of-clause:                   obsolete
    ibm.conf:value-of-clause:                       obsolete
    mf.conf:value-of-clause:                        obsolete
    mvs.conf:value-of-clause:                       obsolete
    

    Either it is part of cobol85 (as obsolete) and all implementors have it or the conf entries need an update, at least for this entry.

    It's at least possible to recognize the typo if you compile your sample with -Wall:

    value_of_fileid.cob: 9: Warning: VALUE OF is obsolete in GNU Cobol
    value_of_fileid.cob: 13: Warning: 'file1-xname' will be implicitly defined
    

    with the result at run-time (using typeck.c from [r309])

    FID INTENDED [./fileY]
    FID ACTUAL   [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ]
    value_of_fileid.cob: 16: libcob: Permanent file error (Status = 30) File : ''
    

    Simon

     
  • Joe Robbins

    Joe Robbins - 2014-08-17

    Hello Simon
    I am far behind in catching up with these postings and this may now be irrelevant ...

    Having done this for years (decades!) using MicroFocus COBOL, I foolishly assumed it was the norm.

    My posting was simply a request for the compiler to check that data-name-1 in ... VALUE OF FILE-ID data-name-1 is actually declared.

    You ask "whom does that extension belong to": I don't know. As I say, we used it in MF COBOL and here is a quote from UNISYS COBOL:

    See attachment for FD syntax.

    data-name-2
    This name is a user-defined word.
    This data-name should be qualified when necessary, but it cannot be subscripted, nor
    can it be described with the USAGE IS INDEX clause.
    This data-name must be in the Working-Storage Section.
    

    The UNISYS accompanying example uses a literal rather than a data-name:

    FD SEQ-FILE
    BLOCK CONTAINS 10 RECORDS
    VALUE OF FILENAME IS "MASTER"
    DATA RECORDS ARE PRIMARY SECONDARY.
    

    Regarding test-cases: I have submitted them in syn-file.at.

     

    Last edit: Joe Robbins 2014-08-17
  • wim niemans

    wim niemans - 2016-01-13

    According to usance, it is the file specification in the ASSIGN clause of the SELECT statement that defines the file name. The ASSIGN clause should be mandatory. Most compilers allow for VALUE OF FILE-ID and show the constraint that file_id should be equal to the ASSIGN clause. That clause should have the constraint that file_id is a literal or is defined in working storage.

     

    Last edit: wim niemans 2016-01-13
    • Vincent (Bryan) Coen

      Don't know what compiler you are using but with v2 it produces:

      cobc -x test1.cbl
      test1.cbl: 6: Error: ASSIGN clause is required for file 'file1'
      

      Which is what I would expect as the ASSIGN clause is missing.

      Small point Cobol-IT compiler is taken from an old version of v1.1 which in itself is using old code compared to v2 series compilers.
      Cobol-IT compiler does contain a fair number of bugs as as they are not supplying the sources which in itself is a breach of the license that was issued along with the code for the v1.0 and v1.1 code bases - and for that matter the latest versions..
      Try compiling the code that they do offer which does not match the binaries they send out!

       

      Last edit: Simon Sobisch 2017-10-29
  • Simon Sobisch

    Simon Sobisch - 2017-10-29

    Ticket moved from /p/open-cobol/patches/17/

     
  • Simon Sobisch

    Simon Sobisch - 2017-10-29
    • assigned_to: Edward Hart
    • Group: Test --> unclassified
    • Priority: 1 --> 6
     
  • Simon Sobisch

    Simon Sobisch - 2017-10-29

    Assigned to Edward Hart to recheck. Note: this is not urgend...

     
  • Simon Sobisch

    Simon Sobisch - 2024-01-27
    • labels: --> ASSIGN, fileio
    • status: open --> closed
    • assigned_to: Edward Hart --> nobody
     
  • Simon Sobisch

    Simon Sobisch - 2024-01-27

    This was solved long time ago - GnuCOBOL uses the VALUE OF clause as an obsolete option to define the filename. It is an "alternative" way of using the ASSIGN clause.

    If the target of it is a literal - then this is the name, with the option of replacing $envvar parts. If it is a variable in the code, then this is used. If there's no variable in the code with this identifier, then this is created (raises a warning as noted above) and that variable has an implicit VALUE clause that is identical to the file name (not empty any more) - so if you do nothing, then the file will be created with its name.

    As far as I see - nothing more to do here, if there is, please post and we can re-inspect.

     
  • Eugenio Di Lorenzo

    The documentation for the VALUE OF FILE-ID clause at 6.2.1 of Programmars Guide is rather lacking. See screenshot attached
    For example, nothing is specified about the meaning of implementor-name-1.
    In my opinion it would be appropriate to add some descriptive specifications.
    Or at least an example like the small working following program:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. VALUEOFFILEID.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT FILE1 ASSIGN TO DISK
           ORGANIZATION    IS LINE SEQUENTIAL
           FILE STATUS     IS w-fs.
       DATA DIVISION.
       FILE SECTION.
       FD file1 VALUE OF FILE-ID file1-name.
       01  file1-rec  pic x(100).
       WORKING-STORAGE SECTION.
       01  file1-name pic x(20) VALUE "file1.TXT".
       01  w-fs       PIC XX    value space.
    
       PROCEDURE DIVISION.
           DISPLAY "FILE-ID [" file1-name "]".
           OPEN OUTPUT file1.
           display 'file status OPEN =   ' w-fs
           perform 10 times
                 move all "X" to file1-rec
                 write file1-rec
                 display 'file status write =  ' w-fs
           end-perform
           CLOSE file1.
           display 'file status CLOSE =  ' w-fs
           STOP RUN.
    
     
    • Simon Sobisch

      Simon Sobisch - 2024-01-29

      I think the only thing that should be added is to note that the implementor-name-1 FILE-ID is used as the ASSIGN clause of the SELECT paragraph (see examples there), if this wasn't specified (= ASSIGN TO wins, if both are specified).
      If there's an example to add somewhere (haven't checked), then this needs to be added there, not "here" or even "twice".

      @dilodilo Can you please suggest a change to the according tex file(s)?

       
      • Eugenio Di Lorenzo

        The following text could be added to chapter 6.2.1 as point n.15.

        n. 15. GnuCOBOL uses the VALUE OF clause as an obsolete option to define the filename. It is an "alternative" way of using the ASSIGN clause.

        If the target of it is a literal - then this is the name.
        If it is a variable in the code, then this is used. If there's no variable in the code with this identifier, then this is created (raises a warning as noted above) and that variable has an implicit VALUE clause that is identical to the file name (not empty any more) - so if you do nothing, then the file will be created with its name.

        implementor-name-1 can take the value: FILE-ID and is used to specify the external name of the file as literal-1 (only if this external name has not been specified in the corresponding SELECT clause). Example:
        SELECT file1 ASSIGN TO DISK (without an external name ...
        ...
        FD File1 VALUE of FILE-ID "file1.txt".

         

        Last edit: Eugenio Di Lorenzo 2024-01-29
  • Vincent (Bryan) Coen

    Done.

     

Log in to post a comment.

MongoDB Logo MongoDB