You are on page 1of 12

COBOL Syntax Guide

Accept Statement

Format 1

mnemonic-name-1
ACCEPT identifier-1 [FROM { }]
environment-name

Format 2

DATE
DAY
ACCEPT identifier-1 FROM { }
DAY-OF-WEEK
TIME

The ADD Statement

Format 1

identifier-1
ADD { } ... TO {identifier-2 [ROUNDED]} ...
literal-1
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]

Format 2

identifier-1 identifier-2
ADD { } ... TO { } GIVING {identifier-3 [ROUNDED]}...
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]

Format 3

CORRESPONDING
ADD { } identifier-1 TO identifier-2 [ROUNDED]
CORR
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]
The CALL Statement

Format 1

identifier-1
CALL { }
literal-1
identifier-2
BY REFERENCE { ADDRESS OF identifier-3 } ...
file-name-1
{ } ...
[LENGTH OF] identifier-2
[ USING { }]
BY CONTENT { ADDRESS OF identifier-3 } ...
literal-2
identifier-2
{ } ...
literal-2
[ON OVERFLOW imperative-statement-1]
[END-CALL]

Format 2

Identifier-1
CALL { }
literal-1
identifier-2
BY REFERENCE { ADDRESS OF identifier-3 } ...
file-name-1
{ } ...
[LENGTH OF] identifier-2
[ USING { }]
BY CONTENT { ADDRESS OF identifier-3 } ...
literal-2
identifier-2
{ } ...
literal-2
[ON EXCEPTION imperative-statement-1]
[NOT ON EXCEPTION imperative-statement-2]
[END-CALL]

The CLOSE Statement

Format

REEL WITH NO REWIND


{}[ ]
UNIT FOR REMOVAL
CLOSE { file-name-1 [ ]} ...
NO REWIND
WITH { }
LOCK
The COMPUTE Statement

Format

=
COMPUTE {identifier-2 [ROUNDED]} ... { } arithmetic-expression
EQUAL
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-COMPUTE]

The DELETE Statement

Format

DELETE file-name-1 RECORD


[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-DELETE]

The DIVIDE Statement

Format 1

identifier-1
DIVIDE { } ... INTO {identifier-2 [ROUNDED]} ...
literal-1
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]

Format 2

identifier-1 identifier-2
DIVIDE { } INTO { } GIVING {identifier-3 [ROUNDED]}...
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]

Format 3

identifier-1 identifier-2
DIVIDE { } BY { } GIVING {identifier-3 [ROUNDED]}...
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]

Format 4

identifier-1 identifier-2 GIVING identifier-3 [ROUNDED] REMAINDER


DIVIDE { } INTO { }
literal-1 literal-2 identifier-4
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]

Format 5

identifier-1 identifier-2
DIVIDE { } BY { } GIVING identifier-3 [ROUNDED] REMAINDER identifier-4
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]

The EVALUATE Statement

Format
identifier-1 identifier-2
literal-1 literal-2
arith-expr-1 arith-expr-2
EVALUATE { }[ ALSO { }] ...
condition-1 condition-2
TRUE TRUE
FALSE FALSE
ANY
condition-3
TRUE
{{WHEN { FALSE }
identifier-3 identifier-4
THROUGH
[NOT] {{ literal-3 }[ { } { literal-4 }]}
THRU
arith-expr-3 arith-expr-4
ANY
condition-4
TRUE
[ALSO { FALSE } ] ...}...
identifier-5 identifier-6
THROUGH
[NOT] {{ literal-5 }[ { } { literal-6 }]}
THRU
arith-expr-5 arith-expr-6
imperative-statement-1}...
[WHEN OTHER imperative-statement-2]
[END-EVALUATE]

The IF Statement
Format
IFcondition-1 THEN
statement-1
{ }
NEXT SENTENCE
[ELSE
statement-1
{ }]
NEXT SENTENCE
[END-IF
The INITIALIZE Statement

Format

INITIALIZE {identifier-1}...
ALPHABETIC
ALPHANUMERIC
identifier-2
[REPLACING { { NUMERIC } DATA BY { } }...]
literal-1
ALPHANUMERIC-EDITED
NUMERIC-EDITED

The INSPECT Statement

Format 1

INSPECT identifier-1 TALLYING identifier-2 FOR


BEFORE identifier-3
CHARACTERS [{ } INITIAL { }] ...
AFTER literal-1
{ } ...
ALL identifier-4 BEFORE identifier-5
{ }{{ }[{ } INITIAL { }] ... } ...
LEADING literal-2 AFTER literal-3

Format 2

INSPECT identifier-6 REPLACING


identifier- identifier-
CHARACTE BEFORE INITIA
{7 }[{ } { 8 }] ...
RS BY AFTER L
literal-4 literal-5
{ } ...
ALL identifier identifier BEFOR identifier
B INITIA
{ LEADING } { -9 } { -10 } [{ E } { -11 }] ... } ...
Y L
FIRST literal-6 literal-7 AFTER literal-8

Format 3

INSPECT identifier-12 TALLYING identifier-13 FOR


identifier-
BEFORE
CHARACTERS [{ } INITIAL { 14 }] ...
AFTER
literal-9 ...
{ }
identifier- identifier- REPLACING
ALL BEFORE
{ }{{ 15 }[{ } INITIAL { 16 }] ... }
LEADING AFTER ...
literal-10 literal-11

identifier- identifier-
CHARACTE BEFORE INITIA
{ 17 }[{ } { 18 }] ...
RS BY AFTER L
literal-12 literal-13
{ identifier identifier identifier } ...
ALL BEFOR
-19 B -20 INITIA -21
{ LEADING } { } { } [{ E } { }] ... } ...
literal- Y literal- L literal-
FIRST AFTER
14 15 16
Format 4

INSPECT identifier-22 CONVERTING


identifier-3 identifier-23 BEFORE identifier-24
{ } TO { } [{ } INITIAL { }] ...
literal-1 literal-17 AFTER literal-18

The MERGE Statement

Format

ASCENDING
MERGE file-name-1{ON { } KEY {data-name-1}...}...
DESCENDING

[COLLATING SEQUENCE IS alphabet-name-1] USING file-name-2 {file-name-3}...


THROUGH
[OUTPUT PROCEDURE IS procedure-name-1 [ { } procedure-name-2]
{ THRU }
[GIVING {file-name-4} ...

The MOVE Statement

Format 1

identifier-1
MOVE { } TO {identifier-2} ...
literal-1

Format 2

CORRESPONDING
MOVE { } identifier-1 TO {identifier-2} ...
CORR

The MULTIPLY Statement

Format 1

identifier-1
MULTIPLY { } ... BY {identifier-2 [ROUNDED]} ...
literal-1
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-MULTIPLY]

Format 2

identifier-1 identifier-2
MULTIPLY { } ... BY { } GIVING {identifier-3 [ROUNDED]}...
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-MULTIPLY]
The OPEN Statement

Format

INPUT {file-name-1} ...


OUTPUT {file-name-2} ...
OPEN { } ...
I-O {file-name-3} ...
EXTEND {file-name-4} ...

The PERFORM Statement

Format 1

THROUGH
PERFORM [procedure-name-1 [{ } procedure-name-2 ] ]
THRU
[imperative-statement-1 END-PERFORM]

Format 2

THROUGH
PERFORM [procedure-name-1 [{ } procedure-name-2 ] ]
THRU
identifier-1
{ } TIMES [imperative-statement-1 END-PERFORM]
integer-1

Format 3

THROUGH
PERFORM [procedure-name-1 [{ } procedure-name-2 ] ]
THRU
BEFORE
[ WITH TEST { }] UNTIL condition-1
AFTER
[imperative-statement-1 END-PERFORM]

Format 4
THROUGH
PERFORM [procedure-name-1 [{ } procedure-name-2 ] ]
THRU
BEFORE
[ WITH TEST { }]
AFTER
identifier-3
identifier-2 identifier-4
VARYING { } FROM { index-name-2 } BY { }
index-name-1 literal-2
literal-1
UNTIL condition-2
identifier-5
identifier-4 identifier-5
[AFTER { } FROM { index-name-4 } BY { }
index-name-3 literal-2
literal-3
UNTIL condition-3] ...
[imperative-statement-1 END-PERFORM]
The READ Statement

Format 1

NEXT WITH [NO] LOCK


READ file-name-1 [ ] RECORD [{| |}]
PREVIOUS INTO identifier-1
[AT END imperative-statement-1]
[NOT AT END imperative-statement-2]
[END-READ]

Format 2

WITH [NO] LOCK


READ file-name-1 RECORD [{| |}] [KEY IS {data-name-1}]
INTO identifier-1
[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-READ]

The RELEASE Statement

Format

identifier-1
RELEASE record-name-1 [ FROM { }]
literal-1

The RETURN Statement

Format

RETURN file-name-1 RECORD [INTO identifier-1]

[AT END imperative-statement-1]


[NOT AT END imperative-statement-2]
[END-RETURN]

The REWRITE Statement


Format 1
identifier-1
REWRITE record-name-1 [ FROM { }]
literal-1

Format 2

identifier-1
REWRITE record-name-1 [ FROM { }]
literal-1
[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-REWRITE]
The SEARCH Statement

Format 1

identifier-2
SEARCH identifier-1 [ VARYING { }]
index-name-1
[AT END imperative-statement-1]
imperative-statement-2
{ WHEN condition-1 { }} ...
NEXT SENTENCE
[END-SEARCH]

Format 2

SEARCH ALL identifier-3


[AT END imperative-statement-3]
identifier-4
IS EQUAL TO
identifier-3 { } { literal-1 }
WHEN { IS =
arithmetic-expression-1 }
condition-name-1
identifier-6
IS EQUAL TO
identifier-5 { } { literal-2 }
[ AND { IS =
arithmetic-expression-2 }]
condition-name-2
imperative-statement-4
{ }}
NEXT SENTENCE
[END-SEARCH]

The SET Statement

Format 1

index-name-2
index-name-1
SET { } ... TO { identifier-2 }
identifier-1
integer-1

Format 2

UP identifier-3
SET {index-name-3} ... { } BY { }
DOWN integer-2

Format 3

ON
SET { {mnemonic-name-1} ... TO { }} ...
OFF

Format 4
SET {condition-name-1} ... TO TRUE...

The SORT Statement

Format

ASCENDING
SORT file-name-1 {ON { } KEY {data-name-1}...}...
DESCENDING

[WITH DUPLICATES IN ORDER] [COLLATING SEQUENCE IS alphabet-name-1]


THROUGH
[INPUT PROCEDURE IS procedure-name-1 [ { } procedure-name-2]
{ THRU }
[USING {file-name-2} ...
THROUGH
[OUTPUT PROCEDURE IS procedure-name-3 [ { } procedure-name-4]
{ THRU }
[GIVING {file-name-3} ...

The START Statement

Format

NOT LESS [THAN]


NOT <
EQUALS
START file-name KEY { } key-name
=
GREATER [THAN]
>
[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-START]

The STRING Statement

Format

identifier-1 identifier-2
STRING {{ } ... DELIMITED BY { }} ...
literal-1 literal-2
INTO identifier-3
[WITH POINTER identifier-4]
[ON OVERFLOW imperative-statement-1]
[NOT ON OVERFLOW imperative-statement-2]
[END-STRING]
The SUBTRACT Statement

Format 1

identifier-1
SUBTRACT { } ... FROM {identifier-2 [ROUNDED]} ...
literal-1
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-SUBTRACT]

Format 2

identifier-1 identifier-2
SUBTRACT { } ... FROM { } GIVING identifier-3 [ROUNDED]
literal-1 literal-2
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-SUBTRACT]

Format 3

CORRESPONDING
SUBTRACT { } identifier-1 FROM identifier-2 [ROUNDED]
CORR
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-SUBTRACT]

The UNSTRING Statement

Format

identifier-2 identifier-3
UNSTRING identifier-1 [ DELIMITED BY [ALL] { } [ OR [ALL] { }] ... ]
literal-1 literal-2
INTO {identifier-4 [DELIMITER IN identifier-5] [COUNT IN identifier-6]}...
[WITH POINTER identifier-7]
[TALLYING IN identifier-8]
[ON OVERFLOW imperative-statement-1]
[NOT ON OVERFLOW imperative-statement-2]
[END-UNSTRING]
The WRITE Statement

Format 1

identifier-1
WRITE record-name-1 [ FROM { }]
literal-1
identifier-2 LINE
{ }[ ]
BEFORE integer-1 LINES
[{ } ADVANCING { }]
AFTER mnemonic-name-1
{ }
PAGE
END-OF-PAGE
[AT { } imperative-statement-1]
EOP
END-OF-PAGE
[NOT AT { } imperative-statement-1]
EOP
[END-WRITE]

Format 2

identifier-1
WRITE record-name-1 [ FROM { }]
literal-1
[INVALID KEY imperative-statement-1]
[NOT INVALID KEY imperative-statement-2]
[END-WRITE]

You might also like