::cobolfree$SETSOURCEFORMAT"FREE"IDENTIFICATIONDIVISION.PROGRAM-ID.Multiplier.AUTHOR.MichaelCoughlan.*ExampleprogramusingACCEPT,DISPLAYandMULTIPLYto*gettwosingledigitnumbersfromtheuserandmultiplythemtogetherDATADIVISION.WORKING-STORAGESECTION.01Num1PIC9VALUEZEROS.01Num2PIC9VALUEZEROS.01ResultPIC99VALUEZEROS.PROCEDUREDIVISION.DISPLAY"Enter first number (1 digit) : "WITHNOADVANCING.ACCEPTNum1.DISPLAY"Enter second number (1 digit) : "WITHNOADVANCING.ACCEPTNum2.MULTIPLYNum1BYNum2GIVINGResult.DISPLAY"Result is = ",Result.STOPRUN.
Mod edit, for colour
Last edit: Brian Tiffin 2019-03-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try this slight mod, due to syntax from the Limerick site.
::cobolfree>>SOURCEFORMATFREEIDENTIFICATIONDIVISION.PROGRAM-ID.Multiplier.AUTHOR.MichaelCoughlan.*>ExampleprogramusingACCEPT,DISPLAYandMULTIPLYto*>gettwosingledigitnumbersfromtheuserandmultiplythemtogetherDATADIVISION.WORKING-STORAGESECTION.01Num1PIC9VALUEZEROS.01Num2PIC9VALUEZEROS.01ResultPIC99VALUEZEROS.PROCEDUREDIVISION.DISPLAY"Enter first number (1 digit) : "WITHNOADVANCING.ACCEPTNum1.DISPLAY"Enter second number (1 digit) : "WITHNOADVANCING.ACCEPTNum2.MULTIPLYNum1BYNum2GIVINGResult.DISPLAY"Result is = ",Result.STOPRUN.
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.
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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).
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Mod edit, for colour
Last edit: Brian Tiffin 2019-03-31
Try this slight mod, due to syntax from the Limerick site.
Runs as:
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
Hi Larry, welcome to GnuCOBOL.
The code doesn't work because it has three issues:
1: The first line looks like a
$SETstatement, but it isn't because of the space within the "word"2: When currently in fixed-format a
$SETstatement must begin in column 7 (yes, this works) or later and may not exceed column 723. According to MF docs
$SET SOURCEFORMAT"FREE"automatically setsNOMFCOMMENT, 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
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 after3 -
$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$SETis) 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 SOURCEFORMATis 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>> SOURCEFORMATin 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]
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.
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
-freeon 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.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
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.
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
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
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