I'm new to Cobol and I'd like to understand continuation if a line is too long. I know that there is a free form, but originally (strict mode) the line length is limited.
I'd like to split the following line:
PERFORM VARYING WS-INDEX FROM 2 BY 1 UNTIL WS-INDEX > WS-FILE-LEN
If I try to split it with "-" in the continuation line, I can do anything (placing multiple spaces after the first line and some in front of the second one), but the spaces are trimmed. So this works:
PERFORM VARYING WS-INDEX FROM 2 BY 1 UN
- TIL WS-INDEX > WS-FILE-LEN
But this doesn't (because "1UNTIL" is invalid):
PERFORM VARYING WS-INDEX FROM 2 BY 1
- UNTIL WS-INDEX > WS-FILE-LEN
I use GnuCobol under Linux.
cobc -x -std=cobol2014
Is that intentional or is there any command line option, or how can I done this issue?
In general you can have as many line breaks as you want outside of literals + names.
Use of line concatenation for literals works from "rest of previous line" (= normally space-filled to column 72) to "start of first literal (so you need a literal start).
Use of line concatenation for word-splitting always works from last non-separator (normally last character) to "start of first element on next line".
Both your first UN
-
TIL
example as well as the second example are of this category, so you end up with 1UNTIL
in the second case.
Note that in COBOL 2002+2014 the continuation of COBOL words, , is archaic and was dropped in COBOL 2023 completely. Also there's commonly no real need for that either (bad COBOL code generators may use it).
Also note that the continuation of literals and the hyphen continuation indicator are marked as obsolete features in COBOL 2023.
COBOL 2002 features (also available in gnucobol) should be used instead:
"your text"-
(then go on next line with " more text"
[or use the alternative with 'your text'-
"your text" & " " & "goes on where you like"