The
ANSI 1985 COBOL standard is commonly referred to as COBOL85. It's still
COBOL, but with some added functionality to make life easier. COBOL85 introduced scope terminators, data field referencing, and the EVALUATE statement.
Scope terminators allow a programmer to write more legible code, and do certain things that were not possible before COBOL85.
Example 1: The inline PERFORM
0300-MAIN.
PERFORM GET-DATA-RECORD.
PERFORM UNTIL (NO-MORE-DATA)
PERFORM CHECK-RECORD-FOR-ERRORS
PERFORM GET-DATA-RECORD
END-PERFORM.
The END-PERFORM is key here, since it tells the
program where the loop ends. There was no END-PERFORM prior to COBOL85.
Example 2: The Nested IF
0300-MAIN.
PERFORM GET-DATA-RECORD.
IF (DATA-RECORD = SPACES)
ADD 1 TO BLANK-CNT
ELSE
IF (DATA-RECORD = ZEROS)
ADD 1 TO ZERO-CNT
ELSE
ADD 1 TO RECORD-CNT
END-IF
END-IF.
The END-IF makes the code more readable, and allows for a bit more coding flexibility.
I won't bore you with the others (there are at least 10), but you can get the idea of what a scope terminator is used for.
Data field referencing allows portions of a field to be manipulated or checked for values. This is useful if a field has a value you want to extract.
Example
The field TEXT-LINE contains PA: Marysville. If you wanted to extract PA, you would do that by using a MOVE statement as follows:
MOVE TEXT-LINE (1:2) TO TEXT-STATE
The TEXT-LINE (1:2) portion is telling the program to move everything from position 1 and 2 to the field TEXT-STATE.
The last big change is the addition of the EVALUATE statement. Using this
statement eliminates the need for a
complex IF block in some instances.
Example 1: Range
EVALUATE MY-DATE-MM
WHEN 01 THRU 12
CONTINUE
WHEN OTHER
PERFORM DATE-ERROR-ROUTINE
END-EVAULATE.
Example 2: Explicit Values
EVALUATE MY-AGE
WHEN 01 THRU 17
MOVE "NON-ADULT" TO AGE-TEXT
WHEN 18
MOVE "ADULT - UNDER DRINKING AGE" TO AGE-TEXT
WHEN 21 THRU 99
MOVE "ADULT - DRINKING AGE" TO AGE-TEXT
END-EVALUATE.
Example 1 shows an
evaluation of a range of values. Example 2 shows the same as Example 1, except it is also checking for an explicit value: 18.
COBOL isn't dead just yet.