Re: newbie question on cobol syntax
- From: "James J. Gavan" <jgavandeletethis@xxxxxxx>
- Date: Sun, 22 Apr 2007 22:24:22 GMT
Mayer wrote:
Hello:Well first off - if you can, avoid using both compilers - you will get
I noticed two styles of cobol syntax:
main.
display "hello"
display "goodbye"
stop run
.
vs.
main.
display "hello".
display "goodbye".
stop run.
Some books use the first, others the second. I have no idea what's the
difference between them, but I note the following:
- MF Cobol/DOS allows both
- RM Cobol/DOS allows only the second, i.e., requires a period at the
end of each statement.
Can someone please explain to me the function of the period in cobol,
what is the basis for the difference in syntax, and what is
recommended.
Thanks,
Mayer
yourself in one hell of a mess :-)
Are you sure about RM/COBOL being adamant about periods/full-stops, or
is it perhaps what you interpreted ? The following extract from a very
old RM compiler, Version 2 and no longer supported :-
--------------------------------------------------------------------------
B040-ENTER-ID.
ACCEPT WS-SCREEN-PROGRAM, POSITION 40, LINE 15,
PROMPT "-", ECHO, CONVERT, REVERSE, NO BEEP
ACCEPT WS-SCREEN-PAGE, POSITION 43, LINE 15,
PROMPT "-", ECHO, CONVERT, REVERSE, NO BEEP
IF WS-SCREEN-PROGRAM = ZEROES
MOVE "Are you sure - Program Zero ? y/n"
TO WS-INSTRUCTION-TEXT
MOVE SPACES TO WS-INSTRUCTION-EXIT
PERFORM Z040-INSTRUCTION-LINE
PERFORM Z025-ANSWER
IF WS-ANSWER = "N"
GO TO B040-ENTER-ID.
IF WS-SCREEN-PAGE = ZEROES
MOVE "Screen ID can't be zeroes"
TO WS-ERROR-MESSAGE-TEXT
PERFORM Z050-ERROR-MESSAGE
GO TO B040-ENTER-ID.
IF WS-SELECTION NOT = 2
MOVE ZEROES TO WS-LINE-ID
ELSE PERFORM B050-LINE-ID.
B050-LINE-ID.
ACCEPT WS-LINE-ID, POSITION 45, LINE 15,
PROMPT "-", ECHO, CONVERT, REVERSE, NO BEEP
IF WS-LINE-ID = ZEROES
MOVE "Line ID can't be zeroes"
TO WS-ERROR-MESSAGE-TEXT
PERFORM Z050-ERROR-MESSAGE
GO TO B050-LINE-ID.
C010-RECORD.
IF WS-SELECTION = 1
MOVE 3 TO WS-NUMBER-OF-QUESTION
PERFORM C020-DISPLAY-SCREEN
PERFORM C030-READ-RECORD
ELSE MOVE 4 TO WS-NUMBER-OF-QUESTION
PERFORM D020-DISPLAY-SCREEN
PERFORM C030-READ-RECORD.
IF WS-RECORD-EXISTS = "Y"
IF WS-SELECTION = 1
PERFORM C040-DISPLAY-VALUES
ELSE PERFORM D040-DISPLAY-VALUES.
IF WS-RECORD-EXISTS = "N"
MOVE
"No record - do you want to input ? y/n"
TO WS-INSTRUCTION-TEXT
MOVE SPACES TO WS-INSTRUCTION-EXIT
PERFORM Z040-INSTRUCTION-LINE
PERFORM Z025-ANSWER
IF WS-ANSWER = "Y"
PERFORM C060-ENTER-NEW-DATA
ELSE GO TO C010-EXIT.
PERFORM C070-LINE-NUMBER THROUGH C070-EXIT.
000000 C010-EXIT.
EXIT.
---------------------------------------------------------------------------------------
If you look at the above code your compiler should certainly hiccup if
you leave out the very last period/full-stop before the next paragraph
name. If you have perform PARAGRAPH-NAME-A and the para-name isn't
preceded by a period, you should get an error like "Invalid Paragraph Name".
I tried searching the latest version of Net Express for "period", "full
stop" - no luck. Familiarize yourself with END SCOPE Terminators - which
weren't around when I wrote the above code.
In written English we finalize our thoughts by putting a period at the
end of a sentence. We group a series of like sentences into a paragraph
and terminate that with a CR/LF(Carriage-Return, Line Feed), have a
blank line and start a new paragraph on the next line.
Translate that to COBOL - using Scope Terminators, mainly you only need
a period preceding the next 'heading' Section, Paragraph-Name etc.
Let's take the very last sequence above and show how it could be edited
to operate with scope terminators "-
IF (#1) WS-RECORD-EXISTS = "N"
MOVE
"No record - do you want to input ? y/n"
TO WS-INSTRUCTION-TEXT
MOVE SPACES TO WS-INSTRUCTION-EXIT
PERFORM Z040-INSTRUCTION-LINE
PERFORM Z025-ANSWER
IF (#2) WS-ANSWER = "Y"
PERFORM C060-ENTER-NEW-DATA
ELSE (#2) GO TO C010-EXIT
----> don't need the period here replaced by following end-if
----> END-IF (#2)
----> END-IF (#1)
PERFORM C070-LINE-NUMBER THROUGH C070-EXIT.
----> If I didn't have the line 'PERFORM C070-LINE...." nor the
two lines for C010-EXIT, then a period would be required after the final
'END-IF', denoting the end of the current paragraph.
000000 C010-EXIT.
EXIT.
Note the two 'IF' s are paired off with an END-IF and we don't need any
intervening periods. (Scope Terminators are the equivalent of something
being finished with a period).
Not a very expansive explanation but if you are saying that RM/COBOL is
rejecting the following, then it might be useful to post the full source
that you are getting errors for, plus the error messasges in the following :-
main.
display "hello"
display "goodbye"
stop run
.
Just a thought, it's so long ago. Doesn't 'old' RM require something like :-
MAIN-SECTION.
FIRST-PARAGRAPH. ?????????
display "hello"
display "goodbye"
stop run
..
And 'Yes' you DEFINITELY need that period after STOP RUN :-)
Jimmy
.
- Follow-Ups:
- Re: newbie question on cobol syntax
- From: James J. Gavan
- Re: newbie question on cobol syntax
- References:
- newbie question on cobol syntax
- From: Mayer
- newbie question on cobol syntax
- Prev by Date: Re: newbie question on cobol syntax
- Next by Date: Re: newbie question on cobol syntax
- Previous by thread: Re: newbie question on cobol syntax
- Next by thread: Re: newbie question on cobol syntax
- Index(es):
Relevant Pages
|