Download presentation
Presentation is loading. Please wait.
Published byClaude Cross Modified over 8 years ago
2
Any Questions!
3
2 Agenda Moving data Arithmetic Verbs Compute statement
4
MOVE COBOL assignment verb MOVE name TO first-name.
5
4 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
6
5 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
7
6 Move Statement MOVE Identifier/Variable or Literal/Constant TO (Indentifier/Variable)s
8
7 Permissible Moves
9
8
10
9
11
10 Non-Permissible Moves
12
Numeric Moves Sending FieldReceiving Field Okay?Numeric –Field sizes NumericAlphanumeric –Decimal places –Packed fields Numeric Group Item
13
12 MOVE numeric TO numeric. Field A PIC 9(3) Field B PIC 9(3) 100 Field A PIC 9(3)Field B PIC 9(4) 100 Field APIC 9(3) Field B PIC 9(2) 100
14
13 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
15
14 MOVE numeric TO alphanumeric. Field A PIC 9(3) Field B PIC X(3) 100 Field A PIC 9(3) Field B PIC X(4) 100 Field A PIC 9(3) Field B PIC X(2) 100
16
15 MOVE numeric TO alphanumeric. Field A PIC 9(3)V99 Field B PIC X(3) 100.03
17
16 MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC 99. Field D PIC 9. Field AField BField CField D 124
18
17 MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC 99. Field D PIC 99. Field AField BField CField D 124
19
18 MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC 9. Field D PIC 9. Field AField BField CField D 124
20
Alphanumeric Moves Sending FieldReceiving Field Okay? Alphanumeric Numeric –Decimal Places –Packed fieldsAlphanumeric –Field sizes Alphanumeric Group Item
21
Zero Moves Sending FieldReceiving Field Okay? ZerosNumeric ZerosAlphanumerics ZerosGroup Item
22
Spaces Moves Sending FieldReceiving Field Okay? SpacesNumeric Spaces Alphanumerics Spaces Group Items
23
MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC XX. Field D PIC X. Field AField BField CField D 124
24
MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC XX. Field D PIC XX. Field AField BField CField D 124
25
MOVE numeric TO group item Field A PIC 9(3)Field B. Field C PIC X. Field D PIC X. Field AField BField CField D 124
26
MOVE alphanum TO alphanum. Field APIC X(3) Field B PIC X(3) CJM Field A PIC X(3)Field BPIC X(4) CJM Field APIC X(3) Field BPIC X(2) CJM
27
MOVE alphanum TO group item Field A PIC X(3)Field B. Field C PIC XX. Field D PIC X. Field AField BField CField D CJM
28
MOVE alphanum TO group item Field A PIC X(3)Field B. Field C PIC XX. Field D PIC XX. Field AField BField CField D CJM
29
MOVE alphanum TO group item Field A PIC X(3)Field B. Field C PIC X. Field D PIC X. Field AField BField CField D CJM
30
MOVE alphanum TO numeric. Field APIC X(3) Field B PIC 9(3) ABC
31
MOVE zeros TO numeric. Field B PIC 9(3) Field BPIC 9(4)V99
32
MOVE zeros TO alphanumeric. Field B PIC X(3) Field BPIC X(1)
33
MOVE zero TO group item Field B. Field C PIC 99. Field D PIC 9. Field BField CField D
34
MOVE zeros TO group item Field B. Field C PIC XX. Field D PIC XX. Field BField CField D
35
MOVE spaces TO numeric. Field B PIC 9(3) Field BPIC 9(4)V99 Note: This is not supposed to work!
36
MOVE spaces TO alphanumeric. Field B PIC X(3) Field BPIC X(1)
37
MOVE spaces TO group item Field B. Field C PIC 99. Field D PIC 9. Field BField CField D Note: this is not supposed to work!
38
MOVE spaces TO group item Field B. Field C PIC XX. Field D PIC XX. Field BField CField D
39
On your own, figure out how Group Item to Group Item and Group Item to Alphanumeric work!
40
39 Arithmetic Verbs Add, Subtract, Multiply and Divide ALL can use SCOPE-TERMINATORS
41
40 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]
42
41 ADD Verb A = 100B = 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)?
43
42 SUBTRACT Verb Two Formats: SUBTRACT Variable/Constant Variable/Constant... FROM Variable [ROUNDED] SUBTRACT Variable/Constant Variable/Constant … FROM Variable GIVING Variable [ROUNDED]
44
43 SUBTRACT Statement A = 100 B = 50C = 150D = 200 SUBTRACT A B FROM C A = B = C = D = SUBTRACT A B FROM C GIVING D A = B = C = D =
45
44 MULTIPLY Statement More restrictive Two Formats MULTIPLY variable/constant BY variable…. MULTIPLY variable/constant BY variable/constant GIVING variable …...
46
45 MULTIPLY Statement A = 50 B = 100C = 20 D = 500 MULTIPLY A BY B A = B = C = MULTIPLY A BY B C A = B = C = MULTIPLY A BY B GIVING C D A = B = C =
47
46 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 …...
48
47 DIVIDE Statement A = 100B = 50C = 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 =
49
48 REMAINDER Clause Two formats: DIVIDE variable/constant INTO variable/constant GIVING variable REMAINDER variable DIVIDE variable/constant BY variable/constant GIVING variable REMAINDER variable
50
49 REMAINDER Clause A = 100 B = 150C = 20D = 10 DIVIDE A INTO B GIVING C REMAINDER D. A = B = C = D =
51
50 Clauses that work with all arithmetic statements.
52
51 Rounding Add the ROUNDED option to the end of the math statement. Eg. DIVIDE A INTO B GIVING C ROUNDED.
53
52 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.
54
53 Compute Statement Combines all of the math verbs plus exponentiation
55
54 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)
56
55 Compute Statement Symbols
57
56 Order of Operations Operations in brackets ( ) are performed first ** (exponentiation) * or / (from left to right) + or - (from left to right)
58
57 Compute Statement A = 10B = 2C = 60 D is PIC 9(4) COMPUTE D ROUNDED = A ** B / ( A - B) + C. What is the value of D?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.