Table Of Content‘ELECTHONIC COMPOTEN PHOGHAMOMING INSTITOTE
1-B-M Data Processing and
Computer Programming Course
LBM, SYSTEM 60 - COBOL
STUDY UNIT COBOL 3
LESSON CB-C-11
Overtion Cade
INDEX TO INSTRUCTIONS, 1BM SYSTEM 360, Instrostton Nawmenie Aetvol
Toad Tez cr
tems Pies tee —tp
SEALS
tar OCS EE
Sowae Wate ——
‘came ee ——
a ona FOr awh wk aa ca | feu, a
| poe ils >
USING :maltinle wase reprstersy La 5 :
SING
LBM. DATA PROC)
AND COMPUTER PROGRAMMING
COBOL
1BM SYSTEM 360
LESSON C-8
TABLE CF CONTENTS
8.1 ARITHMETIC OPERATIONS
Avithmetic may oaly be perforsed
on clementavy oumerie itema defined,
In the Data division ané nameric Iit-
erals. Humerie items ind literals
fray aot exceee. 18 decimal eigite in
fength, A aumerie litera. may rot ke
the receiving Hele of en arithmetic
statement.
In Gono: ealents-
tions are performed ia work areas
Sotablisked ay Ube compiler duvng
all ssithinetic
rogram compilation, These arose
Cansothe refareaces by the program
mer. in ite simplest fore, an arith-
metic statement will cause one Factor
tebe moved to the work area, thon,
depending on the overatina being per-
Formed, the sorsed caczoz is added,
subtzacted, vfs, from the conterts of
tho work neu, The regalt ie ther:
moved From fhe wark area to she re
Sewing ciel apacitied in the arith
snelic statement,
jowever, since the 360 car anly
periare wullanetic on binary iter
br packed decimal iteme, the com
Biler enay Hed it cecezeary to
Grate iustractions to core
Doth factors before the calculations
epeziozmed, In addit'on, Seperdi
in pushed format; ITEM is in DIS~
PLAY. The Procedare division
atetement woud be - ADDITRWA TO
ITEMB, Tae compiler would gererate
astructinrs to fizeteorvert ITZMB ta
packed decimal format and then mo:
to a work area, Since ITFMA is
ready in packae eeeimal format, con-
ersian is imecessary and it can be
added directly to ITED 'n tho work
Area. Lowever, bacanse the usage o:
the recaiving field is DISPTAY, the
tontuita of the work aren wanié have
th le coaverted back to EBCDIG fare
that before it could be stared
Tae wamer can specify that
rounding be getiormed. or the Siral
Feeult by usiag the ROUNDING option
Rounding ie weually desired in sicas-
tien where the intezmediate result
na moredecimal laces than the
When Fae Pounding option
2 exercised, tue Tefimost cigit of tne
digite to be tranzated, 1s examined to
See if ity value is 5 o7 greater. [fat
fa, Log adeod to the sipntmost dieit,
of the fina. resy't. Tf rounding is aot
Specitied, the trascated digite are
Abt insneeted, When used, tae ren
perved ware ROUNDED must imme-
Glicely follow the name of the vee
anihe usape of the receiving he'd, it eiving “Aleld, e.g. ADD A TOB
thay be necessary ty wnmest the Fer ROLNORD, Somecxampies of the use
Sul before it cen be wioved. Asan ani nnrenae of tae option are given
iluetration, lot's nesurnmtaatwe wish delow.
to odd STEMA to IPEMB. TTSMA te
|" Tntermediate Receiving Fied | Rounding Not | Rourdirg
(rn BS isere Soeciied | Spoeiiied
1.0 ova 1s 1.5
16 ws [ns he
3.3256 aves 5.32
98.7 39
2078 v9 ae 4
Lesson €8 age
‘The SI7E ERROR ontioa geviits
the programmer to test if aridire-
fic ove=‘low has occurred, A size
error, uz arithmetic overflow,
cure whea ail of the signilicuat di
to the left of the decimal pal In dhe
intermediate verult, will not Lit Lato
the receiving [eld. Lf the optior isn't
ased aud 2 size error oceurs, the re
Suit stored in she receiving ficle will
havehae someof is high-order di
truncated. IF the optioa is waoe, noth
fag is elored in the roceiving field.
Instead, the imperative statements in
the option are execated, Sine error
skuulé rot be a orohlem since you
yeacrally can Salemlate tie size 0
your ‘argest ~esult Yolerehand, An
exemple vf am ADD statement which
fneludes Cie ROUNDED and ON SL/1,
ERAOR options is shown be'ow,
ADD INVO:CR-AMT TO TOTAL-BILL ROUNDED ON SIR ERKOL
GO TO SIZM-ERROR- ROUTINE
The GIVING option appears ow all
arithmetic statements except for te
COMPUTE statement. This aption al-
lows the programmer to save the fac-
tors used in the calculation and have
the Final resultstored in another area,
For example, ater execttion of the
statement: ADD ATO B, the contents
of Rhavebeen destroyed and replaces
by the sum of A+B. Tf, on the other
hane, we needed tho comtente of Pf
another calculation, we could write
fie following statement: ADD A, 3
GIVINGC. With this staGemont, A ane
B would still be added together ina
work azea but the [asl result would
be stozed in G aad not B. Because tie
Poge 2
contents of the azearepraserted ay ©
in the wtatementabore are tat used in
the calculations, ts picture can be
Uhatel a repurtiters, This means that
we can, for example, sé too num=
bers togethe: and have the reste
ecited, all in one arithmetic st
ment,
Statomont
The ADD statement adde two or
more. elementary mu
Vera's and places
ast dalnararie in the 4
Leseon C8
Format 1,
\eate-name-1 | Paatacnamen2
po [akeiiea | SSR]
TO data-name-r
ERROR imperative: statement
Format 2, GIVING optior
fdatacame-? || dati-narm
ADD aumerie-lterel- | feuses e-siteral2 } — [mume:e-liten
2 ot one 7
wan abatements.
iVING daiaer
nn) [ox size RAKoR imoe
mat, the contents of tent L deta-names ane, Ztevals
‘endfor numeri procoding the word GLVING are added
crals, iucluding cata-neme-n, aze | anethe gamis stored in dace-name--),
added fopcther anc tke aim is stored Data-neme-n must 2¢ either a1 cle
in deto-rame-n,
points are aligned.
implied dectsel mentarymemeric or reportiturm Mun
that walle the xeserved wore TC is
mandatory in the Hirst format, its
In Us second format, at least tee vy inthe second Zozmat ia foxbidden,
dain mamas a- mumericliteracs mush Some examp.ca of ADD sLutermnby In
cede the wor! GIVING, Ike con- both fosmnats aze akown below
ATOR,
ADD A TO 3 RGUNDRD OW S17. ZRKOR GO LO OVELO,
ADD A, B, © TO b ROUSDFD.
ADD A, BCIVING G ROUND=D,
ADD 1 TO cou
pb =20, AVERY
"b GLVING WRIGHT 2D AYLRACT
Lescon CE Pose 3
SUBTRAGT statement
The SUBTRACT statement sub-
tracts one az more elementary ri
meric items oz literals [rom another
elementary numeric item, The dif-
erence is placed in the last data—
nance in the statement, Ils formals
aata-aame-1
TRACT | numerioeliterale1}
| [aata-name-2
suarracr fromericctiersic:} [aumeniciteral-2 |... EROM daseename-a
[rome] ov.sizi nian smporntvecaatement J
Irormae 2. GIVING option
GIVING data-name-n [kommen] fee SIZE ERROR imperative-atatement ...).
Scata-name-m
2}. 4 nemerie-Isterei-m |
I
In the first format, the values of
al data-names or mumerie-liteculs
preceding the word FROM are aub=
facted from the ccntente of data-
pamesn, Tao resulting difference 1s
stored in data-name-n and reslaces
its original contents,
In the second format, die values
of all data-names and humericnTibe
erala sreceding the word FROM aze
subtracted from data-rame-tn oF mi
mieric-Hteral-m, ‘The resulting dif-
ference, however, is stored in duta-
name-a thereby Teaving Gre original
values of data-name-m: oz mumeric-
iteralem uackaaged. Some examples
of subtruct statements are show be
SUBTRACT 1 PROM COUNT,
SUBTRACT A FROM B.
SUBTRACT A, B, FROM,
SUBTRACT A FROM L GIVING C,
TRACT A, B FROM C GIY
1G D ROUNDED,
Poge 4
Lescon C8
Letus lukutaprugras which vses
the ADD and SUBTRACT statemerts
fle 1s recurded an magnetic
records tp tie block, 50 cha
zacters to the record. The “ile con-
tains standard labels. Each record in
the file age the following foz:na
‘The program is to create a cew
tape Bile with the same blocking f2c~
£0 | blank
The result field in the output ro
cord ist contain the reault of
FLDA + FLD3 - FLDC and FLOD.
That is, FLDA and FLDB are to be.
added together and FLDC and PLDD.
are to be subtracted from that sum.
‘The input and output files and re~
cords are defined in the Duta division
fon lines 0) to 17 of Figure 1. Note
that the usage of all elds involved
in the calculations is given as COM
PUTATIONAL-3, or packed decimal
format.
Lesson C8
Result xsoex, xx ( packed)
1-5 | Ancount Number
6-9 P FLDA soe x (packed)
Tqolia | Fepe sone (packed)
wis | F Zoo am (packes) |
1-18 | FuDD (packes)
19-50 | blans ~~
lor and record length, The Zo
the output record is to Ber
The Procecuze division begins 02
line Th, The Bret paragraph opens
our inpse and output fies, The second
paragraph ceace = record from the
Input fle, The AT END clause in the
staternent specitice that the Hles are
fo be loeed and the ran terminated
‘ies! end-of-Ele 1s detected,
The third paragraph processes the
the input record. The first move
statement clears the output area by
foving the Sigurative constant
SPACES ta it, The next statement
Pose 5.
some Han) TNE "aN OSE oe HP
+ ry
CHEL
Gi
CHNLU
; cl
tr Gu
i i
i
t I
- Hy
BI
i ri
i iP
x ere
= Thad
ai E T TLE ee 0] Tag aaa
pone rover) Em ais
ace La
Paikiens a
Lesson C8
I3aHS Wyuooua TOB00
Wal
Peas 3.