Discussion:
hello world doesn't work
(too old to reply)
Cydrome Leader
2005-09-26 04:49:24 UTC
Permalink
I'm trying this hello world program with OpenCOBOL 0.31

* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.


and trying to compile with:

[host]user:~/cobol$ cobc hello.cob

and get:

hello.cob:1: warning: invalid indicator 'l' at column 7
hello.cob:1: syntax error, unexpected WORD, expecting IDENTIFICATION

What does any of this mean, and what's wrong here?
Richard
2005-09-26 05:23:58 UTC
Permalink
Post by Cydrome Leader
OpenCOBOL 0.31
Standard ANS'85 Cobol programs are laid out as follows:

Columns 1-6 Sequence number, may be left blank

Column 7 Indicator column, may have a value of:
* - line is a comment
- - line is a continuation
D - line is a 'debugging line'

Columns 8-11 Area A
Columns 12-72 Area B

Certain things need to, or can, start in Area A such as labels, and
other things, such as statements, need to start in Area B.

Some Cobol systems have extensions that allow frre format source,
OpenCobol does not.

Adjust your program to the correct layout and it will get over that
particular problem.

You will note that it is complaining about the 'l' of 'sample' because
this is in Column 7.
Cydrome Leader
2005-09-26 05:44:56 UTC
Permalink
Post by Richard
Post by Cydrome Leader
OpenCOBOL 0.31
Columns 1-6 Sequence number, may be left blank
* - line is a comment
- - line is a continuation
D - line is a 'debugging line'
Columns 8-11 Area A
Columns 12-72 Area B
Certain things need to, or can, start in Area A such as labels, and
other things, such as statements, need to start in Area B.
Some Cobol systems have extensions that allow frre format source,
OpenCobol does not.
Adjust your program to the correct layout and it will get over that
particular problem.
You will note that it is complaining about the 'l' of 'sample' because
this is in Column 7.
I don't know know enough about what each line is to know where they
belong.

How would you format this program? I can only get it to compile if all
text starts on column 7. The program won't print anything when run though.
Moving anyting over past column 7 = won't compile.
Volker
2005-09-26 07:20:40 UTC
Permalink
Post by Richard
Post by Cydrome Leader
OpenCOBOL 0.31
Columns 1-6 Sequence number, may be left blank
* - line is a comment
- - line is a continuation
D - line is a 'debugging line'
Columns 8-11 Area A
Columns 12-72 Area B
Certain things need to, or can, start in Area A such as labels, and
other things, such as statements, need to start in Area B.
12345678901234567890...
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.

V.
Cydrome Leader
2005-09-26 08:47:51 UTC
Permalink
Post by Volker
Post by Richard
Post by Cydrome Leader
OpenCOBOL 0.31
Columns 1-6 Sequence number, may be left blank
* - line is a comment
- - line is a continuation
D - line is a 'debugging line'
Columns 8-11 Area A
Columns 12-72 Area B
Certain things need to, or can, start in Area A such as labels, and
other things, such as statements, need to start in Area B.
12345678901234567890...
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
V.
This works fine. I suspect I did have a tab after moving text around. I'm
fascinated by the BASIC/foxpro like syntax. Perl disgusts me so I guess
this is the language for me learn.
John Culleton
2005-09-26 19:02:56 UTC
Permalink
Post by Cydrome Leader
Post by Volker
Post by Richard
Post by Cydrome Leader
OpenCOBOL 0.31
Columns 1-6 Sequence number, may be left blank
* - line is a comment
- - line is a continuation
D - line is a 'debugging line'
Columns 8-11 Area A
Columns 12-72 Area B
Certain things need to, or can, start in Area A such as labels, and
other things, such as statements, need to start in Area B.
12345678901234567890...
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
V.
This works fine. I suspect I did have a tab after moving text around. I'm
fascinated by the BASIC/foxpro like syntax. Perl disgusts me so I guess
this is the language for me learn.
I suggest that you use a programmer' editor such as Gvim. If you specify
syntax checking and subequently you get things in the wrong column then the
editor will color the entire line in red with white print.

Also I suggest you borrow get a good college text on COBOL. Or look in the
manuals that come with a commercial version. I learned COBOL (and FORTRAN
and PL/I) from the self teaching booklets from IBM, the famous "Green
Books. Don't think they are around any more.

One trick: Even though line numbers are no longer required I alwasy start
off from scratch with the folLlowing statements:
123456 IDENTIFICATION DIVISION.
123456 PROGRAM-ID.

This gives a visual guide to the correct placement of things.
Or better, start off with a tamplate program. Just copy the file below that
I call "template.cbl" to another file name. Then expand the copy.

----------------------------------------------------------------
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TEMPLATE.
000030 AUTHOR. JOHN CULLETON.
000040 INSTALLATION. WEXFORDPRESS
000045 Eldersburg MD.
000050*REMARKS.
000060* THIS IS A TEMPLATE FOR OPEN COBOL AND HTCOBOL.
000070 ENVIRONMENT DIVISION.
000080
000090 CONFIGURATION SECTION.
000100 SOURCE-COMPUTER.
000110 Linux.
000120 OBJECT-COMPUTER.
000230 Linux.
000140
000150 INPUT-OUTPUT SECTION.
000160 FILE-CONTROL.
000170 SELECT PRINTFILE ASSIGN TO PRINTER.
000180 DATA DIVISION.
000190
000200 FILE SECTION.
000210
000220 WORKING-STORAGE SECTION.
000230
000240 PROCEDURE DIVISION.
000250 001-MAIN-PROCEDURE.
000260 DISPLAY "TEMPLATE".
000270 STOP RUN.
----------------------------------------------
--
John Culleton
Able Indexers and Typesetters
Richard
2005-09-26 07:55:03 UTC
Permalink
The asterisk goes in colum 7
Headers and labels start in column 8.
Statements (DISPLAY, STOP) start in column 12.

* Sample COBOL program <- * in 7
IDENTIFICATION DIVISION. <- I in 8
PROGRAM-ID. hello. <- P in 8
PROCEDURE DIVISION. <- P in 8
DISPLAY "Hello World!". <- D in 12
STOP RUN. <- S in 12
Post by Cydrome Leader
Moving anyting over past column 7 = won't compile.
Do not use tab characters. It may be that your editor is noticing that
colsumn 1-7 are spaces and putting a single tab character instead of
the spaces. Get a better editor.

Alternately put sequence numbers in columns 1-6. ie 000010 for the
first line 000020 for the second line etc. This is not needed by Cobol
but may be required to stop your editor munting the code by using tabs.

The code does compile and run correctly when in the correct format.
The compile command is:

cobc -fmain hello.cbl
Continue reading on narkive:
Loading...