COBOL COMMAND SYNTAX

DEFINITIONS OF SYMBOLS AND PLACEHOLDERS:

... (ellipsis) - indication that the preceding item may be repeated a number of times, separated by a delimeter (ex. comma, space)
[ ] (brackets) - indication of an optional clause in the syntax
| (vertical bar) - two or more words separated by a vertical bar indicates that one of the values may be used
alphanumeric variable - an alphanumerica variable defined in WORKING-STORAGE
arithmetic expression - an expression representing one or more arithmetic operations (+ - / *) involving numeric values
compare list -
condition - an expression representing one or more comparisons between values optionally joined by AND or OR
constant, alphanumeric - a set of characters enclosed in quotation marks: "ABC"
constant, numeric - an expression representing a number:  1296.54
do something - any COBOL command(s)
do something else - any COBOL command(s) different from the one given above
file-field-name - a COBOL variable that is a field in a record of a file described in an FD or SD
file-name - the name of a file described in an FD
file-record - a COBOL variable that is the record of a file described in an FD
index - a variable defined in WORKING-STORAGE used as an index for a table or array
mode - one of the four open modes for a file:  OUTUT, EXTEND, I-O, INPUT
numeric value - a numeric constant or a numeric variable
numeric variable - a numeric variable defined in WORKING-STORAGE
paragraph - a paragraph name in the COBOL program
sort-file - the name of a file described in an SD
value - a constant or a variable
variable - a variable defined in WORKING-STORAGE
 

ACCEPT
ACCEPT variable...
ADD
ADD numeric value ... TO
        numeric variable [ROUNDED] ...
        [ ON SIZE ERROR
            do something]

ADD numeric value ... GIVING
        numeric variable [ROUNDED] ...
        [ ON SIZE ERROR
            do something]

ADD numeric value ... TO
        numeric variable
        GIVING numeric variable [ROUNDED] ...
        [ ON SIZE ERROR
            do something]

CALL
CALL "program-name"
CLOSE
CLOSE filename
COMPUTE
COMPUTE numeric variable
        [ROUNDED] =
        arithmetic expression
        [ ON SIZE ERROR
            do something else]
COPY
COPY "filename.ext"
DELETE
DELETE file-name RECORD
        [ INVALID KEY
            do something
DISPLAY
DISPLAY value [WITH NO ADVANCING]
DIVIDE
DIVIDE numeric value BY numeric value
    GIVING variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

DIVIDE numeric value BY numeric value
    GIVING variable [ROUNDED] ...
    REMAINDER numeric variable
    [ ON SIZE ERROR
        do something ]

DIVIDE numeric value INTO numeric value
    GIVING variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

DIVIDE numeric value INTO numeric value
    GIVING variable [ROUNDED] ...
    REMAINDER numeric variable
    [ ON SIZE ERROR
        do something ]

EXIT
EXIT PROGRAM
GO TO
GO TO paragraph
*** do not use in this class!
IF ELSE
IF condition
    do something...
ELSE
    do something...
INSPECT
INSPECT variable
    CONVERTING compare list
    TO replace list
MOVE
MOVE value TO variable  ...
MULTIPLY
MULTIPLY numeric value
    BY numeric variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

MULTIPLY numeric value
    BY numeric variable
    GIVING variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

OPEN
OPEN mode file-name
PERFORM
PERFORM paragraph

PERFORM paragraph
    value TIMES

PERFORM paragraph
    UNTIL condition

PERFORM paragraph
    VARYING variable
    FROM value
    BY value
    UNTIL condition

READ
READ file-name [NEXT]  RECORD
    AT END
        do something

For a SEQUENTIAL file, READ and READ NEXT RECORD are identical

READ file-name RECORD
    INVALID KEY
        do something

REWRITE
REWRITE file-record
    [ INVALID KEY
        do something ]
SEARCH
SEARCH table name
    [ AT END
        do something ]
    WHEN  condition
        do something
SET
SET index variable TO value

SET index
    UP|DOWN BY value

SORT
SORT sort-file
    ON ASCENDING KEY sort-field
    USING input-file
    GIVING output-file

SORT sort-file
    ON ASCENDING|DESCENDING KEY
        file-field-name

START
START file name
    KEY NOT < key name
        [ INVALID KEY
            do something ]

START file name
    KEY > key name
        [ INVALID KEY
            do something ]

START file name
    KEY EQUALS|NOT <|GREATER THAN
        key name
        [ INVALID KEY
            do something ]

SUBTRACT
SUBTRACT numeric value ...
    FROM numeric variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

SUBTRACT numeric value ... FROM numeric variable
    GIVING numeric variable [ROUNDED] ...
    [ ON SIZE ERROR
        do something ]

UNSTRING
UNSTRING variable
    DELIMITED BY [ALL] value
            [ OR [ALL] value ]
        INTO variable...
WRITE
WRITE file-record
    [FROM variable]
    [ INVALID KEY
        do something ]

WRITE file-record
    AFTER|BEFORE
    ADVANCING
    PAGE|value LINES