Mainframe COBOL Tips & Tricks

24

Click here to load reader

description

Mainframe COBOL Tips & Tricks

Transcript of Mainframe COBOL Tips & Tricks

Page 1: Mainframe COBOL Tips & Tricks

COBOL TIPS AND TRICKSCOBOL TIPS AND TRICKS

Presented byPresented by

William D. KellyWilliam D. KellyUniversity of West FloridaUniversity of West Florida

Page 2: Mainframe COBOL Tips & Tricks

TopicsTopicsChecking a solution with ExcelChecking a solution with ExcelTop of page/summary problemTop of page/summary problemCreating an input/output screenCreating an input/output screenIntrinsic functionsIntrinsic functionsSequential file update using the balance Sequential file update using the balance line algorithmline algorithmCobol 2000 changesCobol 2000 changes

Page 3: Mainframe COBOL Tips & Tricks

Checking a Solution With Checking a Solution With ExcelExcel

You You knowknow the answer before you write the answer before you write oneone line of codeline of codeYou become acquainted with the dataYou become acquainted with the data

What What --if analysisif analysisPlan data validationPlan data validationRounding errorsRounding errors

You can explore appropriate algorithms You can explore appropriate algorithms to perform your calculationsto perform your calculations

Page 4: Mainframe COBOL Tips & Tricks

Data opened in ExcelData opened in Excel461378949 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

Page 5: Mainframe COBOL Tips & Tricks
Page 6: Mainframe COBOL Tips & Tricks

Top of page/Summary prob.Top of page/Summary prob.

http://www.mindspring.com/~proteus.ui/summary.html

The solution is on my web page at:

Page 7: Mainframe COBOL Tips & Tricks

I/O with the Screen SectionI/O with the Screen Section

Display/Accept to make COBOL Display/Accept to make COBOL InteractiveInteractiveSpecifying colors Specifying colors LevelLevel--7878Micro Focus Screens ProgramMicro Focus Screens ProgramLimitationsLimitations

Page 8: Mainframe COBOL Tips & Tricks

Sample COBOL CodeSample COBOL Code

Display “Type Password and press enter”Accept password-check

Procedure Division.……etc….. etc

Shows message on the screen

Placed entered text in a receiving field

Page 9: Mainframe COBOL Tips & Tricks

INTEGER COLOR

0 Black1 Blue2 Green3 Cyan4 Red5 Magenta6 Brown7 White8 Bright black (gray)9 Bright blue

10 Bright green11 Bright cyan12 Bright red13 Bright magenta14 Bright brown15 Bright white

Background and Foreground Colors

Page 10: Mainframe COBOL Tips & Tricks

Micro Focus Level 78Micro Focus Level 78

Micro Focus requires an integer tospecify 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

Page 11: Mainframe COBOL Tips & Tricks

Example of 78Example of 78--LevelLevelDATA 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 ONLY78 BRIGHT-MAGENTA VALUE 13.78 BRIGHT-BROWN VALUE 14.78 BRIGHT-WHITE VALUE 15.

Page 12: Mainframe COBOL Tips & Tricks

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)

Sample Screen

Page 13: Mainframe COBOL Tips & Tricks

SCREEN SECTION.01 OPENING-SCREEN.

05 BLANK-SCREENBACKGROUND-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-NOLINE 3 COLUMN 20 REVERSE-VIDEO.

10 SCR-LAST-NAME PIC X(15) USING REN-LAST-NAMELINE 7 COLUMN 9 REVERSE-VIDEO.

10 SCR-FIRST-NAME PIC X(10) USING REN-FIRST-NAMELINE 7 COLUMN 25 REVERSE-VIDEO.

10 SCR-INITIAL PIC X USING REN-INITIALLINE 7 COLUMN 36 REVERSE-VIDE0.

10 SCR-CAR-TYPE PIC X USING REN-CAR-TYPELINE 10 COLUMN 23 REVERSE-VIDEO

Page 14: Mainframe COBOL Tips & Tricks

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.

(Code Continued)

Page 15: Mainframe COBOL Tips & Tricks

Micro Focus “Screens” Micro Focus “Screens” PgmPgm..

Draw screen out naturallyDraw screen out naturallyAutomatically generate codeAutomatically generate codeGenerate skeleton Cobol programGenerate skeleton Cobol programUse copy statement to pull screen code Use copy statement to pull screen code into skeletoninto skeleton

Page 16: Mainframe COBOL Tips & Tricks

LimitationsLimitations

Multiple Simultaneous Transactions are Multiple Simultaneous Transactions are notnot possiblepossibleScreen Design isScreen Design is tedioustedious and Screen and Screen Generators are usedGenerators are usedNN--tired design would dictate using and tired design would dictate using and I/O program such as I/O program such as CICS CICS

Page 17: Mainframe COBOL Tips & Tricks

Intrinsic FunctionsIntrinsic Functions

Introduced in the 1989 enhanced Introduced in the 1989 enhanced version of COBOL 85version of COBOL 85Mathematical, Statistical, Alphanumeric, Mathematical, Statistical, Alphanumeric, and COBOL 2000 additionsand COBOL 2000 additionsFormat:Format:Function function-name-1 [({argument-1}…)]

MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE-AND-TIME.

Example:

Page 18: Mainframe COBOL Tips & Tricks

CURRENTCURRENT--DATEDATEReturns the current system date in YYYYMMDD formatReturns the current system date in YYYYMMDD format

WHENWHEN--COMPILEDCOMPILEDReturns the compile date in YYYYMMDD formatReturns the compile date in YYYYMMDD format

DATEDATE--OFOF--INTEGERINTEGERConverts YYYYMMDD to an integerConverts YYYYMMDD to an integer

DAYDAY--OFOF--INTEGERINTEGERConverts YYYYDDD to an integerConverts YYYYDDD to an integer

INTEGERINTEGER--OFOF--DATEDATEConverts an integer to YYYYMMDD formatConverts an integer to YYYYMMDD format

INTEGERINTEGER--OFOF--DAYDAYConverts an integer to YYYYDDD formatConverts an integer to YYYYDDD format

Calendar FunctionsCalendar Functions

Page 19: Mainframe COBOL Tips & Tricks

LongdateLongdate..cbl cbl revisitedrevisitedWindowingWindowingAssignment 5 with multiple calls for date Assignment 5 with multiple calls for date conversionconversion

Function and Date Conversion Function and Date Conversion ExamplesExamples

Page 20: Mainframe COBOL Tips & Tricks

Sequential File ProcessingSequential File Processing

The master file and the update file The master file and the update file mustmustbe in order according to a be in order according to a common keycommon key..Opening multiple master files for update Opening multiple master files for update dramaticallydramatically increases the complexity increases the complexity but the balance line algorithm can be but the balance line algorithm can be scaled.scaled.Sequential files are more easily Sequential files are more easily transferredtransferred to other types of computers. to other types of computers.

Page 21: Mainframe COBOL Tips & Tricks

Sequential File OverviewSequential File Overview

OLD MASTER

TRANSACTION

NEWMASTER

ERRORMESSAGES

UPDATEPROGRAM

Page 22: Mainframe COBOL Tips & Tricks

Open filesRead transaction-file, at end move high-values to transaction-keyRead old-master-file, at end move high-values to old-master-keyChoose first active-keyDO WHILE active-key not equal high-values

IF old-master-key = active-keyMove old-master-record to new-master-recordRead old-master-file, at end move high-values to old-master-key

ENDIFDO WHILE transaction-key = active-key

Apply transaction to new-master-recordRead transaction-file, at end move high-values to transaction-key

ENDDOIF no deletion was processed

Write new-master-recordENDIFChoose next active-key

ENDDOClose filesStop run

Balance Line Algorithm

Page 23: Mainframe COBOL Tips & Tricks

COBOL 85 vs. COBOL 2000COBOL 85 vs. COBOL 2000

Rigid coding Rigid coding columnscolumnsSome Object verbs Some Object verbs in upgraded in upgraded versionsversionsStatic Table size Static Table size according to occurs according to occurs clauseclause

Free format directiveFree format directiveFull Object Full Object ImplementationImplementationDynamic Tables Dynamic Tables

Page 24: Mainframe COBOL Tips & Tricks

Solve problems with Solve problems with excel before coding excel before coding Summary line problemSummary line problemCOBOL is interactiveCOBOL is interactiveUse appropriate Use appropriate algorithms and algorithms and functionsfunctionsCOBOL is not a static COBOL is not a static standardstandard

Conclusion