You are on page 1of 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

422234123 AVERYT
265573404 CHILDRESS

ANTONIO G
DINA

BRETT

25

640

80

OK

$$$

1400

ERROR: ANNUAL LEAVE

###

2800

ERROR: SICK LEAVE

594134589 DANG

HANH

28

12

500

OK

85678816

DIFABIO

DAVID

66

1196

OK

262557959 EASLEY

JOHN

15

1380

OK

321478965 GOUTIS

GEORGIOS X

ZZZ

86

1800

ERROR: ANNUAL LEAVE

56

2000

OK

231672342 HAMILTON
265237893 HAUK
267836270 HUTTON

LAWRENCE B 78
HEATHER M

69

47

1300

OK

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
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

COLOR
Black
Blue
Green
Cyan
Red
Magenta
Brown
White
Bright black (gray)
Bright blue
Bright green
Bright cyan
Bright red
Bright magenta
Bright brown
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
Monicas Car Rental Company

04/14/99

Contract No:
Customer Information:
Last Name
First

Car Information:
Type Code:
Date Returned:
Days Rented:
Mileage:
Miles In:
Miles Out:
Insurance:

Initial

(Compact, Economy, Midsize, Fullsize, Luxury)

Mileage Rate:
(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
LINE 3 COLUMN
10 SCR-LAST-NAME
LINE 7 COLUMN
10 SCR-FIRST-NAME
LINE 7 COLUMN
10 SCR-INITIAL
LINE 7 COLUMN
10 SCR-CAR-TYPE
LINE 10 COLUMN

PIC 9(6) USING REN-CONTRACT-NO


20 REVERSE-VIDEO.
PIC X(15) USING REN-LAST-NAME
9 REVERSE-VIDEO.
PIC X(10) USING REN-FIRST-NAME
25 REVERSE-VIDEO.
PIC X
USING REN-INITIAL
36 REVERSE-VIDE0.
PIC X
USING REN-CAR-TYPE
23 REVERSE-VIDEO

(Code Continued)
01

UPDATE-SCREEN.
05 LINE 11 COLUMN 67
05 LINE 12 COLUMN 38
05 UPD-DAILY-RATE
LINE 12 COLUMN 50
05 UPD-DAILY-TOTAL
COLUMN 63
05 LINE 14 COLUMN 37
05 UPD-MILES-DRIVEN
COLUMN 50
05 UPD-MILEAGE-TOTAL
LINE 15 COLUMN 51
05 LINE 16 COLUMN 35
05 UPD-INSURANCE-RATE
LINE 16 COLUMN 51
05 UPD-INSURANCE-TOTAL
COLUMN 64
05 LINE 17 COLUMN 63
05 LINE 18 COLUMN 48
05 UPD-AMOUNT-DUE
COLUMN 62

VALUE Totals HIGHLIGHT.


VALUE Rental Rate: HIGHLIGHT.
PIC $$$9.99 FROM IND-DAILY-RATE
HIGHLIGHT.
PIC $$$,$$9.99 FROM IND-DAILY-TOTAL
HIGHLIGHT.
VALUE Miles Driven: HIGHLIGHT.
PIC ZZZ,ZZ9 FROM IND-MILES-DRIVEN
HIGHLIGHT.
PIC $$,$$9.99 FROM IND-MILEAGE-TOTAL
HIGHLIGHT.
VALUE Insurance Rate: HIGHLIGHT.
PIC $$9.99 FROM INSURANCE-RATE
HIGHLIGHT.
PIC $$,$$9.99 FROM IND-INSURANCE-TOTAL
HIGHLIGHT.
VALUE ---------- HIGHLIGHT.
VALUE Amount Due: HIGHLIGHT.
PIC $$$$,$$9.99 FROM IND-AMOUNT-DUE
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
MASTER

NEW
MASTER

UPDATE
PROGRAM

TRANSACTION

ERROR
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
columns
Some Object verbs
in upgraded
versions
Static Table size
according to occurs
clause

Free format directive


Full Object
Implementation
Dynamic Tables

Conclusion

Solve problems with


excel before coding
Summary line problem
COBOL is interactive
Use appropriate
algorithms and
functions
COBOL is not a static
standard

You might also like