Download Class

Document related concepts
no text concepts found
Transcript
Any Questions!
Agenda
• Moving data
• Arithmetic Verbs
• Compute statement
2
MOVE
• COBOL assignment verb
MOVE name TO first-name.
THE MOVE STATEMENT
PROCESS-RECORDS.
MOVE EMP-NAME TO DET-NAME
MOVE EMP-HOURS TO DET-HOURS
01 EMPLOYEE-IN.
05 EMP-NAME
05 EMP-HOURS
05 EMP-RATE
05 EMP-DEP
01 DETAIL-LINE.
05 FILLER
05 DET-NAME
05 FILLER
05 DET-HOURS
05 FILLER
05 DET-PAY
05 FILLER
4
THE MOVE STATEMENT
PROCESS-RECORDS.
MOVE EMP-NAME TO DET-NAME
MOVE EMP-HOURS TO DET-HOURS
•Source contents assigned to destination
variable
•Specific rules to do the move
•Move is just a copy, source does not
change
•Equivalent to C assignments
5
Move Statement
MOVE Identifier/Variable or Literal/Constant
TO (Indentifier/Variable)s
6
Permissible Moves
Sending Field Receiving Field Okay?
Numeric
Numeric
Yes
Numeric
Alphanumeric
Sometimes
Numeric
Group Item
Sometimes
Alphanumeric Alphanumeric
Yes
Alphanumeric Group Item
Yes
7
Permissible Moves
Sending Field Receiving Field Okay
Zeros
Numeric
Yes
Zeros
Alphanumeric
Yes
Zeros
Group Item
Yes
Spaces
Alphanumeric
Yes
Spaces
Group Item
Sometimes
8
Permissible Moves
Sending Field Receiving Field Okay?
Group Item
Alphanumeric
Yes
Group Item
Group Item
Yes
9
Non-Permissible Moves
Sending Field
Receiving Field
Numeric (with a
Decimal Point)
Alphanumeric
Alphanumeric
Spaces
Numeric*
(works for me!)
Numeric
Group Item
Numeric
10
Numeric Moves
Sending Field
Numeric
Receiving Field
Numeric
– Field sizes
Numeric
Alphanumeric
– Decimal places
– Packed fields
Numeric
Group Item
Okay?
MOVE numeric TO numeric.
Field A PIC 9(3)
100
Field B PIC 9(3)
Field A PIC 9(3)
100
Field B PIC 9(4)
Field A
100
Field B PIC 9(2)
PIC 9(3)
12
MOVE numeric TO numeric.
Field A PIC 9(3)V99 Field B PIC 99V9
100.03
Field A PIC 9(3)V99 Field B PIC 9(4)V999
100.03
Field A PIC 9(3)V99 Field B PIC 9(3)
100.03
13
MOVE numeric TO alphanumeric.
Field A PIC 9(3)
100
Field B PIC X(3)
Field A PIC 9(3)
100
Field B PIC X(4)
Field A PIC 9(3)
100
Field B PIC X(2)
14
MOVE numeric TO alphanumeric.
Field A PIC 9(3)V99
100.03
Field B PIC X(3)
15
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC 99.
Field D PIC 9.
Field A
124
Field C
Field B
Field D
16
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC 99.
Field D PIC 99.
Field A
124
Field C
Field B
Field D
17
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC 9.
Field D PIC 9.
Field A
124
Field C
Field B
Field D
18
Alphanumeric Moves
Sending Field
Alphanumeric
Receiving Field
Numeric
– Decimal Places
– Packed fields
Alphanumeric
Alphanumeric
– Field sizes
Alphanumeric
Group Item
Okay?
Zero Moves
Sending Field
Zeros
Receiving Field
Numeric
Zeros
Alphanumerics
Zeros
Group Item
Okay?
Spaces Moves
Sending Field
Spaces
Receiving Field
Numeric
Spaces
Alphanumerics
Spaces
Group Items
Okay?
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC XX.
Field D PIC X.
Field A
124
Field C
Field B
Field D
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC XX.
Field D PIC XX.
Field A
124
Field C
Field B
Field D
MOVE numeric TO group item
Field A PIC 9(3)
Field B.
Field C PIC X.
Field D PIC X.
Field A
124
Field C
Field B
Field D
MOVE alphanum TO alphanum.
Field A
PIC X(3) Field B
PIC X(3)
Field A
CJM
PIC X(3) Field B
PIC X(4)
Field A
CJM
PIC X(3) Field B
PIC X(2)
CJM
MOVE alphanum TO group item
Field A PIC X(3)
Field A
CJM
Field B
Field B.
Field C PIC XX.
Field D PIC X.
Field C
Field D
MOVE alphanum TO group item
Field A PIC X(3)
Field B.
Field C PIC XX.
Field D PIC XX.
Field A
CJM
Field C
Field B
Field D
MOVE alphanum TO group item
Field A PIC X(3)
Field B.
Field C PIC X.
Field D PIC X.
Field A
CJM
Field C
Field B
Field D
MOVE alphanum TO numeric.
Field A
ABC
PIC X(3) Field B
PIC 9(3)
MOVE zeros TO numeric.
Field B
PIC 9(3)
Field B
PIC 9(4)V99
MOVE zeros TO alphanumeric.
Field B
PIC X(3)
Field B
PIC X(1)
MOVE zero TO group item
Field B.
Field C PIC 99.
Field D PIC 9.
Field B
Field C
Field D
MOVE zeros TO group item
Field B.
Field C PIC XX.
Field D PIC XX.
Field B
Field C
Field D
MOVE spaces TO numeric.
Field B
PIC 9(3)
Field B
PIC 9(4)V99
Note: This is not supposed to work!
MOVE spaces TO alphanumeric.
Field B
PIC X(3)
Field B
PIC X(1)
MOVE spaces TO group item
Field B.
Field C PIC 99.
Field D PIC 9.
Field B
Field C
Field D
Note: this is not supposed to work!
MOVE spaces TO group item
Field B.
Field C PIC XX.
Field D PIC XX.
Field B
Field C
Field D
On your own, figure out how
Group Item to Group Item and
Group Item to Alphanumeric
work!
Arithmetic Verbs
Add, Subtract, Multiply and Divide
ALL can use SCOPE-TERMINATORS
39
Add Verb
• Three Formats:
ADD variable/constant variable/constant …..
TO variable [ROUNDED] ….
ADD variable/constant variable/constant …...…
GIVING variable [ROUNDED]
ADD variable/constant variable/constant …….
TO variable/constant
GIVING variable [ROUNDED]
40
ADD Verb
A = 100
B = 50
C = 300
ADD A to B
A=
B=
C=
ADD A to B GIVING C
A=
B=
C=
What would happen if C was PIC 9(2)?
ADD A B GIVING C ROUNDED
A=
B=
C=
What would happen if C was PIC 9(2)?
41
SUBTRACT Verb
Two Formats:
SUBTRACT Variable/Constant Variable/Constant ...
FROM Variable [ROUNDED]
SUBTRACT Variable/Constant Variable/Constant …
FROM Variable GIVING Variable [ROUNDED]
42
SUBTRACT Statement
A = 100
B = 50
C = 150
SUBTRACT A B FROM C
A=
B=
C=
D = 200
D=
SUBTRACT A B FROM C GIVING D
A=
B=
C=
D=
43
MULTIPLY Statement
• More restrictive
• Two Formats
MULTIPLY variable/constant BY variable….
MULTIPLY variable/constant BY
variable/constant GIVING variable …...
44
MULTIPLY Statement
A = 50
B = 100
C = 20
MULTIPLY A BY B
A=
B=
MULTIPLY A BY B C
A=
B=
D = 500
C=
C=
MULTIPLY A BY B GIVING C D
A=
B=
C=
45
DIVIDE Statement
• More restrictive
• Three Formats
DIVIDE variable/constant INTO variable ….
DIVIDE variable/constant INTO
variable/constant [GIVING variable …..]
DIVIDE variable/constant BY
variable/constant GIVING variable …...
46
DIVIDE Statement
A = 100
B = 50
C = 25 D = 120.5
DIVIDE A INTO B D
A=
B=
C=
DIVIDE A INTO B GIVING C D
A=
B=
C=
DIVIDE A BY B GIVING C
A=
B=
C=
47
REMAINDER Clause
• Two formats:
DIVIDE variable/constant INTO
variable/constant GIVING variable
REMAINDER variable
DIVIDE variable/constant BY
variable/constant GIVING variable
REMAINDER variable
48
REMAINDER Clause
A = 100
B = 150
C = 20
D = 10
DIVIDE A INTO B GIVING C
REMAINDER D.
A=
B=
C=
D=
49
Clauses that work with all
arithmetic statements.
50
Rounding
• Add the ROUNDED option to the end of
the math statement.
• Eg. DIVIDE A INTO B GIVING C
ROUNDED.
51
ON SIZE ERROR option
• What to do if the resulting value from the
Mathematical Expression is too big for the
result variable.
• Used to Resolve Divide by Zero errors.
ADD A B GIVING C
ON SIZE ERROR
PERFORM ERROR-HANDLING-ROUTINE.
52
Compute Statement
Combines all of the math verbs plus
exponentiation
53
The COMPUTE Statement
COMPUTE DET-PAY = EMP-HOURS * EMP-RATE
•Cobol provides:
Addition
+ or ADD
Subtraction
- or SUBTRACT
Multiplication
* or MULTIPLICATION
Division
/ or DIVIDE
Exponentiation
**
•COMPUTE can combine all of them
•Or you can use individual verbs (ADD 1 TO MYCUNTER)
54
Compute Statement Symbols
Symbol
Meaning
+
ADD
-
SUBTRACT
*
MULTIPLY
/
DIVIDE
**
exponentiation
55
Order of Operations
• Operations in brackets ( ) are performed
first
• ** (exponentiation)
• * or / (from left to right)
• + or - (from left to right)
56
Compute Statement
A=
10
B=2
C = 60
D is PIC 9(4)
COMPUTE D ROUNDED = A ** B / ( A B) + C.
What is the value of D?
57
Related documents