workshop 1 – create your first cobol program, … · web viewworkshop 1 – create your first...

33
Workshops – Module3 Basic COBOL Statements Workshop 1 – Create an Example Program Using Snippets Purpose of this workshop: After finishing this workshop you will be able to create a COBOL program that: Exercises all of the major COBOL datatypes Demonstrates all of the MOVE statement format options Displays results in the Debugger Pre-requisites: Product installed Education verification completed Sections on RDz COBOL editor and RDz Workbench completed @ Copyright 2009, International Business Machine - 1

Upload: others

Post on 30-Jun-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Workshop 1 – Create an Example Program Using Snippets

Purpose of this workshop:

After finishing this workshop you will be able to create a COBOL program that: Exercises all of the major COBOL datatypes Demonstrates all of the MOVE statement format options Displays results in the Debugger

Pre-requisites:

Product installed

Education verification completed

Sections on RDz COBOL editor and RDz Workbench completed

@ Copyright 2009, International Business Machine - 1

Page 2: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create a new Project for the samples in this Unit

Steps Launch Rational Developer for System z From the menu:

o Click Fileo New > Other

From the New Select a Wizard dialog:o Type: localo Select: Local Project

Under Workstation COBOL or PL/I Click: Next >

Enter the name of the Project: chapter3 Check the property group: COBOL Sample Property Group

Click FinishThis will create a new project for you in your workspace. For the remaining exercises in this section you will add COBOL programs to this project

Create a new cobol folder for the samples in this Unit

Steps From the z/OS Projects explorer:

o Select your new chapter3 projecto Right-click and select:

New > Foldero Name the folder: cobol

@ Copyright 2009, International Business Machine - 2

Page 3: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Debug an Example COBOL Program

Steps Expand the chapter3 project Right-click over the \cobol\ folder and select:

o New > Fileo Name the file: VARPGM.cbl

Make sure the Snippets View is open With your cursor in column1 of the file, Double-Click the Data Representation and Move

Statements Snippet Fill in as follows:

o Program-ID: VARPGMo Author: Your Name

After the code is copied in from the snippet: Set your cursor inside the file in a blank area. Type another blank and press Ctrl/S – to save your new program

Briefly study the code in VARPGM – note the following: Assortment of variables with different datatypes MOVE statements that show different formats and options for value assignment

@ Copyright 2009, International Business Machine - 3

Page 4: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Build your example COBOL program

Syntax Check your Program When finished, all of the above editing, Right-Click over your COBOL code in the editor From the context menu, select: Save and Syntax Check

o If you have any syntax errors they will appear as small red circles in the COBOL margin, and in the Remote Error List.

o Fix all of the syntax errors before continuingBuild your Project

From z/OS Projects: Select your program: VARPGM.cbl Right-click, and from the context menu select: Nominate as Entry Point Right-click over the project (chapter3) and select: Rebuild Project

Debug your ProgramFrom Project Explorer: Expand the BuildOutput folder Select your program executable: VARPGM.exe Right-click, and from the context menu select:

o Debug As… Debug Configurations

From the Debug Configurations window type (or Browse to) the fully-qualified name of your executable program: VARPGM.exe

Press Debug (if you are prompted to enter the Debug Perspective, select Yes)

@ Copyright 2009, International Business Machine - 4

Page 5: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Discover the COBOL Data Types and Assignment Statement Semantics Expand all of the variables

Click the Step Over (F6) icon – this will execute one instruction at a time in your program

@ Copyright 2009, International Business Machine - 5

Page 6: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

As you debug your program note carefully the effect each value assignment (MOVE) statement has on the Variables

Continue to Debug and watch the assignments – and be sure to recall and associate the COBOL data representation and MOVE syntax you studied in this section – mapping to the run-time behavior exposed through the debugger

@ Copyright 2009, International Business Machine - 6

Page 7: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements When you get to the MOVE CORRESPONDING statements you will have to open and

expose different variable values, in order to understand the effect of these statements

When you have finished debugging, click the Terminate icon

and return to the z/OS Projects perspective (top right-hand corner of your Workbench)

Close VARPGM.cbl in the editor

@ Copyright 2009, International Business Machine - 7

Page 8: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Apply and Master Data Representation and MOVE Statements

You will create a new program that processes insurance policy information. Here are the specifications:o Create a new program named: policy.cblo Use the Snippet named: Program Template

In the WORKING-STORAGE Section Create a Policy Record as an 01 level field Create the following structure as 05 and 10 level variables:

o InsuredName LastName - character 20 FirstName - character 20

o PolicyEffectiveDate - numeric 8o PolicyAmount – input field, decimal numeric values, large enough to hold: 99999.99o PolicyType – character 20

Valid Types: Life Health Property/Casualty Auto

Create an output 01 record with edited output fields for the above. Use appropriate output datatypes for the fields

Name the output fields the same as the input fields (except for the 01 record – which should be named something like: Policy-out

@ Copyright 2009, International Business Machine - 8

Page 9: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements In the Procedure Division

o In the 000-HOUSEKEEPING paragraph Use MOVE statements to assign values to the Policy record

o In the 200-MAINLINE paragraph MOVE the corresponding input fields to the output field in one statement

Debug your program:o Save your changes and Syntax Check

Clean up any/all syntax errorso From z/OS Project explorer

Nominate policy.cbl as the entry point in the application Rebuild the chapter3 project Debug policy.exe

o From the Debug view Step through each statement Verify your logic

@ Copyright 2009, International Business Machine - 9

Page 10: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Workshop 2 – Create and Debug a Program with COBOL Math

Purpose of this workshop:

After finishing this workshop you will be able to create a COBOL program that: Exercises all of the major COBOL Math statements, including:

o Addo Subtracto Multiplyo Divideo Compute

Demonstrates the different arithmetic precision options:o Rounded

Pre-requisites:

Product installed

Education verification completed

Sections on RDz COBOL editor and RDz Workbench completed

@ Copyright 2009, International Business Machine - 10

Page 11: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create and Debug an Example COBOL Program

Steps Expand the chapter3 project Right-click over the \cobol\ folder and select:

o New > Fileo Name the file: calc.cbl

Make sure the Snippets View is open With your cursor in column1 of the file, Double-Click the Data Representation and Move

Statements Snippet Fill in as follows:

o programName: calco authorName: Your Name

In the WORKING-STORAGE SECTION – create the following records (01 levels and all elementary dataitems), as shown below

o Calc-Fieldso temp-convertero simple-interest

Note that the capitalization is your call…..

@ Copyright 2009, International Business Machine - 11

Page 12: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create the Procedure Division In the Procedure Division, add all of the statements as shown below – that demonstrate

COBOL arithmetic:

o MOVEo ADDo SUBTRACTo MULTIPLYo DIVIDEo COMPUTE

@ Copyright 2009, International Business Machine - 12

Page 13: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Build your example COBOL program

Syntax Check your Program When finished, all of the above editing, Right-Click over your COBOL code in the editor From the context menu, select: Save and Syntax Check

o If you have any syntax errors they will appear as small red circles in the COBOL margin, and in the Remote Error List.

o Fix all of the syntax errors before continuingBuild your Project

From Project Explorer: Select your program: calc.cbl Right-click, and from the context menu select: Nominate as Entry Point Right-click over the project (chapter1) and select: Rebuild Project

Debug your ProgramFrom Project Explorer: Expand the BuildOutput folder Select your program executable: calc.exe Right-click, and from the context menu select:

o Debug As… Debug Configurations

From the Debug Configurations window type (or Browse to) the fully-qualified name of your executable program: calc.exe

Press Debug (if you are prompted to enter the Debug Perspective, select Yes)

Debug through all of the code in the program – making sure that all of your code works and is arithmetically – along with syntactically – correct

When you are finished remember to Terminate your debug session, and return to the z/OS Projects perspective

@ Copyright 2009, International Business Machine - 13

Page 14: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Workshop 3 – Create and Debug a Program Conditional Logic

Purpose of this workshop:

After finishing this workshop you will be able to create a COBOL program that: Exercises all of the major COBOL conditional statements, including:

o IF Complex Different types of IF

o EVALUATEo Demonstrates the use of the Debugger to test complex structures

Pre-requisites:

Product installed

Education verification completed

Sections on RDz COBOL editor and RDz Workbench completed

@ Copyright 2009, International Business Machine - 14

Page 15: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create and Debug an Example COBOL Program

Steps Expand the chapter3 project Right-click over the \cobol\ folder and select:

o New > Fileo Name the file: conditional.cbl

Make sure the Snippets View is open With your cursor in column1 of the file, Double-Click the Data Representation and Move

Statements Snippet Fill in as follows:

o programName: conditionalo authorName: Your Name

In the WORKING-STORAGE SECTION – create the following 77 and 88 elementary items as shown:

o ITEM-1o ITEM-2o ITEM-3

VALID-ITEMo ITEM-No Marital-codeo People-count

Note that the capitalization is your call…..

@ Copyright 2009, International Business Machine - 15

Page 16: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create the Procedure Division The Procedure Division is very lengthy – so code at least some of the statements that

demonstrate the types of conditional logic found in COBOL production applications

Note…. Your code is continued on the next slide

@ Copyright 2009, International Business Machine - 16

Page 17: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Final set of statements to enter in the PROCEDURE DIVISION

@ Copyright 2009, International Business Machine - 17

Page 18: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL StatementsBuild and Test your example COBOL program

Syntax Check your Program When finished, all of the above editing, Right-Click over your COBOL code in the editor From the context menu, select: Save and Syntax Check

o If you have any syntax errors they will appear as small red circles in the COBOL margin, and in the Remote Error List.

o Fix all of the syntax errors before continuingBuild your Project

From Project Explorer: Select your program: conditional.cbl Right-click, and from the context menu select: Nominate as Entry Point Right-click over the project (chapter1) and select: Rebuild Project

Debug your ProgramFrom Project Explorer: Expand the BuildOutput folder Select your program executable: conditional.exe Right-click, and from the context menu select:

o Debug As… Debug Configurations

From the Debug Configurations window type (or Browse to) the fully-qualified name of your executable program: conditional.exe

Press Debug (if you are prompted to enter the Debug Perspective, select Yes)

Debug through all of the code in the program – making sure that all of your code works and is conditionally – along with syntactically – correct

Most importantly – make sure you can follow all of the IF/ELSE patterns in the code – and be able to explain why the code execution took one path versus another

@ Copyright 2009, International Business Machine - 18

Page 19: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create and Debug a Sequential File Processing COBOL Program

Steps Expand the chapter3 project Right-click over the \cobol\ folder and select:

o New > Fileo Name the file: seqfileproc1.cbl

Make sure the Snippets View is open With your cursor in column1 of the file, Double-Click the Sequential File Processing –

Example 1 Snippet Fill in as follows:

o programName: seqfileproc1o authorName: Your Name

Start by studying this code – as you did on the course slides, o First getting the big picture of the file-processing paragraphs tied together by performso Understand the semantic concepts of what’s in the paragraphs (get an “outline view”)o Then study the line-by-line code for understanding

o SELECT/ASSIGN – and their associated FDo The purpose of the WORKING-STORAE records, counters and accumulatorso Each of the paragraphs in the PROCEDURE DIVISION – what’s coded in

them, and why it’s coded the way it is

@ Copyright 2009, International Business Machine - 19

Page 20: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Create the input file

Steps:

Select the following lines, and copy them to your Windows buffer

11111Smith Joanne 2016521111I000112/12/20050001123010HMO01201234567822222Martin Ricky 2124441212O000210/01/19520012345623GOV00600123142133333Jones James 2025551212I000311/23/20040000873547HMO02007123232144444McAllisterBillieJoe 8762341234I023409/23/20080234323483GOV01104532132155555Luthor Lex 7645234324I098412/31/2008043435674600000000012378666666Barnum P.T. 7854354354O078321/09/20060000432439HMO02507017632177777Clampett E.M. 5464432432I001308/12/20050002342138GOV03000453617988888Watson Thomas 2127643483O002207/25/2005001211232900001000354632199999Hamilton Alex 9098883213I000206/30/20060002323483HMO02000004757400000Welch John 2036520980O000105/31/20070001123245GOV04009781214388888Bad Pat. Type X GOV99999Bad Ins. Type O XXX

From the Start Menu, save these lines in a Notepad file, named: c:\datain.dat

Note: - not a text file, you will have to save as (*) All files

After you’ve saved, your file should look like this – from My Computer:

@ Copyright 2009, International Business Machine - 20

Page 21: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Build and test the program

Syntax Check your Program When finished, all of the above editing, Right-Click over your COBOL code in the editor From the context menu, select: Save and Syntax Check

o If you have any syntax errors they will appear as small red circles in the COBOL margin, and in the Remote Error List.

o Fix all of the syntax errors before continuing

Build your ProjectFrom Project Explorer: Select your program: seqfileproc1.cbl Right-click, and from the context menu select: Nominate as Entry Point Right-click over the project (chapter1) and select: Rebuild Project

Debug your ProgramFrom Project Explorer: Expand the BuildOutput folder Select your program executable: seqfileproc1.exe Right-click, and from the context menu select:

o Debug As… Debug Configurations

From the Debug Configurations window type (or Browse to) the fully-qualified name of your executable program: seqfileproc1.exe

Press Debug (if you are prompted to enter the Debug Perspective, select Yes)

Debug through all of the code in the program. Verify your desk-checking view of the program logic.

Note that you may wish to Run to break-points, as there is some amount of repetition in this (and all Batch processing) programs

When you are finished remember to Terminate your debug session, and return to the z/OS Projects perspective

@ Copyright 2009, International Business Machine - 21

Page 22: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements

Enhance the Program

It is a common requirement to modify, enhance, maintain and support production COBOL programs (more common in fact than creating new programs from scratch). So we might as well learn how this works – and some best practices and keys to success.

Do the following – after you’ve made each code modification: When finished, all of the above editing, Right-Click over your COBOL code in the editor From the context menu, select: Save and Syntax Check Debug to verify your work

Enhancements to the seqfileproc1.cbl:1. Make the READ routine a performed paragraph.

Note that the COBOL statements that read the input file is repeated in three different places in the program. o Create a paragraph that contains the statementso Perform that paragraph from the three original spotso Test your changes

2. Edit for bad numeric data Production programs do not assume valid input values (especially in online

applications, but even in batch processing mode)o Create a new error-flag in Working-Storageo Create a paragraph that edits each of the numeric fields in

WS-INPUT-REC for valid numeric valueso If you find an error set your new error-flag on

Typically this would be something along the lines of MOVE “Y” to ERROR-FLAG-WS

o At the beginning of 100-MAINLINE – perform your new paragrapho If you find an error in the data, follow the kind of processing logic in

the IF VALID-TYPE statement – to add to the error count, re-read the input file, and skip past the rest of the 100-MAINLINE statements

Note that you will have to modify some of the test data values in: c:\datain.dat – to create bad numeric values in order to test your logic

@ Copyright 2009, International Business Machine - 22

Page 23: Workshop 1 – Create your first COBOL program, … · Web viewWorkshop 1 – Create your first COBOL program, using Snippets Author jsayles Last modified by odbc Created Date 2/7/2010

Workshops – Module3 Basic COBOL Statements3. Test for empty input file

Copy c:\datain.dat – to some other file for backup Delete all records in c:\datain.dat Run your program, and ensure that it behaves correctly. If it does not

(hint/hint – when it does not) add logic to the program to handle an empty file

When you’re satisfied with your work, copy the files back to their original state (not-empty)

4. Average the final totals Add an inline perform in the 200-CLEANUP paragraph that calculates

the average Total Patient Net amount for all good (non-error) input records read

Modify WS-TOTALS-REC – and add the new value to your final output record

5. Add a new file for error output records Many production programs write error records to a separate output

file. In our case, we’ll simply write the original input record to an output file.

Add a new:o Select/Assign for an error fileo FD for the file (same file characteristics as INFILE)o In the PROCEDURE DIVISION:

Modify the file OPEN and CLOSE routines for the new file Add a paragraph that writes the output file Add code so that when your edit routines spot an error in

the input file record, after adding to the error-counter it performs the paragraph to write the input file with errors to the output file

@ Copyright 2009, International Business Machine - 23