Upload
marylou-walters
View
212
Download
0
Embed Size (px)
Citation preview
Arithmetic Arithmetic and and
Edited PicturesEdited Pictures
Arithmetic Verb TemplateArithmetic Verb Template
Most COBOL arithmetic verbs conform to the template Most COBOL arithmetic verbs conform to the template above. For example;above. For example;
ADD Takings TO CashTotal.ADD Takings TO CashTotal.ADD Males TO Females GIVING TotalStudents. ADD Males TO Females GIVING TotalStudents. SUBTRACT Tax FROM GrossPay.SUBTRACT Tax FROM GrossPay.SUBTRACT Tax FROM GrossPay GIVING NetPay.SUBTRACT Tax FROM GrossPay GIVING NetPay.DIVIDE Total BY Members GIVING MemberAverage.DIVIDE Total BY Members GIVING MemberAverage.DIVIDE Members INTO Total GIVING MemberAverage.DIVIDE Members INTO Total GIVING MemberAverage.MULTIPLY 10 BY Magnitude.MULTIPLY 10 BY Magnitude.MULTIPLY Members BY Subs GIVING TotalSubs.MULTIPLY Members BY Subs GIVING TotalSubs.
The exceptions are the The exceptions are the COMPUTE COMPUTE and the and the DIVIDEDIVIDE with with REMAINDER.REMAINDER.
VERB Identifier
Literal
TO
FROM
BY
INTO
Identifier
Identifier GIVING Identifier ROUNDED
ON SIZE ERROR StatementBlock END - VERB
The ROUNDED optionThe ROUNDED optionReceiving Field Actual Result Truncated Result Rounded Result
PIC 9(3)V9. 123.25
PIC 9(3). 123.25
123.2123.2 123.3 123.3
123123 123 123
The ROUNDED option takes effect when, after The ROUNDED option takes effect when, after decimal point alignment, the result calculated decimal point alignment, the result calculated must be truncated on the right hand side. must be truncated on the right hand side.
The option adds 1 to the receiving item when the The option adds 1 to the receiving item when the leftmost truncated digit has an absolute value of leftmost truncated digit has an absolute value of 5 or greater.5 or greater.
A size error condition exists when, after decimal A size error condition exists when, after decimal point alignment, the result is truncated on either point alignment, the result is truncated on either the the leftleft or the or the rightright hand side.hand side.
If an arithmetic statement has a rounded phrase If an arithmetic statement has a rounded phrase then a size error only occurs if there is truncation then a size error only occurs if there is truncation on the on the leftleft hand side (most significant digits). hand side (most significant digits).
Receiving Field Actual Result SIZE ERROR
PIC 9(3)V9. 245.96
PIC 9(3)V9. 1245.9
PIC 9(3). 124
PIC 9(3). 1246
PIC 9(3)V9 Not Rounded 124.45
PIC 9(3)V9 Rounded 124.45
PIC 9(3)V9 Rounded 3124.45
The ON SIZE ERROR optionThe ON SIZE ERROR option
YesYes
YesYes
NoNo
YesYes
YesYes
NoNo
YesYes
ADD ExamplesADD Examples
ADD Cash TO Total.BeforeBefore 3 1000AfterAfter
ADD Cash, 20 TO Total, Wage.Before Before 3 1000 100AfterAfter
ADD Cash, Total GIVING Result.BeforeBefore 3 1000 0015AfterAfter
ADD Males TO Females GIVING TotalStudents.Before Before 1500 0625 1234AfterAfter
ADD Cash TO Total.BeforeBefore 3 1000AfterAfter
ADD Cash, 20 TO Total, Wage.Before Before 3 1000 100AfterAfter
ADD Cash, Total GIVING Result.BeforeBefore 3 1000 0015AfterAfter
ADD Males TO Females GIVING TotalStudents.Before Before 1500 0625 1234AfterAfter
3 3 10031003
33 1023 123 1023 123
3 1000 3 1000 1003 1003
1500 06251500 0625 2125 2125
SUBTRACT ExamplesSUBTRACT Examples
SUBTRACT Tax FROM GrossPay, Total.Before Before 120 4000 9120 AfterAfter
SUBTRACT Tax, 80 FROM Total.Before Before 100 480AfterAfter
SUBTRACT Tax FROM GrossPay GIVING NetPay.BeforeBefore 750 1000 0012AfterAfter
SUBTRACT Tax FROM GrossPay, Total.Before Before 120 4000 9120 AfterAfter
SUBTRACT Tax, 80 FROM Total.Before Before 100 480AfterAfter
SUBTRACT Tax FROM GrossPay GIVING NetPay.BeforeBefore 750 1000 0012AfterAfter
120 120 3880 9000 3880 9000
100100 300 300
750 1000 750 1000 0250 0250
MULTIPLY and DIVIDE ExamplesMULTIPLY and DIVIDE Examples
MULTIPLY Subs BY Members GIVING TotalSubs ON SIZE ERROR DISPLAY "TotalSubs too small" END-MULTIPLY. Subs Members TotalSubsSubs Members TotalSubs
BeforeBefore 15.50 100 0123.45AfterAfter
MULTIPLY 10 BY Magnitude, Size.
BeforeBefore 355 125AfterAfter
DIVIDE Total BY Members GIVING Average ROUNDED.BeforeBefore 9234.55 100 1234.56AfterAfter
MULTIPLY Subs BY Members GIVING TotalSubs ON SIZE ERROR DISPLAY "TotalSubs too small" END-MULTIPLY. Subs Members TotalSubsSubs Members TotalSubs
BeforeBefore 15.50 100 0123.45AfterAfter
MULTIPLY 10 BY Magnitude, Size.
BeforeBefore 355 125AfterAfter
DIVIDE Total BY Members GIVING Average ROUNDED.BeforeBefore 9234.55 100 1234.56AfterAfter
15.50 100 15.50 100 1550.001550.00
3550 12503550 1250
9234.55 100 9234.55 100 92.35 92.35
The Divide ExceptionThe Divide Exception
DIVIDE INTO GIVING Identifier [ ROUNDED ] REMAINDER Identifier
ON SIZE ERROR
NOT ON SIZE ERROR StatementBlock END - DIVIDE
DIVIDE BY GIVING Identifier [ ROUNDED ] REMAINDER Identifier
ON SIZE ERROR
NOT ON SIZE ERROR StatementBlock END - DIVIDE
Identifier
Literal
Identifier
Literal
Identifier
Literal
Identifier
Literal
DIVIDE 201 BY 10 GIVING Quotient REMAINDER Remain.Before Before 209 424AfterAfter
DIVIDE 201 BY 10 GIVING Quotient REMAINDER Remain.Before Before 209 424AfterAfter 020 001020 001
Compute IrishPrice = SterlingPrice / Rate * 100.Before Before 1000.50 156.25 87 AfterAfter
Compute IrishPrice = SterlingPrice / Rate * 100.Before Before 1000.50 156.25 87 AfterAfter 179.59 179.59 156.25 87156.25 87
The COMPUTEThe COMPUTE
COMPUTE Identifier [ ROUNDED ] . . . = ArithmeticExpression
ON SIZE ERROR
NOT ON SIZE ERROR StatementBlock END - COMPUTE
Precedence Rules.Precedence Rules.1.1. **** = POWER NN
2.2. ** = MULTIPLY x// = DIVIDE ÷
3.3. ++ = ADD +-- = SUBTRACT -
Precedence Rules.Precedence Rules.1.1. **** = POWER NN
2.2. ** = MULTIPLY x// = DIVIDE ÷
3.3. ++ = ADD +-- = SUBTRACT -
Edited Pictures.Edited Pictures.
Edited Pictures are PICTURE clauses which Edited Pictures are PICTURE clauses which formatformat data data intended for output to screen or printer.intended for output to screen or printer.
To enable the data items to be formatted in a particular To enable the data items to be formatted in a particular style COBOL provides additional picture symbols style COBOL provides additional picture symbols supplementing the basic supplementing the basic 99, , XX, , AA, , VV and and SS symbols. symbols.
The additional symbols are referred to as “Edit Symbols” The additional symbols are referred to as “Edit Symbols” and PICTURE clauses which include edit symbols are and PICTURE clauses which include edit symbols are called “Edited Pictures”.called “Edited Pictures”.
The term edit is used because the edit symbols have the The term edit is used because the edit symbols have the effect of changing, or editing, the data inserted into the effect of changing, or editing, the data inserted into the edited item.edited item.
Edited items can Edited items can notnot be used as operands in a be used as operands in a computation but they may be used as the result or computation but they may be used as the result or destination of a computation (i.e. to the right of the word destination of a computation (i.e. to the right of the word GIVING).GIVING).
Editing TypesEditing Types
COBOL provides two basic types of editingCOBOL provides two basic types of editing
ŒŒ Insertion Editing - Insertion Editing - which modifies a value by which modifies a value by including additional items.including additional items.
Suppression and Replacement Editing -Suppression and Replacement Editing -which suppresses and replaces leading zeros.which suppresses and replaces leading zeros.
Each type has sub-categoriesEach type has sub-categories
Insertion editingInsertion editingSimple InsertionSimple InsertionSpecial InsertionSpecial InsertionFixed InsertionFixed InsertionFloating InsertionFloating Insertion
Suppression and ReplacementSuppression and ReplacementZero suppression and replacement with spacesZero suppression and replacement with spacesZero suppression and replacement with Zero suppression and replacement with
asterisksasterisks
Editing SymbolsEditing Symbols
, B 0 / Simple Insertion
. Special Insertion
+ - CR DB $ Fixed Insertion
+ - S Floating Insertion
Z * Suppression and Replacement
, B 0 / Simple Insertion
. Special Insertion
+ - CR DB $ Fixed Insertion
+ - S Floating Insertion
Z * Suppression and Replacement
Edit Symbol Editing TypeEdit Symbol Editing Type
Simple Insertion.Simple Insertion.
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 999999 123456 PIC 999,999
PIC 9(6) 000078 PIC 9(3),9(3)
PIC 9(6) 000078 PIC ZZZ,ZZZ
PIC 9(6) 000178 PIC ***,***
PIC 9(6) 002178 PIC ***,***
PIC 9(6) 120183 PIC 99B99B99
PIC 9(6) 120183 PIC 99/99/99
PIC 9(6) 001245 PIC 990099
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 999999 123456 PIC 999,999
PIC 9(6) 000078 PIC 9(3),9(3)
PIC 9(6) 000078 PIC ZZZ,ZZZ
PIC 9(6) 000178 PIC ***,***
PIC 9(6) 002178 PIC ***,***
PIC 9(6) 120183 PIC 99B99B99
PIC 9(6) 120183 PIC 99/99/99
PIC 9(6) 001245 PIC 990099
123123,,456456000000,,0780787878****178****178**2**2,,178178
1212010183831212//0101//8383 121200004545
Special Insertion.Special Insertion.
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 999V99 12345 PIC 999.99
PIC 999V99 02345 PIC 999.9
PIC 999V99 51234 PIC 99.99
PIC 999 456 PIC 999.99
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 999V99 12345 PIC 999.99
PIC 999V99 02345 PIC 999.9
PIC 999V99 51234 PIC 99.99
PIC 999 456 PIC 999.99
123123..4545
023023..44
1212..3434
456456..0000
Fixed Insertion - Plus and Minus.Fixed Insertion - Plus and Minus.
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC S999 -123 PIC -999
PIC S999 -123 PIC 999-
PIC S999 +123 PIC -999
PIC S9(5) +12345 PIC +9(5)
PIC S9(3) -123 PIC +9(3)
PIC S9(3) -123 PIC 999+
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC S999 -123 PIC -999
PIC S999 -123 PIC 999-
PIC S999 +123 PIC -999
PIC S9(5) +12345 PIC +9(5)
PIC S9(3) -123 PIC +9(3)
PIC S9(3) -123 PIC 999+
--123123123123--123123
++1234512345--123123123123--
Fixed Insertion - Credit, Debit, $Fixed Insertion - Credit, Debit, $
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC S9(4) +1234 PIC 9(4)CR
PIC S9(4) -1234 PIC 9(4)CR
PIC S9(4) +1234 PIC 9(4)DB
PIC S9(4) -1234 PIC 9(4)DB
PIC 9(4) 1234 PIC $99999
PIC 9(4) 0000 PIC $ZZZZZ
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC S9(4) +1234 PIC 9(4)CR
PIC S9(4) -1234 PIC 9(4)CR
PIC S9(4) +1234 PIC 9(4)DB
PIC S9(4) -1234 PIC 9(4)DB
PIC 9(4) 1234 PIC $99999
PIC 9(4) 0000 PIC $ZZZZZ
1234123412341234CRCR1223122312341234DBDB
$$0123401234$$
Floating Insertion.Floating Insertion.
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 9(4) 0000 PIC $$,$$9.99
PIC 9(4) 0080 PIC $$,$$9.00
PIC 9(4) 0128 PIC $$,$$9.99
PIC 9(5) 57397 PIC $$,$$9
PIC S9(4) - 0005 PIC ++++9
PIC S9(4) +0080 PIC ++++9
PIC S9(4) - 0080 PIC - - - - 9
PIC S9(5) +71234 PIC - - - - 9
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 9(4) 0000 PIC $$,$$9.99
PIC 9(4) 0080 PIC $$,$$9.00
PIC 9(4) 0128 PIC $$,$$9.99
PIC 9(5) 57397 PIC $$,$$9
PIC S9(4) - 0005 PIC ++++9
PIC S9(4) +0080 PIC ++++9
PIC S9(4) - 0080 PIC - - - - 9
PIC S9(5) +71234 PIC - - - - 9
$$00..0000 $$8080.00.00 $$128128..0000$$77,,397397
--55 ++8080 --8080 žž12341234
Suppression and ReplacementSuppression and Replacement
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 9(5) 12345 PIC ZZ,999
PIC 9(5) 01234 PIC ZZ,999
PIC 9(5) 00123 PIC ZZ,999
PIC 9(5) 00012 PIC ZZ,999
PIC 9(5) 05678 PIC **,**9
PIC 9(5) 00567 PIC **,**9
PIC 9(5) 00000 PIC **,***
Sending Sending Receiving Receiving
Picture Data Picture ResultPicture Data Picture Result
PIC 9(5) 12345 PIC ZZ,999
PIC 9(5) 01234 PIC ZZ,999
PIC 9(5) 00123 PIC ZZ,999
PIC 9(5) 00012 PIC ZZ,999
PIC 9(5) 05678 PIC **,**9
PIC 9(5) 00567 PIC **,**9
PIC 9(5) 00000 PIC **,***
1212,,34534511,,234234123123012012**55,,678678******567567************