Professional Documents
Culture Documents
BUSINESS 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
Syntax
01 MARITAL-STATUS PIC 9.
After
WS00-MARKS 050
WS00-DISP NOT CLEARED COMPRE
Before After
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.
****************************************
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
Paragraph-Name-2 ] UNTIL
condition.
Example
Paragraph-Name-2 ]
[WITH TEST {BEFORE,
AFTER}]
UNTIL condition.
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
Paragraph-Name-2 ] { integer,
identifier } TIMES.
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
Identifier 5
Identifier4
AFTER FROM IndexName 4
IndexName3 Literal
Identifier6
BY UNTIL Condition2
Literal
[StatementBlock END - PERFORM ]
PERFORM .. VARYING Example
PERFORM .. VARYING Example
OUTPUT SPOOL
EVALUATE Verb
Syntax
imperative-statement-1 } . . .
Identifier
Literal
CondExpression
EVALUATE
ArithExpression
TRUE
FALSE
ANY
Condition
WHEN TRUE StatementBlock
FALSE
Identifier Identifier
THRU
[ NOT] Literal Literal
ArithExpression THROUGH ArithExpression
[ WHEN OTHER StatementBlock]
END - EVALUATE
EVALUATE Verb .. example
1) Marks > 79
2) Marks > 64 & <= 79
*************************************
Overview
Array
Array Declaration
ARRAY – Multi dimensional Array
Output
Spool of the
Job
Array Declaration
INDEXED ARRAY
Defining an Array – Using Indexed
clause
Output
Spool of the
Job
PROJECT EMP# EMPNAME
Declaring Tables –BANKS
An example
11111 SRINI
BANKS 22222 JYOTI
MKTNG 33333 VINAY
MKTNG 44444 SARMA
Declaring Tables – An example
PROJECT EMP# EMPNAM
Declaring Tables – BANKS
An example
11111 E
SRINI
BANKS 22222 JYOTI
MKTNG 33333 VINAY
MKTNG 44444 SARMA
DISPLAY '**************************************************'
DISPLAY 'WS00-ORG : ' WS00-ORG
DISPLAY 'WS00-IBU FIRST OCCUR : ' WS00-IBU(1)
DISPLAY 'WS00-PROJ FIRST OCCUR : ' WS00-PROJ(1,1)
DISPLAY 'WS00-EMP : ' WS00-EMP(1,1)
DISPLAY 'WS00-EMPNAME : ' WS00-EMPNAME(1,1)
DISPLAY '**************************************************'
Accessing the elements of an array
Syntax-1
Syntax-2
Subscript Index
(1) Is a WORKING- Is a special subscript
STORAGESECTION variable created
defined by the user.
and maintained by the
(2) Represents an Represents
operating a displacement
System.
occurrence of array from
element
the address of the first
(3) To modify the value of To modify the value of an
element
a index,
subscript, the MOVE or the SET verb is used.
Arithmetic verbs are used.
SEARCH Statement
Syntax
[ END-SEARCH ].
Searching in a table
JCL
Output Spool
SEARCH ALL
Syntax
literal-1, arithmetic-expression-1 }
imperative-statement-2.
SEARCH ALL
Inspect
String
Unstring
INSPECT statement
Syntax
• LEADING
The LEADING phrase causes
counting/replacement of all Compare$il
characters from the first valid one encountered to
the first invalid one.
• FIRST
The FIRST phrase causes only the first valid
character to be replaced.
• BEFORE
The BEFORE phrase designates as valid those
characters to the left of the delimiter associated
with it.
AFTER
INSPECT – Example (finding
occurrences)
Display
messages to
come in sysout
INSPECT – Example (finding
occurrences)
OUTPUT SPOOL
STRING statement
Example:
01 NAME.
05 F-NAME PIC A(10).
05 M-NAME PIC A(10).
05 L-NAME PIC A(10).
STRING
END-STRING.
Example
STRING
F-NAME DELIMITED BY ‘ ‘
‘ ‘ DELIMITED BY SIZE
M-NAME DELIMITED BY SIZE
‘ ‘ DELIMITED BY SIZE
STRING statement
OVERFLOW Option
POINTER Option
STRING
statement
Display in the
spool
STRING - Example
JCL for executing
program STRNG
Display in the
Output spool
UNSTRING statement
Syntax
UNSTRING identifier-1
INTO identifier-4 . . .
[ END-UNSTRING ].
UNSTRING statement
Display in the
Output spool
Some Common programming problems
• DATA EXCEPTION
Performing arithmetic operation or comparison on a
field containing BLANKS or non-numeric data
• DIVIDE EXCEPTION
Attempting to divide by ZERO
• ADDRESSING ERROR
When we have Invalid value placed in a sub-script or index.
This might lead to addressing beyond the table boundaries.
• OPERATION ERROR
Attempting to access file before opening it.