any questions? agenda level 77 initialize display & accept arithmetic verbs compute statement...
TRANSCRIPT
![Page 1: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/1.jpg)
Any Questions?
![Page 2: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/2.jpg)
Agenda
• Level 77
• Initialize
• Display & Accept
• Arithmetic Verbs
• Compute statement
• String/Unstring
• Inspect
![Page 3: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/3.jpg)
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).
![Page 4: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/4.jpg)
Initialize Verb01 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 Alpha2 PIC X(20) VALUE ‘FUN’.
INITIALIZE NUM1.
INITIALIZE ALPHA1 NUM2.
What happens?
![Page 5: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/5.jpg)
Initialize Verb01 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 Alpha2 PIC X(20) VALUE ‘FUN’.
INITIALIZE Group-Item-1.
What happens?
![Page 6: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/6.jpg)
Initialize Verb
INITIALIZE variable1 variable2 variable3 …
ALPHABETIC
REPLACING ALPHANUMERIC
NUMERIC
ALPHANUMERIC-EDITED
NUMERIC-EDITED
BY Variable4
literal-1
![Page 7: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/7.jpg)
Initialize Verb01 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 Alpha2 PIC X(20) VALUE ‘FUN’.
INITIALIZE Group-Item-1 REPLACING ALPHANUMERICS BY ‘X’
NUMERIC BY 9
What happens?
![Page 8: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/8.jpg)
Initialize Verb01 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 Alpha2 PIC X(20) VALUE ‘FUN’.
INITIALIZE Group-Item-1 REPLACING NUMERICS BY 100.
What happens?
![Page 9: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/9.jpg)
Display & Accept
• Fast Interactive Screens
• Use of message queue / command line
![Page 10: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/10.jpg)
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.
![Page 11: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/11.jpg)
ACCEPT
ACCEPT variable1
AT LINE 99 COLUMN 99.
Examples:
DISPLAY ‘Press Enter to Continue’.
ACCEPT ENTER-VARIABLE.
![Page 12: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/12.jpg)
Arithmetic Verbs
Add, Subtract, Multiply, Divide
And Compute
![Page 13: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/13.jpg)
Add Verb
• Three Formats:
ADD variable/constant TO variable
ADD variable/constant, variable/constant, … GIVING variable
ADD variable/constant TO variable/constant GIVING variable
![Page 14: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/14.jpg)
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)?
![Page 15: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/15.jpg)
SUBTRACT Verb
• Two Formats:
SUBTRACT Variable/Constant Variable/Constant ... FROM Variable
SUBTRACT Variable/Constant Variable/Constant … FROM Variable
GIVING Variable
![Page 16: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/16.jpg)
SUBTRACT Statement
A = 100 B = 50 C = 150 D = 200
SUBTRACT A B FROM C
A = B = C = D =
SUBTRACT A B FROM C GIVING D
A = B = C = D =
![Page 17: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/17.jpg)
MULTIPLY Statement
• More restrictive
• Two Formats
MULTIPLY variable/constant BY variable
MULTIPLY variable/constant
BY variable/constant
GIVING variable
![Page 18: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/18.jpg)
MULTIPLY Statement
A = 50 B = 100 C = 20
MULTIPLY A BY B
A = B = C =
MULTIPLY A BY B GIVING C
A = B = C =
![Page 19: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/19.jpg)
DIVIDE StatementMore 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
![Page 20: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/20.jpg)
DIVIDE Statement
A = 100 B = 50 C = 25
DIVIDE A INTO B
A = B = C =
DIVIDE A BY B GIVING C
A = B = C =
![Page 21: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/21.jpg)
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!
![Page 22: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/22.jpg)
REMAINDER Clause
A = 100 B = 150 C = 20 D = 10
DIVIDE A INTO B GIVING C REMAINDER D.
A = B = C = D =
![Page 23: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/23.jpg)
Clauses that work with all arithmetic statements.
ROUNDED
ON SIZE ERROR
![Page 24: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/24.jpg)
Rounding
• Add the ROUNDED option to the math statement directly following the resulting field
• Eg. DIVIDE A INTO B GIVING C ROUNDED.
![Page 25: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/25.jpg)
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.
![Page 26: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/26.jpg)
Compute Statement
Combines all of the math verbs plus exponentiation
![Page 27: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/27.jpg)
Compute Statement Symbols
Symbol Meaning
+ ADD
- SUBTRACT
* MULTIPLY
/ DIVIDE
** exponentiation
![Page 28: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/28.jpg)
Order of Operations
• Operations in brackets ( ) are performed first
• ** (exponentiation)
• * or / (from left to right)
• + or - (from left to right)
![Page 29: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/29.jpg)
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?
![Page 30: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/30.jpg)
73
![Page 31: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/31.jpg)
STRING Statement
Used to Concatenate character strings together.
![Page 32: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/32.jpg)
STRING Statement
STRING
Variable/Constant DELIMITED BY {Variable/Constant/SIZE)
INTO variable
END-STRING
![Page 33: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/33.jpg)
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
![Page 34: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/34.jpg)
STRING Statement
STRING first-name DELIMITED BY ‘ ‘
last-name DELIMITED BY ‘ ‘
INTO full-name
END-STRING
first-name last-name full-name
‘Cindy ‘ ‘Laurin’
![Page 35: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/35.jpg)
STRING Statement
STRING first-name DELIMITED BY ‘ ‘
‘ ‘ DELIMITED BY SIZE
last-name DELIMITED BY ‘ ‘
INTO full-name
END-STRING
first-name last-name full-name
‘Cindy ‘ ‘Laurin ‘
![Page 36: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/36.jpg)
STRING StatementMOVE ‘XXXXXXXXXXXXXXXXXXXXXXXX’
TO full-name.
STRING first-name DELIMITED BY ‘ ‘
‘ ‘ DELIMITED BY SIZE
last-name DELIMITED BY ‘ ‘
INTO full-name
END-STRING
first-name last-name full-name
‘Cindy ‘ ‘Laurin ‘
![Page 37: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/37.jpg)
We can concatenate strings together using the String Verb.
Wouldn’t it be nice if we could parse a string into other strings?
![Page 38: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/38.jpg)
UNSTRING Verb!!
UNSTRING
Variable DELIMITED BYVariable/Constant/SIZE
INTO variable1 variable2 variable3
END-UNSTRING
![Page 39: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/39.jpg)
UNSTRING01 Name-In-Pieces.
05 Last-Name PIC X(16).
05 First-Name PIC X(10).
05 Middle-Initial PIC X.
01 Entire-Name PIC X(31)
VALUE ‘Cindy M Laurin’.
UNSTRING Entire-Name DELIMITED BY ‘ ‘
INTO First-Name Middle-Initial Last-Name.
![Page 40: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/40.jpg)
UNSTRING01 Name-In-Pieces.
05 Last-Name PIC X(16).05 First-Name PIC X(10).05 Middle-Initial PIC X.
01 Entire-Name PIC X(31)VALUE ‘Eddie Laurin’.
UNSTRING Entire-Name DELIMITED BY ‘ ‘INTO First-Name Middle-Initial Last-Name.
![Page 41: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/41.jpg)
UNSTRING01 Name-In-Pieces.
05 Last-Name PIC X(16).05 First-Name PIC X(10).05 Middle-Initial PIC X.
01 Entire-Name PIC X(31)VALUE ‘Cindy M Laurin-Moogk’
UNSTRING Entire-Name DELIMITED BY ‘ ‘ or ‘-’INTO First-Name Middle-Initial Last-Name.
![Page 42: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/42.jpg)
Substring(nn:nn)position, length
01 whole-name pic x(50).
01 first-name pic x(25).
move whole-name(1:25) to first-name
starts at the first character of whole name and retrieves 25 characters
![Page 43: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/43.jpg)
01 Student-Number PIC 9(9) Comp-3.
We would like to print it as
999-999-999
![Page 44: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/44.jpg)
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.
![Page 45: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/45.jpg)
Inspect Verb
• Used to replace one character or character string with another
INSPECT variable REPLACING
{ALL}
{LEADING} var/lit by var/lit
{FIRST}
![Page 46: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/46.jpg)
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 ‘-’.
![Page 47: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/47.jpg)
Printing with Externally Described Printer Files
• New addition to the select statement – FORMATFILE!
select report-file
assign to formatfile-filename.
![Page 48: Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect](https://reader036.vdocuments.mx/reader036/viewer/2022062804/5697bf881a28abf838c89663/html5/thumbnails/48.jpg)
Writing to an Externally Described Printer File
Write record-name
format is ‘RECORD’
eop perform print-heading
End-write.
(eop means end of page)