You are on page 1of 23

IBM Mainframes

COBOL Training Class-5


Verbs in COBOL
We have few types of verbs IN COBOL.

SIMPLE VERBS DISPLAY AND ACCEPT.

DATA MOVEMENT VERBS MOVE.

ARITHMETIC VERBS ADD S!BT"ACT M!LTIPY


DIVIDE COMP!TE.

CONDITIONAL VERBS I# AND EVA!LATE .

CONTROL SEQUENCE VERBS PE"#O"M STOP


"!N$OBAC%E&ITE&IT'P"O$"AM$OTO ETC.

FILE VERBS OPEN "EAD W"ITE "EW"ITE CLOSE


DELETE

SPECIAL VERBS COPY CALL ( INITILIAL)E.


SIMPLE VERBS
S*+p,e Verbs ( ACCEPT/DISPLAY- These two verbs are
.se/ to ta0e *1p.t for+ 2CL a1/ /*sp,ay o.tp.t to the re3.*re/
,o4at*o1.
Accept statement *s .se/ to ass*51 a va,.e to /ata *te+
/y1a+*4a,,y .1,*0e Va,.e 4,a.se wh*4h *s a stat*4 way

Sy1ta67

ACCEPT DATAITEM!"

ACCEPT DATAITEM#"
D$sp%a& statement *s .se/ to /*sp,ay the o.tp.t fro+ the /ata
*te+ to the SYSO!T wh*4h *s *1 the 2ob Spoo,.

S&nta'7 DISPLAY DATAITEM!(DATAITEM#(CONSTANTS


Data Movement verbs
Move State+e1t *s .se/ to +ove /ata fro+ o1e /ata'
*te+s84o1sta1t to a1other /ata'*te+.
The /est*1at*o1 sho.,/ be a,ways a /ata'*te+ b.t 1ot 4o1sta1t.

Sy1ta67
MOVE DATAITEM/CONSTANT TO DATAITEM#(DATAITEM)*
Move state+e1t 4a1 be /o1e *1 /*ffere1t types

S*+p,e +ove state+e1t

$ro.p state+e1t ( Move Correspo1/*15 state+e1t

Move state+e1t .s*15 Of 4,a.se

"efere1t*a, +ove state+e1t


Move Statement
I1/*v*/.a, Move State+e1t *s .se/ to +ove /ata fro+ o1e
e,e+e1tary /ata *te+ to a1other e,e+e1tary /ata *te+.

MOVE WS'EMPNO'IN TO WS'EMPNO'O!T.


$ro.p +ove state+e1t *s .se/ to +ove /ata fro+ o1e 5ro.p
/ata to other 5ro.p.

MOVE WS'EMP"EC'IN TO WS'EMP"EC'O!T.


#ew Po*1ts To "e+e+ber wh*,e 5ro.p +ove *s that we 1ee/ to
see a,ways the *1/*v*/.a, /ata *te+ type8 s*9e a1/ se3.e14e of
the /ata *te+s.
MOVE STATEMET COTD!!
MOVE CO""ESPONDIN$ *s a,so o1e type of
5ro.p +ove b.t *1 th*s a,, the var*ab,es asso4*ate to
4orrespo1/*15 var*ab,e *1 other 5ro.p.

Sy1ta6

M+,e CORR -ROUP! TO -ROUP#"


I1 Most 4ases we /o1:t prefer 5ro.p +ove at a,,.

E"am#le!!
;< WS'DATE'DMY. ;< WS'DATE'YMD.
;= WS'DD PIC >?@-. ;= WS'YY PIC >?@-.
;= WS'MM PIC >?@-. ;= WS'MM PIC >?@-.
;= WS'YY PIC >?@-. ;= WS'DD PIC >?@-.
MOVE CO""ESPONDIN$ WS'DATE'DMY TO WS'DATE'
YMD.
MOVE STATEMET COTD!!
Move statement using Of clause; suppose we have two
groups and each of which contains one data-item with
same name.
EX: 01 EMPE!1. 01 EMPE!"

0# EMP-$% 0# EMP-$%.

MO&E EMP-$% 'O EMP-$%.


'(E )*O&E +tatement will ma,e the s-stem confuse.
'o avoid this error we can use;
MOVE EMP-ID O$ EMPREC% TO EMP-ID O$
EMPREC&!
'(stifi)ation
At the t*+e of N!ME"IC +ove the /*5*ts a,*51+e1t
ta0es p,a4e fro+ r*5ht s*/e a1/ the tr.14at*o1 +ay
ta0es p,a4e fro+ ,eft s*/e of the va,.e.
At the t*+e of ALPAABETIC a1/
ALPAAN!ME"IC +ove the 4hara4ter a,*51+e1t
ta0es p,a4e fro+ ,eft s*/e a1/ the tr.14at*o1 +ay ta0es
p,a4e fro+ r*5ht s*/e of the va,.e.
At the t*+e of DECIMAL +ove the /*5*ts ta0es po*1t
a,*51+e1t a1/ the tr.14at*o1 +ay ta0es p,a4e fro+
both ?,eft8r*5ht- s*/es of the va,.e.

ADD

S!BT"ACT

M!LTIPLY

DIVIDE

COMP!TE
Arit*meti) VERBS
The ADD state+e1t s.+s two or +ore 1.+er*4 opera1/s a1/ stores
the res.,t.
Sy1ta6'<
ADD B */e1t*f*er'< ,*tera,'< C D */e1t*f*er'@ ,*tera,'@ E . . .
TO */e1t*f*er'F D */e1t*f*er'G E . . .
Sy1ta6'@
ADD B */e1t*f*er'< ,*tera,'< C B */e1t*f*er'@ ,*tera,'@ C
D */e1t*f*er'F ,*tera,'F E $IVIN$ */e1t*f*er'G . . .
ADD VERB
Before
WS;;'IN< <@F
WS;;'O!T< ;;;;
After
WS;;'IN< <@F
WS;;'O!T< ;<@F
Before
WS;;'IN< <@F
WS;;'O!T@ ;;;;
After
WS;;'IN< <@F
WS;;'O!T@ ;@@F
Before
WS;;'IN< <@F
WS;;'IN@ G=H
WS;;'O!T@ ;;;;
After
WS;;'IN< <@F
WS;;'IN@ G=H
WS;;'O!T@ ;=I>
ADD
The S!BT"ACT state+e1t s.btra4ts o1e 1.+er*4 *te+ or the
s.+ of two or +ore 1.+er*4 *te+s fro+ o1e or +ore 1.+er*4
*te+s a1/ stores the res.,t.
Sy1ta6
S!BT"ACT B */e1t*f*er'< ,*tera,'< C D */e1t*f*er'@ ,*tera,'@ E
. . .
#"OM */e1t*f*er'F D */e1t*f*er'G E
D $IVIN$ */e1t*f*er'= D */e1t*f*er'H E . . . E
S+BTRACT VERB
Before
WS;;'IN< <<<
WS;;'O!T< <<<<
After
WS;;'IN< <<<
WS;;'O!T< <;;;
Before
WS;;'IN< <<<
WS;;'O!T@ @@@@
After
WS;;'IN< <<<
WS;;'O!T@ @;;;
Before
WS;;'IN< <<<
WS;;'IN@ ===
WS;;'O!TF HHHH
WS;;'O!TG >HHH
After
WS;;'IN< <<<
WS;;'IN@ ===
WS;;'O!TF HHHH
WS;;'O!TG H;;;
S!BT"ACT
The M!LTIPLY state+e1t +.,t*p,*es 1.+er*4 *te+s a1/ sets the
va,.es of /ata *te+s e3.a, to the res.,ts
Sy1ta6
M!LTIPLY B */e1t*f*er'< ,*tera,'< C BY */e1t*f*er'@
D */e1t*f*er'F E . . .
D $IVIN$ */e1t*f*er'G D */e1t*f*er'= E . . . E
M+LTIPL, VERB
Before
WS;;'IN< <;;
WS;;'O!T< <<<<
After
WS;;'IN< <;;
WS;;'O!T< <;;;
Before

WS;;'IN@ <;
WS;;'O!T@ ;@@@
WS;;'O!TF ;HHH
After
WS;;'IN@ <;
WS;;'O!T@ ;@@@
WS;;'O!TF @@@;
M!LTIPLY
"
The DIVIDE state+e1t /*v*/es o1e 1.+er*4 /ata *te+ *1to or by other?s- a1/ sets
the va,.es of /ata *te+s e3.a, to the 3.ot*e1t a1/ re+a*1/er.
Sy1ta6'<
DIVIDE B */e1t*f*er'< ,*tera,'< C INTO */e1t*f*er'@ D */e1t*f*er'@ E . . . D
$IVIN$ */e1t*f*er'G D */e1t*f*er'= E . . . E ..
Sy1ta6'@
DIVIDE B */e1t*f*er'< ,*tera,'< C BY B */e1t*f*er'@ ,*tera,'@ C
$IVIN$ */e1t*f*er'F D */e1t*f*er'G E.
Sy1ta6'F
DIVIDE B */e1t*f*er'< ,*tera,'< C B INTO BY C B */e1t*f*er'@ ,*tera,'@ C
$IVIN$ */e1t*f*er'F "EMAINDE" */e1t*f*er'G.
DIVIDE VERB
Before
WS;;'IN< <;;
WS;;'O!T< <;;;
After
WS;;'IN< <;;
WS;;'O!T< ;;<;
Before

WS;;'IN@ <;
WS;;'O!T@ @;;;
WS;;'O!TF ;;
After
WS;;'IN@ <;
WS;;'O!T@ ;;;J
WS;;'O!TF <H
DIVIDE
T*e
COMP+TE
{ } COMPUTE I.ent$/$e0 1 ROUNDED 2 " " " 3 A0$t4met$cE'p0ess$+n

ON SI5E ERROR
NOT ON SI5E ERROR
StatementB%+c6 END COMPUTE

'

1
]
1
Precedence Rules.
1. ** = POWER NN
2. * = MULTIPLY x
/ = DIVIDE
. ! = "DD !
# = $U%TR"&T #
.
T*e RO+DED o#tion
Rece'('n) *'eld "c+u,l Resul+ Trunc,+ed Resul+ R-unded Resul+
PI& ./0V.. 12.21
PI& ./0. 12.21
1".." 1"...
1". 1".

The "O!NDED opt*o1 ta0es effe4t whe1 after


/e4*+a, po*1t a,*51+e1t the res.,t 4a,4.,ate/ +.st
be tr.14ate/ o1 the r*5ht ha1/ s*/e.

The opt*o1 a//s < to the re4e*v*15 *te+ whe1 the


,eft+ost tr.14ate/ /*5*t has a1 abso,.te va,.e of =
or 5reater.
Before
WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'INF
After
WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'INF @G.H
Before

WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'ING
After
WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'ING @G.I
Before
WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'INF ;
WS;;'E""O"'INF N
After
WS;;'IN< <@.FG
WS;;'IN@ <@.FG
WS;;'INF ;;
WS;;'E""O"'INF Y
Before

WS;;'IN< <@FG
WS;;'IN@ <@FG
WS;;'ING @GH
WS;;'E""O"'ING N
After
WS;;'IN< <@FG
WS;;'IN@ <@FG
WS;;'ING @GH
WS;;'E""O"'ING N
T*an- ,o(

You might also like