Menu

Error: Invalid indicator 'F' at column 7

2019-03-31
2022-11-17
  • Larry Crouch

    Larry Crouch - 2019-03-31

    I have a very simple cobol program that is not compiling. Can someone tell me what is wrong?
    I'm running Ubuntu 16.04

    I have purged and reinstalled the libcob1 and open-cobol to no effect.

    larry@capricorn:~/longspur/cobol/test$ cobc sample1.cob
    sample1.cob:1: Error: Invalid indicator 'F' at column 7
    larry@capricorn:~/longspur/cobol/test$ cat sample1.cob

    ::cobolfree
    
        $ SET SOURCEFORMAT"FREE"
    IDENTIFICATION DIVISION.
    PROGRAM-ID.  Multiplier.
    AUTHOR.  Michael Coughlan.
    * Example program using ACCEPT, DISPLAY and MULTIPLY to 
    * get two single digit numbers from the user and multiply them together
    
    DATA DIVISION.
    
    WORKING-STORAGE SECTION.
    01  Num1                                PIC 9  VALUE ZEROS.
    01  Num2                                PIC 9  VALUE ZEROS.
    01  Result                              PIC 99 VALUE ZEROS.
    
    PROCEDURE DIVISION.
        DISPLAY "Enter first number  (1 digit) : " WITH NO ADVANCING.
        ACCEPT Num1.
        DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
        ACCEPT Num2.
        MULTIPLY Num1 BY Num2 GIVING Result.
        DISPLAY "Result is = ", Result.
        STOP RUN.
    

    Mod edit, for colour

     

    Last edit: Brian Tiffin 2019-03-31
  • Brian Tiffin

    Brian Tiffin - 2019-03-31

    Try this slight mod, due to syntax from the Limerick site.

    ::cobolfree
           >>SOURCE FORMAT FREE
    IDENTIFICATION DIVISION.
    PROGRAM-ID.  Multiplier.
    AUTHOR.  Michael Coughlan.
    *> Example program using ACCEPT, DISPLAY and MULTIPLY to
    *> get two single digit numbers from the user and multiply them together
    
    DATA DIVISION.
    
    WORKING-STORAGE SECTION.
    01  Num1                                PIC 9  VALUE ZEROS.
    01  Num2                                PIC 9  VALUE ZEROS.
    01  Result                              PIC 99 VALUE ZEROS.
    
    PROCEDURE DIVISION.
        DISPLAY "Enter first number  (1 digit) : " WITH NO ADVANCING.
        ACCEPT Num1.
        DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
        ACCEPT Num2.
        MULTIPLY Num1 BY Num2 GIVING Result.
        DISPLAY "Result is = ", Result.
        STOP RUN.
    

    Runs as:

    ::text
    prompt$ cobc -xj Multiplier.cob
    Enter first number  (1 digit) :
    ...
    

    Note the change to the top directive line, default is FIXED form, and the directive >> has to start in column 8.

    Also note, that in FREE form, the line comment character has to become *> and not just the asterisk as there is no concept of column-7 in FREE format. There is a configuration flag for asterisk in column 1 support (not overly recommended as it can lead to rare/subtle ambiguities). Not needed with the small code change above.

    Attached.

    Cheers,
    Blue

     

    Last edit: Brian Tiffin 2019-03-31
  • Simon Sobisch

    Simon Sobisch - 2019-03-31

    Hi Larry, welcome to GnuCOBOL.

    The code doesn't work because it has three issues:

    1: The first line looks like a $SET statement, but it isn't because of the space within the "word"
    2: When currently in fixed-format a $SET statement must begin in column 7 (yes, this works) or later and may not exceed column 72
    3. According to MF docs $SET SOURCEFORMAT"FREE" automatically sets NOMFCOMMENT, therefore the asterisk in column 1 should even not work if explicit requested for the compilation group by -fmfcomment (note: GC actually cheats by not parsing mf-comment in free format at all, it should work with MF when the statement is changed to $SET SOURCEFORMAT"FREE" MFCOMMENT)

    Using cobol standard options to set the source-format and using floating comments *> should work with more compilers in general.

    BTW: If possible update your outdated version (which actually passed its 10th birthday one month ago).

     

    Last edit: Simon Sobisch 2019-03-31
    • Simon Sobisch

      Simon Sobisch - 2022-11-17

      I stand corrected for 1 and 3 - and both will be corrected in GnuCOBOL 3.2rc-1 (the first time in OpenCOBOL/GnuCOBOL).

      1 - GnuCOBOL had that limit, but that wasn't according to MF docs, @nberth fixed that with [r4821]
      2 - the $ must be either at column 7 or after
      3 - $SET SOURCEFORMAT"FREE"(in general, but not with MF!) is different to >> SOURCE FORMAT FREE - the second comes from iso 2002 (now also usable with MF(and interpreted as $SET is) while $SET SOURCEFORMAT"FREE" is setting the X/Open COBOL free format - which by definition has the indicator column moved to col1 - so an asterisk there does work as comment line - @nbert will commit the fix for that soon (it is already "ready for svn)
      Also mfcomment can be re-enabled after that directive by its own directive - and will then mean that all comment lines will be removed from the printing (I did not verify that, just inspecting the docs), only inline comments (so *> starting at or after column 2 will then be included in the listing)

      Note: using X/Open free format will only happen if -std=mf (or -std=mf-strict) was used, otherwise COBOL2002 free-form reference-format will be chosen.
      There was consideration to internally set the MF dialect if $SET SOURCEFORMAT is seen, but as there are likely lots of sources that originated in some MF environment and was later converted to GnuCOBOL, then extended - and also because the same rules apply to >> SOURCEFORMAT in MF) this idea was dropped - it will always depend on the std in GnuCOBOL (and likely someday this can also be configured in-source via $SET DIALECT).

       

      Related

      Commit: [r4821]

  • Eugenio Di Lorenzo

    In order to make the compiler more modern, I would suggest taking the FREE FORMAT as default instead of the FIXED FORMAT that I think is now more than obsolete.
    Nowadays it no longer makes sense to develop COBOL source in the FIXED FORMAT, I would not recommend it to anyone. It must exist only to have compatibility with the past.

     
    • Simon Sobisch

      Simon Sobisch - 2019-03-31

      And compatibility is something that COBOL is quite about, isn't it?
      Actually many tools out there (editors, preparsers) still require fixed format, which is also the reason that MF documents to not use SOURCEFORMAT"FREE" if their COBSQL parser is used.

      Note: It is completely fine to use -free on the command line in general and use only a directive to fixed-form reference-format where needed. If/when Jim finishes his "on-site configuration" for cobc you could set this default for a complete installation.

       
    • Mário Matos

      Mário Matos - 2019-04-02

      Well, FIXED format is kinda "legacy" but, like Simon said, should be preserved. I can use both in a single source file :-)

      See attached COPYFILE...

      MM

       
  • Anonymous

    Anonymous - 2019-03-31

    First of all thank you for your help. I deleted the $SET... first line and used -free on the command line as in cobc -x -free sample1.cob and it worked fine.

     
    • Anonymous

      Anonymous - 2019-04-03

      I'm trying to learn Cobol and so far I understand everything to this
      point. These examples are from
      http://www.csis.ul.ie/cobol/examples/default.htm#Direct
      Does cobc (open-cobol) include the report writer?
      I'm asking because I downloaded some Cobol examples and some of them use
      the report writer. Everything seems to work right up to the point of
      actually generating the example report.
      I created the needed files STUDPAY.DAT and STUDMAST.DAT.

      Here is the sample Cobol...

      Mod edit; removing some Michael Coughlan copyrighted material

      Link is http://www.csis.ul.ie/cobol/exercises/Exm-StudFeesRpt/Prg-StudPay.htm

      --
      Larry Crouch
      larry@larkat.com

       

      Last edit: Brian Tiffin 2019-04-03
      • Brian Tiffin

        Brian Tiffin - 2019-04-03

        Larry, don't hate me, but I removed a code listing. We should ask the author someday, but for now I like to stick to not reproducing the University of Limerick files here in the project space. Replaced the code with a link.

        If this steps on any changes you were attempting to highlight in a modified copy, then perhaps a diff would be better. And apologies for the cut.

        Yep, GnuCOBOL (reportwriter branch, or GC 3+) supports the Report Writer module. Earlier versions, perhaps versions in main distros may not have the module included. But yes.

        Instead of the code listing, Larry, a terminal capture of the compile session can help track down issues (sometimes).

        Cheers,
        Blue

         
  • Anonymous

    Anonymous - 2019-04-03

    That was my bad. I wasn't thinking. Thanks for the reminder about code
    listings.

    Thank you for your time in answering my questions.

     

    Last edit: Simon Sobisch 2019-04-03

Anonymous
Anonymous

Add attachments
Cancel