Escolar Documentos
Profissional Documentos
Cultura Documentos
'
5
(1) MOVE
(2) MOVE . . . CORRESPONDING ( CORR )
(3) MOVE . . . OF . . . TO . . . OF
DATA movement verbs
6
Before
WS00-OUT1 BEST
WS00-OUT2 1234
Before
WS00-OUT1
WS00-OUT2 0
Before
WS00-OUT3 0786
After
WS00-OUT3 2345
Before
WS00-OUT4 PAYAL PAREKH
After
WS00-OUT4 SHUTI DEY
7
MOVE to a numeric item
When the destination item is numeric, or edited numeric, then
data is aligned along the decimal point with zero filling or
truncation as necessary.
When the decimal point is not explicitly specified in either the
source or destination items, the item is treated as if it had an
assumed decimal point immediately after its rightmost
character.
8
Before
WS00-OUT1 0000
WS00-OUT2 000000
Before
WS00-OUT1 3456
WS00-OUT2 345678
Before
WS00-OUT3 000000
After
WS00-OUT3 123456
Before
WS00-OUT4 00000000
After
WS00-OUT4 12345678
9
MOVE .. example
****************************
WS00-OUT1 : HARAYANA
WS00-OUT2 : HARAYANA
****************************
Output SPOOL
10
Is used to change the default type movement of alphabetic and
alphanumeric data.
Example
01 NAME PIC X(10) JUSTIFIED RIGHT.
MOVE KAJOL TO NAME.
Contents of NAME field is
bbbbbKAJOL
JUSTIFIED RIGHT clause
11
JUSTIFIED RIGHT clause ..
example
*********************************************
WS00-OUT1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ
WS00-OUT2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ
*********************************************
Output SPOOL
12
Facilitates movement of value of sub-item of a group item to a similar
named sub-item of another group item
Syntax
MOVE { CORRESPONDING, CORR } identifier-1
TO identifier-2
where identifier-1 and identifier-2 are group items.
MOVE CORRESPONDING
13
MOVE CORRESPONDING ..
example
****************************
WS00-GR2 : NISHANT 00000
****************************
Output SPOOL
14
Facilitates the movement of a particular field of a record to a particular field of
another record. (in other words it facilitates movement of value of a
individual/group item of one group item to an individual/group item of another
group item).
Example:
MOVE NAME OF STUD-REC TO
WS-NAME OF WS-STUD-REC.
MOVE . . . OF . . . TO . . . OF
15
Certain combinations of sending and receiving data types are not
permitted.
Alphabeti
c
Alphanu
meric
Edited
Alphan
umeric
Numeric Numeric
non
integer
Edited
numeric
Alphabetic Y Y Y N N N
Alphanumer
ic
Y Y Y Y Y Y
Edited
Alphanumer
ic
Y Y Y N N N
Numeric N Y Y Y Y Y
Numeric non
integer
N N N Y Y Y
Edited
numeric
N Y Y Y Y Y
Receiving field
S
e
n
d
i
n
g
f
i
e
l
d
LEGAL MOVES
16
GO TO
IF . . . THEN . . .
PERFORM
EVALUATE
STOP RUN
SEQUENCE CONTROL verbs
17
Syntax-1
GO TO paragraph-name.
Example
GO TO 400-READ-PARA.
GO TO Verb
18
Syntax-2
GO TO paragraph-name-1 [paragraph-name-2 ]
. . . DEPENDING ON identifier.
Example
GO TO 500-INSERT-PARA, 600-UPDATE-PARA,
700-DELETE-PARA DEPENDING ON TRANS-
CODE.
GO TO . . . DEPENDING ON . . .
19
Syntax-1
IF condition [ THEN ] {statement-1, NEXT
SENTENCE}
[ELSE {statement-2, NEXT SENTENCE}]
END-IF
Examples
(1)IF MARKS >= 80 THEN MOVE A TO GRADE
ELSE MOVE B TO GRADE
END-IF.
(2) IF NOT OK-BALANCE THEN MOVE 2 TO BALANCE-
CODE
ELSE NEXT-SENTENCE
END-IF
IF statement
20
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
IF ( Var1 < 10 ) THEN DISPLAY Zero
ELSE
IF Var2 = 14 THEN DISPLAY First
ELSE DISPLAY Second
END-IF
END-IF
IF statement
21
Example
IF TIME < 2 AND TIME > 1
THEN MOVE SLOW TO SPEED
END-IF.
Is equivalent to
IF TIME < 2 AND > 1 THEN MOVE SLOW TO
SPEED.
Relational condition
Sign condition
Class condition
Compound condition
Condition-name
Classification of Conditions
23
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Identifier
Literal
Arithmetic Expression
Identifier
Literal
Arithmetic Expression
'
'
'
IS
NOT GREATERTHAN
NOT >
NOT LESSTHAN
NOT <
NOT EQUALTO
NOT =
GREATERTHAN OR EQUALTO
>=
LESSTHAN OR EQUALTO
<=
Relational condition
24
Syntax
Example
IF DISCRIMINANT IS
NEGATIVE THEN
DISPLAY The roots are
imaginary.
'
ZERO
NEGATIVE
POSITIVE
] NOT [ IS Expression Arithmetic
Sign condition
25
Syntax
Example
IF REGNO IS NOT NUMERIC
THEN DISPLAY Records will not be
sorted.
IdentifierIS [NOT]
NUMERIC
ALPHABETIC
ALPHABETIC- LOWER
ALPHABETIC- UPPER
UserDefine dClassName
'
Class condition
26
Syntax
Condition-1 { AND, OR } Condition-2
Examples
(1) IF PERCENT > 80 AND TOTAL > 480
THEN MOVE A TO GRADE.
(2) IF ROW-NUMBER > 24 OR COLUMN > 80
THEN DISPLAY Page Error ! .
Compound Condition
27
Syntax
88 condition-name {VALUE IS, VALUES ARE } literal-1 [
{ THRU, THROUGH } literal-2 ].
Condition Names
28
01 MARITAL STATUS PIC 9.
88 SINGLE VALUE IS ZERO.
88 MARRIED VALUE IS 1.
88 WIDOWED VALUE IS 2.
88 DIVORCED VALUE IS 3.
88 ONCE-MARRIED VALUES ARE 1, 2, 3.
88 VALID-STATUS VALUES ARE 0 THRU 3.
PROCEDURE DIVISION Statements.
IF SINGLE SUBTRACT 125 FROM DEDUCTIONS.
IF ONCE-MARRIED ADD 300 TO SPECIAL-PAY.
IF MARRIED PERFORM B000-MARRIAGE-GIFT.
Condition Variable
Condition
Names
Condition-Names .. example
29
'
'
'
Simple PERFORM
In-line PERFORM
Nested PERFORM
PERFORM . . . THRU
PERFORM . . . UNTIL
PERFORM . . . TIMES
PERFORM . . . VARYING
PERFORM Verb - variations
33
Syntax
PERFORM Paragraph-Name.
Example
PERFORM 500-PROCESS-PARA.
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
Lets see an example ..
PERFORM Verb - In-line
PERFORM
36
INLINE PERFORM PROGRAM
37
JCL FOR THE INLINE
PERFORM PROGRAM
38
When SYSIN data satisfies
the condition WS-STRING =
KARINA the scope of the
INLINE PERFORM gets
terminated
39
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
40
PERFORM Verb Nested
PERFORM
****************************************
WE ARE INSIDE B000-LAST-PARA
WE ARE INSIDE B001-FIRST-PARA
WE ARE INSIDE B002-MIDDLE-PARA
****************************************
Output SPOOL
41
Syntax
PERFORM Paragraph-Name-1 [ { THRU, THROUGH }
Paragraph-Name-2 ].
Example
PERFORM 300-READ-PARA THRU 600-UPDATE-
PARA.
PERFORM Verb PERFORM
THRU
42
PERFORM THRU -
example
****************************
WE ARE INSIDE B000-DISP-PARA
WE ARE INSIDE B001-DISP-PARA
WE ARE INSIDE B002-DISP-PARA
****************************
Output SPOOL
43
Syntax
PERFORM Paragraph-Name-1 [ { THRU,
THROUGH }
Paragraph-Name-2 ] UNTIL
condition.
Example
PERFORM 300-READ-PARA UNTIL EOF = N.
PERFORM Verb PERFORM ..
UNTIL ..
44
Syntax
PERFORM Paragraph-Name-1 [ { THRU,
THROUGH }
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
45
Syntax
PERFORM Paragraph-Name-1 [ { THRU, THROUGH }
Paragraph-Name-2 ] { integer, identifier }
TIMES.
Example
PERFORM 500-PROCESS-PARA THRU 800-END-PARA 8 TIMES.
PERFORM Verb PERFORM .. TIMES
49
PERFORM Verb PERFORM ..
TIMES Example
****************************
HELLO GUEST. WELCOME TO E&R TRAINING
HELLO GUEST. WELCOME TO E&R TRAINING
HELLO GUEST. WELCOME TO E&R TRAINING
HELLO GUEST. WELCOME TO E&R TRAINING
HELLO GUEST. WELCOME TO E&R TRAINING
****************************
Output SPOOL
50
Syntax
PERFORM Paragraph-Name-1 [ { THRU, THROUGH }
Paragraph-Name-2 ] VARYING identifier-1 FROM
{identifier-2, integer-1} BY { identifier-3, integer-
2 }
UNTIL condition.
Example
PERFORM 500-WRITE-PARA
VARYING I FROM 1 BY 1
UNTIL I > 5.
PERFORM Verb - PERFORM . . . VARYING
51
PERFORM Verb -
PERFORM . . . VARYING
****************************
HELLO GUEST. WISH YOU ALL THE BEST
HELLO GUEST. WISH YOU ALL THE BEST
HELLO GUEST. WISH YOU ALL THE BEST
HELLO GUEST. WISH YOU ALL THE BEST
****************************
Output SPOOL
52
Is used to transfer the control back to the statement following the
PERFORM statement from within a paragraph invoked by the
PERFORM statement.
Syntax
EXIT.
Note:
It is recommended to avoid using EXIT similar to GO TO since it is against
the idea of structured programming.
EXIT statement
53
Syntax
EVALUATE subject-1 [ ALSO subject-2 ] . . .
{ { WHEN object-1 [ ALSO object-2 ] . . . } . . . }
imperative-statement-1 } . . .
Where subject = { identifier, expression, TRUE, FALSE }
and object = { condition, TRUE, FALSE }.
EVALUATE Verb
54
[ ]
EVALUATE
Identifier
Literal
CondExpres sion
ArithExpre ssion
TRUE
FALSE
WHEN
ANY
Condition
TRUE
FALSE
NOT
Identifier
Literal
ArithExpre ssion
THRU
THROUGH
Identifier
Literal
ArithExpre ssion
Statement Block
'
'
'
'
1
]
1
1
1
'
'
'
[ ]
WHENOTHERStatement Block
END- EVALUATE
The Evaluate
55
EVALUATE Verb .. example
There are two valid ranges
which the logic checks for
1) Marks > 79
2) Marks > 64 & <= 79
*************************************
YOU HAVE CLEARED EXAM WITH A GRADE
*************************************
Output SPOOL
56
Closes all the files that were opened for file operations.
Syntax
USAGE IS {DISPLAY, COMPUTATIONAL, COMP} [ - {1, 2,
3}].
USAGE Clause
58
USAGE is DISPLAY
USAGE IS COMPUTATIONAL
USAGE IS COMP-1
USAGE IS COMP-2
USAGE IS COMP-3
Usage clause when declared for a group item, ensures that all the
sub-items of the group item default to the same USAGE clause as the
group items.
USAGE Clause
60
USAGE Clause .. example
B0001-POPULATE-FIELDS.
MOVE 99999 TO WS00-COMP-FORM
MOVE 99999 TO WS00-COMP1-FORM
MOVE 99999 TO WS00-COMP2-FORM
MOVE 99999 TO WS00-COMP3-FORM
B0002-DISPLAY-FIELDS.
DISPLAY '******************************************'
DISPLAY '* COMP DISPLAY IS : ' WS00-COMP-FORM
DISPLAY '* COMP1 DISPLAY IS : ' WS00-COMP1-FORM
DISPLAY '* COMP2 DISPLAY IS : ' WS00-COMP2-FORM
DISPLAY '* COMP3 DISPLAY IS : ' WS00-COMP3-FORM
DISPLAY '******************************************'
******************************************
* COMP DISPLAY IS : 99999
* COMP1 DISPLAY IS : .99999000E 05
* COMP2 DISPLAY IS : .99999000000000000E 05
* COMP3 DISPLAY IS : 99999
******************************************
Output SPOOL
61
Types of conditions.
Simplest
Most complex
Syntax
OPEN {INPUT, OUTPUT, I-O, EXTEND} Filename-1 . . .
OPEN MODE
STATEMENT INPUT OUTPUT I-O EXTEND
READ
WRITE
REWRITE
OPEN verb
The READ statement makes it possible to get the file
record from the file onto the file buffer into the
program.
So to process all the records of a given file we would be
required to read all the records one by one and carry
out the required processing.
Again the file record buffer is our only connection with
the file and it is only able to store a single record at a
time.
The READ verb
READ verb syntax
Internal filename is given in the select
statement in FILE-CONTROL section. By
this time the file should be already opened
This mentions the identifier
name into which the file data
would be fetched into after the
read operation
So at any given point of time after the read statement has been executed,
there would be two copies of the data read. One would be the FD entry (i.e.
Internal Filename) and the other would be the identifier used in [INTO
Identifier] statement. The AT END traps the condition when the end of file
has been reached.
READ InternalFileName [NEXT] RECORD
[INTO identifier]
[NOT] AT END Statement block
END-READ
83
INSIDE THE COBOL PROGRAM
READ STATEMENT
1000MARY ANNA JOHN
2000TIM MAYOR KRUEGER
3000HANS OSLON
4000KUMAR GAURAV
5000SEVARATHNAM ALVA
6000KIM JAE JING
1000 ANNA JOHN N
ACCNO NAME EOF
2000 MAYOR KRUEGER N
3000 HANS OSLON N
4000 KUMAR GAURAV N
5000 SEVARATHNAM ALVA N
6000 KIM JAE JING N
Y
'
1
]
1
'
1
]
1
1
1
1
1
1
WRITE Syntax
85
001800 MAIN-PARA.
001900 OPEN OUTPUT SEQFL
002000 MOVE '1000' TO ACCNO
002100 MOVE 'RAJ KAPOOR' TO NAME
002200 WRITE CUSTOMER
002300 MOVE '2000' TO ACCNO
002400 MOVE 'DEV ANAND' TO NAME
002410 WRITE CUSTOMER
002600 MOVE '3000' TO ACCNO
002700 MOVE 'DILIP KUMAR' TO NAME
002710 WRITE CUSTOMER
002810 CLOSE SEQFL
002900 STOP RUN.
The WRITE statement is
used to write the output file
buffer data into the output
file
86
REWRITE is used to update an existing record in the file which has been read in the
program
Syntax
REWRITE record-name [FROM data-name]
{AFTER, BEFORE} ADVANCING integer {LINE, LINES, PAGE}
[END-REWRITE]
Note:
The REWRITE statement can only be used if the file is opened in the I-O
mode and its execution must be preceded by the successful READ
statement on the file.
The REWRITE statement replaces last read record
REWRITE verb
87
Syntax
CLOSE filename1
REDEFINES
JUSTIFIED
SELECT
Types of conditions.
USAGE clauses.