Professional Documents
Culture Documents
Cobol (Common Business Oriented Language)
Cobol (Common Business Oriented Language)
Cobol (Common Business Oriented Language)
ORIENTED LANGUAGE)
Overview
COBOL Fundamentals
DAY3
SEQUENCE CONTROL verbs
GO TO
IF . . . THEN . . .
PERFORM
EVALUATE
STOP RUN
GO TO Verb
Syntax-1
GO TO paragraph-name.
Example
GO TO 400-READ-PARA.
GO TO . .
Syntax-2
GO TO paragraph-name-1 [paragraph-name-2 ]
Example
GO TO 500-INSERT-PARA, 600-UPDATE-PARA,
700-DELETE-PARA DEPENDING ON TRANS-CODE.
IF statement
Syntax-1
Examples
Syntax-2 ( Nested IF )
IF condition-1 [ THEN ] statement-1
ELSE
IF condition-2 [ THEN ] statement-2
ELSE statement-3
END-IF
END-IF.
Example
Syntax
POSITIVE
Arithmetic Expression IS [ NOT] NEGATIVE
ZERO
Example
Syntax NUMERIC
ALPHABETIC
Identifier IS [NOT] ALPHABETIC - LOWER
ALPHABETIC - UPPER
UserDefinedClassName
Example
Syntax
Examples
Literal
VALUE
88 ConditionName THROUGH
VALUES LowValue THRU HighValue
Condition Names are defined using the special level number 88 in the DATA
DIVISION of a COBOL program.
They are defined immediately after the definition of the data item with which
they are associated with.
A condition name takes the value TRUE or FALSE depending on the value of
the data item with which it is associated. The VALUE clause of the associated
data item is used to identify the values which make the Condition Name
TRUE.
Condition Names
Syntax
01 MARITAL-STATUS PIC 9.
After
WS00-MARKS 050
WS00-DISP NOT CLEARED COMPRE
Before After
Paragraph names are either user defined or language enforced. They are
followed by a full stop.
B0000-PERF-PARA.
PROGRAM-ID.
PERFORM Verb - variations
Simple PERFORM
In-line PERFORM
Nested PERFORM
PERFORM . . . THRU
PERFORM . . . UNTIL
PERFORM . . . TIMES
PERFORM . . . VARYING
PERFORM Verb - Simple PERFORM
Syntax
PERFORM Paragraph-Name.
Example
PERFORM 500-PROCESS-PARA.
This is not iterative but instructs the computer to execute the chunk of code
inside the mentioned paragraph before reverting back to the sentence
following the PERFORM coded.
PERFORM Verb – Simple PERFORM example
****************************************
WE ARE INSIDE B000-LAST-PARA
Output SPOOL WE ARE INSIDE B001-FIRST-PARA
WE ARE INSIDE B002-MIDDLE-PARA
PERFORM Verb - In-line PERFORM
Syntax
PERFORM imperative-statements.
Example
PERFORM
MOVE NUM-1 TO MAX
IF NUM-2 > MAX THEN MOVE NUM-2 TO MAX
DISPLAY “Maximum is ” MAX.
END-PERFORM
INLINE PERFORM PROGRAM
JCL FOR THE INLINE
PERFORM PROGRAM
When SYSIN data satisfies
the condition WS-STRING =
‘KARINA’ the scope of the
INLINE PERFORM gets
terminated
PERFORM Verb – Nested PERFORM
Syntax
Paragraph-Name-1.
PERFORM Paragraph-Name-2.
. . . . .
. . . . .
Paragraph-Name-2.
PERFORM Paragraph-Name-3.
. . . . .
. . . . .
Paragraph-Name-3.
MOVE A TO B.
. . . . .
. . . . .
PERFORM Verb – Nested PERFORM
****************************************
WE ARE INSIDE B000-LAST-PARA
Output SPOOL WE ARE INSIDE B001-FIRST-PARA
WE ARE INSIDE B002-MIDDLE-PARA
PERFORM Verb – PERFORM … THRU …
Syntax
Paragraph-Name-2 ].
Example
****************************
WE ARE INSIDE B000-DISP-PARA
Output SPOOL WE ARE INSIDE B001-DISP-PARA
WE ARE INSIDE B002-DISP-PARA
****************************
PERFORM Verb – PERFORM .. UNTIL ..
Syntax
Example
Paragraph-Name-2 ]
[WITH TEST {BEFORE, AFTER}]
UNTIL condition.
Example
PERFORM 300-PROCESS-PARA WITH TEST AFTER
UNTIL VALUE NOT = 0.
PERFORM Verb …
PERFORM . . UNTIL .. WITH TEST AFTER OPTION
****************************
Output SPOOL
****************************
PERFORM Verb –
PERFORM . . UNTIL .. WITH TEST AFTER
10 Times!! Why?
****************************
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
Output SPOOL WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
WE ARE INSIDE B000-PERF-PARA
****************************
PERFORM Verb – PERFORM .. TIMES
Syntax
Example
****************************
HELLO GUEST. WELCOME TO E&R TRAINING
HELLO GUEST. WELCOME TO E&R TRAINING
Syntax
Example
PERFORM 500-WRITE-PARA
VARYING I FROM 1 BY 1
UNTIL I > 5.
PERFORM Verb - PERFORM . . . VARYING
****************************
HELLO GUEST. WISH YOU ALL THE BEST
HELLO GUEST. WISH YOU ALL THE BEST
Output SPOOL HELLO GUEST. WISH YOU ALL THE BEST
HELLO GUEST. WISH YOU ALL THE BEST
****************************
PERFORM ...VARYING Syntax
THRU BEFORE
PERFORM 1stProc EndProc WITH TEST
THROUGH AFTER
Identifier 2
Identifer1
VARYING FROM IndexName2
IndexName1 Literal
Identifier3
BY UNTIL Condition1
Literal
Identifier5
Identifier4
AFTER FROM IndexName 4
IndexName3 Literal
Identifier6
BY UNTIL Condition2
Literal
StatementBlock END - PERFORM