Workshops – Module2 COBOL General Language Rules
Workshop 1 – Create your first COBOL program, using Snippets
Purpose of this workshop:
After finishing this workshop you will be able to create your own skeleton COBOL program that:
- Displays messages on the Console
- Accepts input-data from the Console operator (you)
- Writes that input-data out to a file
Pre-requisites:
Product installed
Education verification completed
Sections on RDz COBOL editor and RDz Workbench completed
Add the Identification Division
Steps
- Launch Rational Developer for System z
- Expand the chapter2 project
- Right-click over the \cobol\ folder and select:
- New > File
- Name the file: ex01.cbl
Make sure the Snippets View is open
- With your cursor in column1 of the file, Double-Click the Identification Division Snippet
- Fill in as follows:
- DataCompiled: The current date
- programName: ex01
- authorName: Your Name
- DateWritten: The current Date
- Press: Insert
Add the Environment Division
From the Snippets View
- With your cursor in column1 of the file – at the end of the Identification Division, Double-Click the Environment Division Snippet
- Optionally – change the values of the:
- FileSpec - to point to a drive, sub-directory or folder other than the c:\ root drive
- InternalFileName
- Press Insert
Add the Data Division
From the Snippets View
- With your cursor in column1 of the file – at the end of the Environment Division, Double-Click the Data Division Snippet
- Optionally – change the values of the:
- InternalFileName - note that if you customized the InternalFileName from the Environment Division Select/Assign – you will have to type in a matching name in the Data Division.
- RecName
- RecordLength
- Press Insert
Add the Procedure Division
- At the end of the Environment Division, add the following lines by typing carefully – and noting which COBOL coding area to enter statements in:
Note the following:
- If you customized the InternalFileName or other entries in the Snippets, you will have to reconcile the PROCEDURE DIVISION statements with what you selected
- You can display some other message than the above
- You do not need to type in Upper-Case (as is shown) however, it won’t hurt
- As you type, if you finish a line that may be syntactically wrong, you will get this warning:
- Mouse-over the warning to learn how to fix the statement
Be sure you follow (understand) what you’re coding in COBOL, as you type.
Build and Test your 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
- If you have any syntax errors they will appear as small red circles in the COBOL margin, and in the Remote Error List.
- Fix all of the syntax errors before continuing
Build your Project
From Project Explorer:
- Select your program: ex01.cbl
- Right-click, and from the context menu select: Nominate as Entry Point
- Right-click over the project (chapter1) and select: Rebuild Project
Test your Program
From Project Explorer:
- Expand the BuildOutput folder
- Select your program executable: ex01.exe
- Right-click, and from the context menu select: Run as > Run Configurations
- From the Run Configurations windowtype the fully-qualified name of your executable program: ex01.exe
- Press Run
- Enter (type) something in the DOS window
- Press Enter
- From Windows Explorer – open the file you wrote your output to (in our case it’s: c:\ex01.dat - from the Select/Assign clause.
Modify, Compile, Build and re-Test your COBOL Program
(See screen capture below)
- Change the internal COBOL file name (Select clause) – and update all of the areas of the program that are affected.
- Change the file’s 01 Record as shown below (note that all of the PIC clause values must add up to 80 – as per the RECORD CONTAINS clause)
- Add a VALUE clause to the REC-KTR variable
- Change the Procedure Division as shown below
- Save – and fix any/all COBOL syntax errors
- Rebuild your Project
- Run (test) the program again, and note the output produced in your external file – align this output to the values in the CBLINTERNALFILE-REC fields’ values
Optional Lab – ACCEPT with Current Date and Time Info
Modify the WORKING-STORAGE SECTION of your program, to add the following fields and ACCEPT statements
Debug your program – or modify the CBLINTERNALFILE-REC to include these fields.
Then Run your program, and verify your results by looking at the file produced.
@ Copyright 2009, International Business Machine - 1