KEMBAR78
Cobol Tips | PDF | Magenta | Color
0% found this document useful (0 votes)
111 views24 pages

Cobol Tips

The document provides tips and tricks for COBOL programming, including checking solutions in Excel first, creating interactive input/output screens, using intrinsic functions, and processing sequential files using the balance line algorithm. It also discusses topics like the top of page problem, Micro Focus screen programming, and changes between COBOL 85 and COBOL 2000.

Uploaded by

PaoloR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views24 pages

Cobol Tips

The document provides tips and tricks for COBOL programming, including checking solutions in Excel first, creating interactive input/output screens, using intrinsic functions, and processing sequential files using the balance line algorithm. It also discusses topics like the top of page problem, Micro Focus screen programming, and changes between COBOL 85 and COBOL 2000.

Uploaded by

PaoloR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

COBOL TIPS AND TRICKS

Presented by
William D. Kelly
University of West Florida
Topics
„ Checking a solution with Excel
„ Top of page/summary problem
„ Creating an input/output screen
„ Intrinsic functions
„ Sequential file update using the balance
line algorithm
„ Cobol 2000 changes
Checking a Solution With
Excel
„ You know the answer before you write
one line of code
„ You become acquainted with the data
„ What -if analysis
„ Plan data validation
„ Rounding errors
„ You can explore appropriate algorithms
to perform your calculations
Data opened in Excel
461378949 ALFEO ANTONIO G 25 640 80 OK

422234123 AVERYT DINA S $$$ 2 1400 ERROR: ANNUAL LEAVE

265573404 CHILDRESS BRETT B 0 ### 2800 ERROR: SICK LEAVE

594134589 DANG HANH T 28 12 500 OK

85678816 DIFABIO DAVID L 66 1 1196 OK

262557959 EASLEY JOHN H 15 6 1380 OK

321478965 GOUTIS GEORGIOS X ZZZ 86 1800 ERROR: ANNUAL LEAVE

231672342 HAMILTON LAWRENCE B 78 56 2000 OK

265237893 HAUK HEATHER M 69 47 1300 OK

267836270 HUTTON ROBERT E 16 &&& 2000 ERROR SICK LEAVE


Top of page/Summary prob.

The solution is on my web page at:

http://www.mindspring.com/~proteus.ui/summary.html
I/O with the Screen Section
„ Display/Accept to make COBOL
Interactive
„ Specifying colors
„ Level-78
„ Micro Focus Screens Program
„ Limitations
Sample COBOL Code
Procedure Division.
……etc
….. etc

Display “Type Password and press enter”


Accept password-check

Placed entered text in a receiving field

Shows message on the screen


Background and Foreground Colors
INTEGER COLOR

0 Black
1 Blue
2 Green
3 Cyan
4 Red
5 Magenta
6 Brown
7 White
8 Bright black (gray)
9 Bright blue
10 Bright green
11 Bright cyan
12 Bright red
13 Bright magenta
14 Bright brown
15 Bright white
Micro Focus Level 78

Micro Focus requires an integer to


specify the foreground and
background colors. To avoid the
confusion of remembering the
color numbers, Micro Focus
introduced the 78 level (similar to
the 88 level) . The 78-level allows
you to define and name a constant
value
Example of 78-Level
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SCREEN-COLORS PIC S9(4) COMP-5.
* COLORS FOR FOREGROUND AND BACKGROUND
78 BLACK VALUE 0.
78 BLUE VALUE 1.
78 GREEN VALUE 2.
78 CYAN VALUE 3.
* COLORS FOR THE FOREGROUND ONLY
78 BRIGHT-MAGENTA VALUE 13.
78 BRIGHT-BROWN VALUE 14.
78 BRIGHT-WHITE VALUE 15.
Sample Screen
Monica’s Car Rental Company 04/14/99

Contract No:
Customer Information:
Last Name First Initial

Car Information:
Type Code: (Compact, Economy, Midsize, Fullsize, Luxury)
Date Returned:
Days Rented:
Mileage:
Miles In:
Miles Out: Mileage Rate:
Insurance: (Y/N)
Above information correct?
(Y - yes, N - No)
SCREEN SECTION.
01 OPENING-SCREEN.
05 BLANK-SCREEN
BACKGROUND-COLOR BLUE FOREGROUND-COLOR WHITE.
05 SCREEN-PROMPTS.
.
.
10 LINE 3 COLUMN 7 VALUE ‘Contract No:’.
10 LINE 5 COLUMN 7 VALUE ‘Customer Information:’.
10 LINE 6 COLUMN 9 VALUE ‘Last Name’.
10 COLUMN 25 VALUE ‘First’.
10 COLUMN 36 VALUE ‘Initial’.
10 LINE 9 COLUMN 6 VALUE ‘Car Information:’
10 LINE 10 COLUMN 12 VALUE ‘Type Code:’.
.
.
05 SCREEN-INPUTS.
10 SCR-CONTRACT-NO PIC 9(6) USING REN-CONTRACT-NO
LINE 3 COLUMN 20 REVERSE-VIDEO.
10 SCR-LAST-NAME PIC X(15) USING REN-LAST-NAME
LINE 7 COLUMN 9 REVERSE-VIDEO.
10 SCR-FIRST-NAME PIC X(10) USING REN-FIRST-NAME
LINE 7 COLUMN 25 REVERSE-VIDEO.
10 SCR-INITIAL PIC X USING REN-INITIAL
LINE 7 COLUMN 36 REVERSE-VIDE0.
10 SCR-CAR-TYPE PIC X USING REN-CAR-TYPE
LINE 10 COLUMN 23 REVERSE-VIDEO
(Code Continued)
01 UPDATE-SCREEN.
05 LINE 11 COLUMN 67 VALUE ‘Totals’ HIGHLIGHT.
05 LINE 12 COLUMN 38 VALUE ‘Rental Rate:’ HIGHLIGHT.
05 UPD-DAILY-RATE PIC $$$9.99 FROM IND-DAILY-RATE
LINE 12 COLUMN 50 HIGHLIGHT.
05 UPD-DAILY-TOTAL PIC $$$,$$9.99 FROM IND-DAILY-TOTAL
COLUMN 63 HIGHLIGHT.
05 LINE 14 COLUMN 37 VALUE ‘Miles Driven:’ HIGHLIGHT.
05 UPD-MILES-DRIVEN PIC ZZZ,ZZ9 FROM IND-MILES-DRIVEN
COLUMN 50 HIGHLIGHT.
05 UPD-MILEAGE-TOTAL PIC $$,$$9.99 FROM IND-MILEAGE-TOTAL
LINE 15 COLUMN 51 HIGHLIGHT.
05 LINE 16 COLUMN 35 VALUE ‘Insurance Rate:’ HIGHLIGHT.
05 UPD-INSURANCE-RATE PIC $$9.99 FROM INSURANCE-RATE
LINE 16 COLUMN 51 HIGHLIGHT.
05 UPD-INSURANCE-TOTAL PIC $$,$$9.99 FROM IND-INSURANCE-TOTAL
COLUMN 64 HIGHLIGHT.
05 LINE 17 COLUMN 63 VALUE ‘----------’ HIGHLIGHT.
05 LINE 18 COLUMN 48 VALUE ‘Amount Due: ‘ HIGHLIGHT.
05 UPD-AMOUNT-DUE PIC $$$$,$$9.99 FROM IND-AMOUNT-DUE
COLUMN 62 HIGHLIGHT.
Micro Focus “Screens” Pgm.
„ Draw screen out naturally
„ Automatically generate code
„ Generate skeleton Cobol program
„ Use copy statement to pull screen code
into skeleton
Limitations
„ Multiple Simultaneous Transactions are
not possible
„ Screen Design is tedious and Screen
Generators are used
„ N-tired design would dictate using and
I/O program such as CICS
Intrinsic Functions
„ Introduced in the 1989 enhanced
version of COBOL 85
„ Mathematical, Statistical, Alphanumeric,
and COBOL 2000 additions
„ Format:
Function function-name-1 [({argument-1}…)]
Example:
MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE-AND-TIME.
Calendar Functions
„ CURRENT-DATE
„ Returns the current system date in YYYYMMDD format
„ WHEN-COMPILED
„ Returns the compile date in YYYYMMDD format
„ DATE-OF-INTEGER
„ Converts YYYYMMDD to an integer
„ DAY-OF-INTEGER
„ Converts YYYYDDD to an integer
„ INTEGER-OF-DATE
„ Converts an integer to YYYYMMDD format
„ INTEGER-OF-DAY
„ Converts an integer to YYYYDDD format
Function and Date Conversion
Examples
„ Longdate.cbl revisited
„ Windowing
„ Assignment 5 with multiple calls for date
conversion
Sequential File Processing
„ The master file and the update file must
be in order according to a common key.
„ Opening multiple master files for update
dramatically increases the complexity
but the balance line algorithm can be
scaled.
„ Sequential files are more easily
transferred to other types of computers.
Sequential File Overview

OLD NEW
MASTER MASTER

UPDATE
PROGRAM

ERROR
TRANSACTION
MESSAGES
Balance Line Algorithm
Open files
Read transaction-file, at end move high-values to transaction-key
Read old-master-file, at end move high-values to old-master-key
Choose first active-key
DO WHILE active-key not equal high-values
IF old-master-key = active-key
Move old-master-record to new-master-record
Read old-master-file, at end move high-values to old-master-key
ENDIF
DO WHILE transaction-key = active-key
Apply transaction to new-master-record
Read transaction-file, at end move high-values to transaction-key
ENDDO
IF no deletion was processed
Write new-master-record
ENDIF
Choose next active-key
ENDDO
Close files
Stop run
COBOL 85 vs. COBOL 2000
„ Rigid coding „ Free format directive
columns „ Full Object
„ Some Object verbs Implementation
in upgraded „ Dynamic Tables
versions
„ Static Table size
according to occurs
clause
„ Solve problems with
excel before coding
Conclusion
„ Summary line problem
„ COBOL is interactive
„ Use appropriate
algorithms and
functions
„ COBOL is not a static
standard

You might also like