Download - Cobol Keywords
-
8/3/2019 Cobol Keywords
1/20
1
COBOL KEYWORDS
-
8/3/2019 Cobol Keywords
2/20
2
INTRODUCTION
Keywords are special, predefined syntactic meanings in
a program
In COBOL, the keywords are reserved, and cannot be
used as identifiers.
-
8/3/2019 Cobol Keywords
3/20
3
ADD statement
ADD & SUBTRACT statement
ADD : ADD A,B GIVING C ROUNDED.
EX: 77 A PIC 99V999 VALUE IS 23.412.
77 B PIC 99V999 VALUE IS 35.273.
77 C PIC 99V9 VALUE IS 42.3.
ADD A,B GIVING C ROUNDED
after execution the value of c will be 58.7 instead of 58.685.
SUBTRACT :
SUBTRACT 10 FROM A , B.
SUBTRACT A ,B FROM C .
SUBTRACT A FROM B GIVING C ROUNDED.
after execution, the value of c will be 11.9 instead of 11.861
-
8/3/2019 Cobol Keywords
4/20
4
MULTIPLY & DIVIDE STATEMENT
MULTIPLY : MULTIPLY A BY B GIVING C.
MULTIPLY 10 BY A , B GIVING X,Y.
x would have product of 10 and A.
Y would have product of 10 and B.
DIVIDE : 77 A PIC 9(2) VALUE IS 15.
77 B PIC 9(2) VALUE IS 5.
77 C PIC 9(2) VALUE IS 34.
DIVIDE A BY 3 GIVING C.
DIVIDE 5 INTO A.
DIVIDE 5 INTO A GIVING B.
DIVIDE 3 INTO A GIVIING B,C.
DIVIDE C BY B GIVING A REMAINDER D.
-
8/3/2019 Cobol Keywords
5/20
5
COMPUTE STATEMENT
All the computations performed by the other four arithmetic statementscan be done by using only the COMPUTE statement.
Syntax : COMPUTE Identifier-1 = Arithmetic expression.
Example :
COMPUTE A = ( ( B + C ) / ( D E ) ) * 100
-
8/3/2019 Cobol Keywords
6/20
6
ON SIZE ERROR OPTION
If after an arithmetic operation, the result exceeds the largest value
that can be accommodated in the result field, the ON SIZE ERROR
occurs.
Useful in detecting overflow, zero division
It is an optional phrase
Syntax :
< Arithmetic statement > ON SIZE ERROR Imperative Statement.
-
8/3/2019 Cobol Keywords
7/20
7
ACCEPT & DISPLAY
ACCEPT
Syntax:
ACCEPT identifier [ FROM {mnemonic-name / system variable}]
mnemonic-name is the device identifier as defined in SPECIAL-NAMES
paragraph in ENVIRONMENT DIVISION
system variable may be DATE,DAY,TIMEDISPLAY
Displays data on the console.
Syntax:
DISPLAY [ Identifier-1/ Literal-1] , {Identifier-2 / Litera
l-2}. . .
[UPON mnemonic-name]
[WITH NO ADVANCING]
-
8/3/2019 Cobol Keywords
8/20
8
DATAMOVEMENT MOVE VERB
Moves data values from literal to identifier, or identifier to identifier
DOES NOT ACTUALLY MOVE BUT COPIES
Numeric data is aligned according to decimal point and receiving field is
padded with zeroes
Alphabetic / alphanumeric data is left justified in receiving field
Syntax:
MOVE Literal-1 [, Identifier-1] TO Identifier-2 [, Identifiers-3]. . .
-
8/3/2019 Cobol Keywords
9/20
9
DATAMOVEMENT MOVE VERB
-
8/3/2019 Cobol Keywords
10/20
10
GROUP MOVE Data items in GROUP MOVE is considered to be alphanumeric
01 DATE
05 DD PIC 99
05 MM PIC 99 MOVE 123 TO DATE
05 YY PIC 99
Contents after MOVE DD-12, MM-30, YY-00
MOVE CORRESPONDING
Data items of one group are moved to data items of another
group-If names of corresponding data items of both groups
are identical-no use of move statements
-
8/3/2019 Cobol Keywords
11/20
11
MOVE CORRESPONDING ID-1 TO ID-2
RULES
Identifiers 1,2 must refer to group items
Data items must have same data names
Corresponding items can have different locations within the group
Field size can be different
MOVE CORRESPONDING
Example
01 PAY-REC 01 PROFILE
02 IDNUM PIC 9(2) 02 IDNUM PIC 9(3)
02 NAME PIC X(30) 02 DEPT PIC X(3)
02 SALARY PIC 9(7)V99 02 SALARY PIC 9(6)V9
02 NAME PIC X(35)
MOVE CORRESPONDING PAY-REC TO PROFILE
-
8/3/2019 Cobol Keywords
12/20
12
Partial fields can be moved in COBOL85
EXAMPLE
77 ABC PIC X(5) VALUE COBOL
77 XYZ PIC X(5)
MOVE ABC(3 : 3) TO XYZ BOLbb
PARTIAL MOVE
-
8/3/2019 Cobol Keywords
13/20
13
CONTINUE & EXIT
The CONTINUE statement allows to specify a no
operation statement.
CONTINUE indicates that no executable instruction ispresent.
The EXIT statement provides a common end point for
a series of programs.
-
8/3/2019 Cobol Keywords
14/20
14
GOTO STATEMENT
Unconditionally transfers control from one part of
program to other part of program
Format:GO TO Paragraph name
Cant track the flow of the program
-
8/3/2019 Cobol Keywords
15/20
15
EVALUATE STATEMENT
Evaluate statement is used when different actions are to
be specified for different values of an identifier.
Syntax :EVALUATE Identifier-1
WHEN Identifier/Literal Imperative Statement(s)
WHEN OTHER Imperative Statement(s)
END-EVALUATE.
Example : EVALUATE MARKS
WHEN 50 THRU 100 MOVE A TO GRADEWHEN 0 THRU 49 MOVE B TO GRADE
WHEN OTHER MOVE WRONG TO GRADE
END EVALUATE.
-
8/3/2019 Cobol Keywords
16/20
16
EXAMINE AND INSPECT STATEMENTS
EXAMINE and INSPECT are used to tally and/or replace the
occurrences of a single character or a group of characters in a
data field.
Syntax :
EXAMINE identifierTALLYING [ALL/LEADING/UNTIL FIRST]
literal-1 REPLACING BY literal-2
INSPECT identifier-1 TALLYING identifier-2 FOR
[ALL/LEADING] identifier -3 [BEFORE/AFTER] INITIAL
identifier-4
In Examine, a counter variable tally is used as default but in
inspect, we need to declare the counter variables.
-
8/3/2019 Cobol Keywords
17/20
17
Example
77 A PICX(5) VALUE IS EERIE
EXAMINE A TALLYING ALL E Tally Register =3
EXAMINE A TALLYING LEADING E Tally Register=2
EXAMINE A REPLACING UNTIL FIRST I BY P A=EERPE
MY-STRING = ANANTA KUMAR MAITY
INSPECT MY-STRING TALLYING TALLY-COUNTFOR
ALL A. IfTALLY-COUNT=08, now TALLY-COUNT=13
MY-STRING = BACDABCZPABCABCPQ
INSPECT MY-STRING TALLYING TALLY-1 FOR ALL
ABC BEFORE INITIAL . AFTER INITIAL Z.
IfTALLY-1=02, now TALLY-1=04
-
8/3/2019 Cobol Keywords
18/20
18
STRING
Concatenates two or more strings into a single data
item
Syntax:
STRING Identifier-1 DELIMITED BY [ ALL ]
Identifier-2 DELIMITED BY [ ALL ]INTO destination-string
[ WITH POINTER pointer integer]
[ ON OVERFLOW statement block]
[ NOT ON OVERFLOW statement block]
[ END-STRING ]
-
8/3/2019 Cobol Keywords
19/20
19
UNSTRING
Used to divide a string into sub strings
Syntax:
UNSTRING Identifier-1 DELIMITED BY [ ALL ]
Identifier-2 DELIMITED BY [ ALL ]
INTO destination-string[ WITH POINTER pointer integer]
[ ON OVERFLOW statement block]
[ NOT ON OVERFLOW statement block]
[ END-UNSTRING ]
-
8/3/2019 Cobol Keywords
20/20
20
THANK YOU