Download presentation
Presentation is loading. Please wait.
Published byElinor Heath Modified over 9 years ago
2
Any Questions?
3
Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect
4
Level 77 Used to define stand alone elementary items. No limit to the “number of” used in a program. Exclusively used in the WORKING-STORAGE SECTION ie. 77 ws-counter pic s9(5). 77 ws-alpha-work pix x(30).
5
Initialize Verb 01 Group-Item-1. 05 Num1 PIC 9(4) VALUE 9. 05 Num2 PIC 9(4) VALUE 35. 05 Alpha1 PIC X(10) VALUE ‘COBOL’. 05 Alpha2PIC X(20) VALUE ‘FUN’. INITIALIZE NUM1. INITIALIZE ALPHA1 NUM2. What happens?
6
Initialize Verb 01 Group-Item-1. 05 Num1 PIC 9(4) VALUE 9. 05 Num2 PIC 9(4) VALUE 35. 05 Alpha1 PIC X(10) VALUE ‘COBOL’. 05 Alpha2PIC X(20) VALUE ‘FUN’. INITIALIZE Group-Item-1. What happens?
7
Initialize Verb INITIALIZE variable1 variable2 variable3 … ALPHABETIC REPLACING ALPHANUMERIC NUMERIC ALPHANUMERIC-EDITED NUMERIC-EDITED BY Variable4 literal-1
8
Initialize Verb 01 Group-Item-1. 05 Num1 PIC 9(4) VALUE 9. 05 Num2 PIC 9(4) VALUE 35. 05 Alpha1 PIC X(10) VALUE ‘COBOL’. 05 Alpha2PIC X(20) VALUE ‘FUN’. INITIALIZE Group-Item-1 REPLACING ALPHANUMERICS BY ‘X’ NUMERIC BY 9 What happens?
9
Initialize Verb 01 Group-Item-1. 05 Num1 PIC 9(4) VALUE 9. 05 Num2 PIC 9(4) VALUE 35. 05 Alpha1 PIC X(10) VALUE ‘COBOL’. 05 Alpha2PIC X(20) VALUE ‘FUN’. INITIALIZE Group-Item-1 REPLACING NUMERICS BY 100. What happens?
10
Display & Accept Fast Interactive Screens Use of message queue / command line
11
Display DISPLAY variable1/literal1 variable2/literal2… AT LINE 99 COLUMN 99. Examples: DISPLAY STUDENT-RECORD. DISPLAY ‘Amount: ’ TRANS-AMOUNT. DISPLAY ‘Amount: ’ TRANS-AMOUNT AT LINE 8 COLUMN 10.
12
ACCEPT ACCEPT variable1 AT LINE 99 COLUMN 99. Examples: DISPLAY ‘Press Enter to Continue’. ACCEPT ENTER-VARIABLE.
13
Arithmetic Verbs Add, Subtract, Multiply, Divide And Compute
14
Add Verb Three Formats: ADD variable/constant TO variable ADD variable/constant, variable/constant, … GIVING variable ADD variable/constant TO variable/constant GIVING variable
15
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)?
16
SUBTRACT Verb Two Formats: SUBTRACT Variable/Constant Variable/Constant... FROM Variable SUBTRACT Variable/Constant Variable/Constant … FROM Variable GIVING Variable
17
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 =
18
MULTIPLY Statement More restrictive Two Formats MULTIPLY variable/constant BY variable MULTIPLY variable/constant BY variable/constant GIVING variable
19
MULTIPLY Statement A = 50B = 100C = 20 MULTIPLY A BY B A = B = C = MULTIPLY A BY B GIVING C A = B = C =
20
DIVIDE Statement More restrictive - Three Formats - Decimal alignment DIVIDE variable/constant INTO variable DIVIDE variable/constant INTO variable/constant GIVING variable DIVIDE variable/constant BY variable/constant GIVING variable
21
DIVIDE Statement A = 100B = 50C = 25 DIVIDE A INTO B A =B = C = DIVIDE A BY B GIVING C A = B = C =
22
REMAINDER Clause Two formats: DIVIDE variable/constant INTO variable/constant GIVING variable REMAINDER variable DIVIDE variable/constant BY variable/constant GIVING variable REMAINDER variable DECIMAL ALIGNMENT!
23
REMAINDER Clause A = 100 B = 150C = 20D = 10 DIVIDE A INTO B GIVING C REMAINDER D. A = B = C = D =
24
Clauses that work with all arithmetic statements. ROUNDED ON SIZE ERROR
25
Rounding Add the ROUNDED option to the math statement directly following the resulting field Eg. DIVIDE A INTO B GIVING C ROUNDED.
26
ON SIZE ERROR option What to do if the resulting value from the Mathematical Expression is too big for the result variable leading or trailing the decimal position. Used to Resolve Divide by Zero errors. ADD A B GIVING C ON SIZE ERROR PERFORM ERROR-HANDLING-ROUTINE.
27
Compute Statement Combines all of the math verbs plus exponentiation
28
Compute Statement Symbols
29
Order of Operations Operations in brackets ( ) are performed first ** (exponentiation) * or / (from left to right) + or - (from left to right)
30
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?
31
73
32
STRING Statement Used to Concatenate character strings together.
33
STRING Statement STRING Variable/Constant DELIMITED BY {Variable/Constant/SIZE) INTO variable END-STRING
34
STRING Statement Rules DELIMITED BY required Receiving field must be an elementary data (not a group item) element with no editing symbols All literals must be alphanumeric String moves data from left-right but doesnot pad with blanks
35
STRING Statement STRING first-name DELIMITED BY ‘ ‘ last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-namelast-namefull-name ‘Cindy ‘‘Laurin’
36
STRING Statement STRING first-name DELIMITED BY ‘ ‘ ‘ ‘ DELIMITED BY SIZE last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-namelast-namefull-name ‘Cindy ‘‘Laurin ‘
37
STRING Statement MOVE ‘XXXXXXXXXXXXXXXXXXXXXXXX’ TO full-name. STRING first-name DELIMITED BY ‘ ‘ ‘ ‘ DELIMITED BY SIZE last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-namelast-namefull-name ‘Cindy ‘‘Laurin ‘
38
We can concatenate strings together using the String Verb. Wouldn’t it be nice if we could parse a string into other strings?
39
UNSTRING Verb!! UNSTRING Variable DELIMITED BY Variable/Constant/SIZE INTO variable1 variable2 variable3 END-UNSTRING
40
UNSTRING 01 Name-In-Pieces. 05 Last-NamePIC X(16). 05 First-Name PIC X(10). 05 Middle-InitialPIC X. 01 Entire-NamePIC X(31) VALUE ‘Cindy M Laurin’. UNSTRING Entire-Name DELIMITED BY ‘ ‘ INTO First-Name Middle-Initial Last-Name.
41
UNSTRING 01 Name-In-Pieces. 05 Last-NamePIC X(16). 05 First-Name PIC X(10). 05 Middle-InitialPIC X. 01 Entire-NamePIC X(31) VALUE ‘Eddie Laurin’. UNSTRING Entire-Name DELIMITED BY ‘ ‘ INTO First-Name Middle-Initial Last-Name.
42
UNSTRING 01 Name-In-Pieces. 05 Last-NamePIC X(16). 05 First-Name PIC X(10). 05 Middle-InitialPIC X. 01 Entire-NamePIC X(31) VALUE ‘Cindy M Laurin-Moogk’ UNSTRING Entire-Name DELIMITED BY ‘ ‘ or ‘-’ INTO First-Name Middle-Initial Last-Name.
43
Substring(nn:nn) position, length 01 whole-name pic x(50). 01first-name pic x(25). move whole-name(1:25) to first-name starts at the first character of whole name and retrieves 25 characters
44
01 Student-Number PIC 9(9) Comp-3. We would like to print it as 999-999-999
45
The Long Way File-Section. 05 student-number pic 9(9) comp-3. Working-Storage. 01 student-number-unpacked pic 9(9). 01 Student-number-edited redefines student-number-unpacked.. 05 part1 pic 999. 05 part2 pic 999. 05 part3 pic 999. 01 detail-line. 05 prt-part1 pic 999. 05 pic X value ‘-’. 05 prt-part2 pic 999. 05 pic X value ‘-’. 05 prt-part3 pic 999.
46
Inspect Verb Used to replace one character or character string with another INSPECT variable REPLACING {ALL} {LEADING} var/lit by var/lit {FIRST}
47
Print Student Number with ‘-’ using Inspect File-Section. 05 student-number pic 9(9) comp-3. Working-Storage. 01 detail-line. 05 prt-student-number pic 999B999B999. Procedure Division. inspect prt-student-number replacing all ‘ ‘ by ‘-’.
48
Printing with Externally Described Printer Files New addition to the select statement – FORMATFILE! select report-file assign to formatfile-filename.
49
Writing to an Externally Described Printer File Write record-name format is ‘RECORD’ eop perform print-heading End-write. (eop means end of page)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.