COBOL Programming With VSCode PDF
COBOL Programming With VSCode PDF
1
Preface
Abstract
One computer programming language was designed specifically for business, Common Business-Oriented
Language, COBOL. Today COBOL remains as relevant as ever, handling $3 trillion in commerce every day.
This publication is aimed at beginners looking to build a working understanding of COBOL programming.
It describes how to work with COBOL using modern tools including Visual Studio Code with Zowe and Z
Open Editor extensions. It describes how to write, test, execute, and debug COBOL programs.
Authors
Michael Bauer is a development leader for the Open Mainframe value stream at Broadcom and is a squad
lead for the Zowe open source initiative. Zowe, a popular framework of modern interfaces for z/OS, opens
the mainframe to DevOps tools and practices. Mike leads the Command Line Interface (CLI) squad, which
created and recently spun-off the successful Zowe Explorer extension for Visual Studio Code. A frequent
speaker and blogger, Mike runs interactive workshops around the world for those interested in incorporating
mainframe in their enterprise DevOps initiatives.
Zeibura Kathau is a technical writer for the Mainframe DevOps value stream at Broadcom. He works on
the open-source projects Che4z and Code4z, which are IDE extension packages for mainframe developers. He
has 8 years of experience in the Information Technology field.
Makenzie Manna is an IBM Redbooks Project Leader in the United States. She has 3 years of experience
in the Computer Science Software Development field. She holds a Master’s degree in Computer Science
Software Development from Marist College. Her areas of expertise include mathematics, IBM Z and cloud
computing.
Paul Newton is a Consulting IT Specialist in the United States. He has 40 years of experience in the
Information Technology field. He holds a degree in Information Systems from the University of Arizona. His
areas of expertise include IBM Z, z/OS, and LinuxONE. He has written extensively on implementation of
z/OS based technology.
Jonathan Sayles is a technical educator at IBM, where he conducts presentations, seminars and training
courses, as well as producing educational materials. His more than 40 years in the IT education and computer
industries encompass work within both academic and corporate development organizations. He has also
been engaged as a software developer/designer/consultant, educator, and author, with a focus on relational
database, IDE, and object technologies. In addition to authoring/publishing 16 books, Jon has written and
published more than 150 articles in technical journals, and served as technical editor for several IT magazines.
He is also co-author of IBM Redbook publications Transitioning: Informix 4GL to Enterprise Generation
Language (EGL), SG24-6673 and z/OS Traditional Application Maintenance and Support, SG24-7868.
William Yates is a Software engineer working for IBM UK. For the majority of his career he has working
on the CICS TS product mainly as a software tester and now as Test Architect. He has delivered technical
content for many Redbooks, video courses and at conferences around the world. He is also one of the leaders
of the Galasa project, building an open source integration test framework for hybrid cloud applications
available at https://galasa.dev
Acknowledgements
Special thanks to the following people for participating in the residency to shape the content in this publication.
• Dr. Tak Auyeung, Professor, American River College
• Jeffrey Bisti, Z Ecosystem Architect, IBM
• Ilicena Elliott, IT Specialist II, Employment Development Department
• Martin Keen, Technical Content Services, IBM
2
• Sudharsana Srinivasan, z Influencer Ecosystem Program Coordinator, IBM
• Suzy Wong, Information Technology Specialist, DMV
•
Left-to-right: Ilicena, Suzy, Makenzie, Martin, Paul, and Tak
3
Contents
Part 1 - Getting started 10
1 Why COBOL? 10
1.1 What is COBOL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2 How is COBOL being used today? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Why should I care about COBOL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4
4.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
8 Basic COBOL 48
8.1 COBOL characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.1.1 Enterprise COBOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.1.2 Chapter objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
8.2 What must a novice COBOL programmer know to be an experienced COBOL programmer? 49
8.2.1 What are the coding rules and the reference format? . . . . . . . . . . . . . . . . . . . 49
8.2.2 What is the structure of COBOL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.3 What are COBOL reserved words? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.4 What is a COBOL statement? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.5 What is the meaning of a scope terminator? . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.6 What is a COBOL sentence? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.7 What is a COBOL paragraph? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2.8 What is a COBOL section? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.3 COBOL Divisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5
8.3.1 COBOL Divisions structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.3.2 What are the four Divisions of COBOL? . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.4 PROCEDURE DIVISION explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8.5 Additional information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8.5.1 Professional manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8.5.2 Learn more about recent COBOL advancements . . . . . . . . . . . . . . . . . . . . . 52
8.6 Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.7 Lab - Zowe CLI & Automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.7.1 Zowe CLI - Interactive Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.7.2 Zowe CLI - Programmatic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9 Data division 68
9.1 Variables / Data-items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
9.1.1 Variable / Data-item name restrictions and data types . . . . . . . . . . . . . . . . . . 68
9.2 PICTURE clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.2.1 PIC clause symbols and data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.2.2 Coding COBOL variable / data-item names . . . . . . . . . . . . . . . . . . . . . . . . 69
9.2.3 PICTURE clause character-string representation . . . . . . . . . . . . . . . . . . . . . 69
9.3 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
9.3.1 Figurative constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
9.3.2 Data relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
9.3.3 Levels of data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.4 MOVE and COMPUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.5 Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
10 File handling 75
10.1 COBOL code used for sequential file handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
10.1.1 COBOL inputs and outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
10.1.2 FILE-CONTROL paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
10.1.3 COBOL external data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.1.4 Data sets, records, and fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.1.5 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.1.6 ASSIGN clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.2 PROCEDURE DIVISION sequential file handling . . . . . . . . . . . . . . . . . . . . . . . . 78
10.2.1 Open input and output for read and write . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.2.2 Close input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.3 COBOL programming techniques to read and write records sequentially . . . . . . . . . . . . 79
10.3.1 READ-NEXT-RECORD paragraph execution . . . . . . . . . . . . . . . . . . . . . . . 79
10.3.2 READ-RECORD paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.3.3 WRITE-RECORD paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.3.4 Iterative processing of READ-NEXT-RECORD paragraph . . . . . . . . . . . . . . . 80
10.4 Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
11 Program structure 84
11.1 Styles of programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
11.1.1 What is structured programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
11.1.2 What is Object Orientated Programming . . . . . . . . . . . . . . . . . . . . . . . . . 85
11.1.3 COBOL programming style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
11.2 Structure of the Procedure Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
11.2.1 Program control and flow through a basic program . . . . . . . . . . . . . . . . . . . . 85
11.2.2 Inline and out of line perform statements . . . . . . . . . . . . . . . . . . . . . . . . . 86
11.2.3 Using performs to code a loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
11.2.4 Learning bad behavior using the GO TO keyword . . . . . . . . . . . . . . . . . . . . 87
11.3 Paragraphs as blocks of code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6
11.3.1 Designing the content of a paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
11.3.2 Order and naming of paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
11.4 Program control with paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
11.4.1 PERFORM TIMES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
11.4.2 PERFORM THROUGH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
11.4.3 PERFORM UNTIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
11.4.4 PERFORM VARYING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
11.5 Using subprograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
11.5.1 Specifying the target program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
11.5.2 Specifying program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
11.5.3 Specifying the return value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
11.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
12 File output 95
12.1 Review of COBOL write output process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
12.1.1 ENVIRONMENT DIVISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
12.2 FILE DESCRIPTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
12.2.1 FILLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
12.3 Report and column headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
12.3.1 HEADER-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
12.4 PROCEDURE DIVISION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
12.4.1 MOVE sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
12.4.2 PRINT-REC FROM sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
12.5 Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7
14.5 Examples of COBOL arithmetic statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
14.6 Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
8
19.1.3 TSO/ISPF in the real world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
19.1.4 ISPF emulation architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
19.1.5 Accessing the 3270-Emulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
19.2 Basic editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
19.2.1 Launch IDz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
19.2.2 Access TSO/ISPF from IDz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
19.2.3 Log in to ISPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
19.3 Overview of the ISPF primary option menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
19.3.1 What if my cursor becomes stuck in the user interface? . . . . . . . . . . . . . . . . . 141
19.3.2 Edit entry panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
19.3.3 ISPF edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
19.3.4 Navigating within a COBOL file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
19.3.5 Working with COBOL source - Prefix Area . . . . . . . . . . . . . . . . . . . . . . . . 144
19.3.6 Saving your work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
19.4 Access to batch jobs - launch and view results in JES . . . . . . . . . . . . . . . . . . . . . . 145
19.4.1 Steps - using the same basic workflow as edit . . . . . . . . . . . . . . . . . . . . . . . 146
19.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
20 Testing 148
20.1 Importance of testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
20.1.1 What is testing and why do it? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
20.1.2 What is unit testing? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
20.1.3 What is function/integration/system testing? . . . . . . . . . . . . . . . . . . . . . . . 149
20.1.4 The role of exploratory testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
20.2 Basics of continuous integration, continuous delivery . . . . . . . . . . . . . . . . . . . . . . . 151
20.2.1 Introduction to DevOps and CI/CD pipelines . . . . . . . . . . . . . . . . . . . . . . . 151
20.2.2 Focus on efficiency and automation through the pipeline . . . . . . . . . . . . . . . . . 152
20.2.3 Tests as the quality gatekeeper through phases of the pipeline . . . . . . . . . . . . . . 152
20.2.4 Managing the pipeline when test cases fail . . . . . . . . . . . . . . . . . . . . . . . . . 153
20.3 Testing on z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
20.3.1 Importance of testing on z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
20.3.2 Challenges for test automation on z/OS . . . . . . . . . . . . . . . . . . . . . . . . . . 154
20.4 Why does this matter? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
20.4.1 Value of automated testing in continuous delivery . . . . . . . . . . . . . . . . . . . . 155
20.4.2 Dangers of not automating testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
20.4.3 Risks of not adopting continuous delivery . . . . . . . . . . . . . . . . . . . . . . . . . 155
20.4.4 Use of automated testing for system reliability . . . . . . . . . . . . . . . . . . . . . . 155
20.5 How can test automation be achieved on z/OS? . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9
Part 1 - Getting started
1 Why COBOL?
This chapter introduces COBOL, specifically with reference to its use in enterprise systems.
• What is COBOL?
• How is COBOL being used today?
• Why should I care about COBOL?
10
The point is - whatever you read or hear about COBOL, be very skeptical. If you have the opportunity to
work directly with someone involved in writing or maintaining critical business logic using COBOL, you will
learn about the operation of the core business. Business managers, business analysts, and decision makers
come and go. The sum of all good business decisions can frequently be found in the decades of changes
implemented in COBOL programs. The answer to “How does this business actually work?” can be found in
COBOL programs.
Add the following to your awareness of COBOL. It is an absolute myth that you must be at least 50 years
old to be good with COBOL. COBOL is incredibly easy to learn and understand. One of the many reasons
financial institutions like COBOL, is the fact that it is not necessary to be a programmer to read and
understand the logic. This is important because critical business logic code is subject to audit. Auditors
are not programmers. However, auditors are responsible for ensuring the business financial statements are
presented fairly. It is COBOL processing that frequently result in the business ledger updates and subsequent
financial statements.
Now for a real-world lesson. A comment recently made in a well-known business journal by someone with a
suspect agenda was quoted as saying, “COBOL is a computing language used in business and finance. It was
first designed in 1959 and is pretty old and slow.” A highly experienced business technology person knows
the only true part of that last sentence was that COBOL was first designed in 1959.
It’s no secret that lots of banks still run millions of lines of COBOL on mainframes. They probably want to
replace that at some point. So why haven’t they? Most banks have been around long enough to still feel the
pain from the ~1960’s software crisis. After spending enormous amounts of money, and time, on developing
their computer systems, they finally ended up with a fully functional, well-tested, stable COBOL core system.
Speaking with people that have worked on such systems, nowadays they have Java front ends and wrappers
which add functionality or more modern interfaces, they run the application on virtualized replicated servers,
but in the end, everything runs through that single core logic. And that core logic is rarely touched or
changed, unless necessary.
From a software engineering perspective, that even makes sense. Rewrites are always more expensive than
planned, and always take longer than planned (OK, probably not always. But often.). Never change a
running system etc., unless very good technical and business reasons exist.
11
2 VSCode with Zowe Explorer
Zowe Explorer is an open-source extension for VS Code that lets developers and system administrators
interact with z/OS mainframes using the VSC interface.
• Introduction to Zowe Explorer
• Profiles in Zowe Explorer
– Secure Credentials
– Creating a New Profile
– Editing Profiles
– Deleting Profiles
• Using Zowe Explorer
• Summary
3. Type Zowe-Plugin in the text box. This will trigger the Built-in Secure Credential Store.
Alternatively, to enable this feature by editing settings.json, hover over the gear icon and click “Copy Setting
as JSON”. You can then paste that to settings.json and update the value to Zowe Plugin.
12
Note: If you are using Zowe CLI and you’ve installed the Secure-Credential-Store Plugin, the steps to activate
it will still be the same.
2. Click on the + sign. A dialog box will appear and ask if you want to “Create a New Connection to
z/OS”.
3. Press enter or click on that selection.
5. Enter the URL and Port that you received by email when you registered for the COBOL Course. The
connection information that you need has a title of “IP address for VSCode extension”.
13
6. Enter your Username. This is also included in the email.
Note: You can leave this blank if you do not want to save your credentials in your machine. You will be
prompted for your username once you start using Zowe Explorer.
7. Enter your Password.
Note: You can leave this blank if you do not want to save your credentials in your machine. You will be
prompted for your username once you start using Zowe Explorer.
8. Select True/False if you want to accept or reject Self-Signed Certificates.
14
3. Edit the URL information if changes are required, or enter to confirm the information is still correct.
Note: You can leave this blank if you do not want to save your credentials in your machine. You will be
prompted for your username once you start using Zowe Explorer.
5. Edit your Password.
Note: You can leave this blank if you do not want to save your credentials in your machine. You will be
prompted for your username once you start using Zowe Explorer.
6. Edit your authorized connections
15
If you are successful, an information message will appear:
16
Once confirmed, the following message is displayed:
17
• Download, edit, and upload existing PDS members Instantly pull data sets and data set members from
the mainframe, edit them and upload back.
• Create and delete both data sets and data set members
• View, access, and work with multiple profiles simultaneously.
• Submit a JCL. You can submit a JCL from a chosen data set.
USS Files
• View multiple Unix System Services (USS) files simultaneously.
• Rename USS files.
• Download, edit, and upload existing USS files. You can instantly pull USS files from the mainframe,
edit them and upload back.
• Create and delete USS files and directories.
• View, access, and work with multiple profiles simultaneously.
Jobs:
• View multiple jobs simultaneously.
• Download spool content onto your computer.
For more information about Zowe Explorer and the different use cases, visit the GitHub repository: https:
//github.com/zowe/vscode-extension-for-zowe
2.4 Summary
In this section you have learned how to create and work with Zowe compatible zosmf profiles and learned
about the basic features of the Zowe Explorer extension.
18
3 VSCode with Z Open Editor
In this chapter we will explain how to use the IBM Z Open Editor extension for VSCode and how using it
can help you develop COBOL source code in a feature rich environment.
• Introduction to the IBM Z Open Editor
– What is the IBM Z Open Editor?
– The role of the Language Server Protocol
– Installing the IBM Z Open Editor for VS Code
• Basic editing
– Known file extensions
– Margins
– Variable expansion
– Syntax highlighting
• Navigation of code
– Outline view
– Breadcrumb view
– Jump to declaration / reference
• Code-completion
– COBOL reserved word completion
– Variable completion
– CICS, MQ, DB2 API completion
• Refactoring code
– Renaming variables
– Handling errors
• Summary
19
The language server protocol defines six broad capabilities that should be implemented for a language server
to be LSP compliant. These capabilities include code completion, hover, jump to definition, workspace
symbols, find references and diagnostics. The IBM Z Open Editor provides compliant language servers for
both the Enterprise Cobol and Enterprise PL/I for z/OS languages. In addition to being compliant, they
also provide additional capabilities that we will discuss further on.
Note: More information on Language Server Protocol implementations can be found at: https://langserver.org
Will be assumed to be COBOL code. This information is stored in the global VSCode settings.json file that
can be accessed through VSCode preferences. This allows for a user to tailor VSCode’s known extensions to
a particular site naming convention.
3.2.2 Margins
The first thing you will notice when editing COBOL source code is that VSCode will have inserted five
vertical lines down the file. These lines segment each line of code into the areas reserved for sequence numbers,
comment / continuation characters, area A and area B. When coding without this basic aid I cannot recount
the number of times I have made a compilation error because I started coding in the wrong column. This
20
alone is a very useful aid to a new COBOL programmer. Move information about COBOL syntax and in
particular the columns will be discussed later
21
3.2.4 Syntax highlighting
The COBOL code that you are editing will also be highlighted to help you understand the different elements
of the COBOL language. Depending on the color theme that you have selected in VSCode, comments,
COBOL reserved words, literal values and variables will be colored differently allowing you to spot obvious
syntax issues early on before even submitting the code to a build.
22
Figure 4. Breadcrumb trail in VSCode
Clicking on any of the items in the breadcrumb trail will highlight that element of the code in the editor,
quickly showing you the location of that element within the code. It will also show a view of the code in a
pop-up window, shown in Figure 5. , similar to the outline view previously discussed.
23
paragraph or variable to all the places within the application that reference that paragraph or variable. To
demonstrate this, navigate to line 62 of CBL0001, which again is the declaration of the READ-RECORD
paragraph. To see all of the places where this paragraph is called, right click and select Go to References
, or hit the key combination SHIFT+F12 . This will summon a new pop up dialog which shows all the
references to this paragraph in the code, shown in Figure 6.
Note: If SHIFT+F12 does not work for your machine, you may need to use the key combination, Fn+F12
instead.
3.4 Code-completion
Code completion isn’t exactly a new concept in most IDEs. For example, the Eclipse editor has provided
auto-completion for Java APIs for a long time. The same key combination, CTRL+SPACE , triggers this
auto-completion function while you are coding and can be used to help guide you through COBOL syntax
and CICS, IMS API calls.
24
Figure 7. Auto-completion in VSCode
You can see that not only is the variable ACCT-BALANCE prompted as a potential candidate, but it also
presents ACCT_BALANCE IN ACCT-FIELDS.
25
rename the variable, we probably need to update this reference as well. To perform the rename, ensure that
the cursor is on the variable and then press SHIFT/Fn+F2 . This will bring up a small pop-up asking you
to provide a new variable name, as shown in Figure 8. Enter ACCT-NO-TEST and press enter .
26
Figure 10. Highlighting error in source code
Now that you see where the error is located, it can now be corrected. As soon as the error has been rectified,
the problem disappears from the problem view.
3.6 Summary
In this chapter you have been able to go through some of the editing features of the Z Open Editor for
VSCode. These capabilities make editing COBOL, PL/Iand JCL a lot friendlier and easier than some of the
other editors in the market.
27
4 VS Code with Code4z Open-Source Extension Package
This section introduces the Code4z extension package, in particular the COBOL Language Support extension.
• What is Code4z?
• Known File Extensions
• Syntax Highlighting and Coloring
• Syntax and Semantic Check
• Navigation of Code
– Breadcrumb View
– Outline View
– Shortcuts
– Go To Definition
– Find All References
• Copybook Support
• Autocomplete
• Summary
28
Figure 1. The syntax and semantic check feature highlights an error.
4.5.3 Shortcuts
You can use the following shortcuts to navigate through your code:
• CTRL+ALT+, moves you one section back.
• CTRL+ALT+. moves you one section forward.
• CTRL+ALT+D takes you to the data division.
• CTRL+ALT+P takes you to the procedure division.
• CTRL+ALT+W takes you to the working storage section.
These commands are also available if you right click anywhere in the code.
29
4.5.4 Go To Definition
While your cursor is placed on a variable or paragraph name, you can press F12 or CTRL+click to use the
Go To Definition functionality to display the point in the code where the variable or paragraph is defined.
Figure 3. Go To Definition shows the point at which the USER-STREET variable is first defined.
Figure 4. Find All References lists all references to the USER-STREET variable in the code.
4.7 Autocomplete
The COBOL Language Support extension provides live suggestions while you type for COBOL keywords,
as well as variables and paragraphs which are already referenced in the code or in copybooks used by the
program.
30
Figure 5. Autocomplete lists possible variables and keywords beginning with the typed string in a list.
4.8 Summary
In this chapter you have been introduced to all the COBOL language support features of the Code4z package
of open-source extensions for VS Code.
31
5 Zowe CLI and Zowe CLI Plug-ins
In this chapter we will explain what a CLI is and why you would use it, how to use Zowe CLI interactively,
how to abstract CLI commands into useful scripts, and how Zowe CLI enables the use of familiar open source
tooling while developing COBOL applications on the mainframe.
• What is a CLI and why would you use it?
• What is Zowe CLI?
• Zowe CLI interactive use
– Installing Zowe CLI
– Interactive Help
– Zowe Profiles
– Interacting with z/OS Data Sets
– Interacting with z/OS Jobs
• Automating tasks using Zowe CLI
– Automated Job Submission
– Using Other Programming Languages and Continuous Integration
– Additional Examples
• The world of modern open source tooling
• Summary
32
CLIs are useful for automating repeated tasks. For mainframe COBOL apps, Zowe CLI can help you automate
your build, deployment, and testing processes. Check out this blog for more info and the sample code that
made it possible! Zowe CLI can also help you to automate administrative tasks.
Most IDEs have integrated terminals as well so the CLI can be leveraged from your favorite distributed
development environment, including VS Code!
33
In the example above, multiple extensions are installed. The structure of commands is zowe <group>
<action> <object> followed by various parameters and options specific to the command. For example,
a valid command is zowe files list data-set "HLQ.*". This command will list data-sets matching a
pattern of "HLQ.*". You can append -h to any command to find out more information. Frequently referring
to the help can be difficult and time consuming so if your environment has access to a web browser, simply
append --help-web or --hw to any command to launch interactive web help.
34
5.3.4 Interacting with z/OS Data Sets
Zowe CLI provides a significant suite of z/OS data set interaction functionality. See the following figures for
details on available actions and a sample list command.
35
Figure 7. Sample Zowe CLI zos-jobs submit ds command
36
Figure 10. Sample Zowe CLI response format JSON output
Now, instead of issuing this command and reviewing it to see if the retcode is less than or equal to 4, we
want to automate it. See the implementation in a node script below.
Figure 11. Sample code to submit job and verify output is less than or equal to a maximum allowable RC
I had to make the investment to write this automation but for future job submissions I can simply issue
npm run submitJob. IDEs like VS Code can visualize these tasks making my commonly repeated tasks as
easy as clicking a button :). This job could compile, link, and/or run a COBOL program.
37
Figure 12. Vizualization of npm script and sample run
More advanced code automating the compilation, deployment to test environment, and testing of a COBOL
CICS application is described in this blog.
38
You can then level-up this process by leveraging a CI/CD pipeline. What is a CI/CD pipeline? It is an
automated way of building, testing, and deploying your application and you can do the same with your
COBOL development. The figure below shows the pipeline for the same automated tasks that we did earlier.
Figure 14. CI/CD pipeline of the “one click” COBOL build process
To know more about this topic, check this out.
5.6 Summary
As both a user and programmatic interface, command line interfaces offer significant value in simplifying
complex repeatable processes into single tasks. CLIs are commonly used when developing on popular cloud
platforms like Amazon Web Services. The Zowe CLI is the CLI for the mainframe that has been extended via
numerous plug-ins. Zowe CLI acts as a bridge tool enabling the use of distributed development tooling while
working with mainframe applications. Numerous resources and articles are available for using Zowe CLI to
create custom automation, build CI pipelines, and incorporate static analysis into your COBOL development
processes. Development tooling created by the distributed open source community can now be effectively
leveraged for mainframe development.
39
6 Installation of VSCode and extensions
This chapter covers all aspects of download and installation of Visual Studio (VS) Code and any prerequisites
that are needed. It includes:
• Install prerequisites
– Install node.js
– Install Java SDK
• Install VSCode
• Install VSCode extensions
– Zowe Explorer
– IBM Z Open Editor
– Code4z
• Summary
V12 .16.1
40
Note : The version numbers in our examples are provided purely for reference and may not reflect the latest
versions of the software.
41
Figure 1. VSCode download site
Note : Be sure to select the correct installation file for your workstations respective OS, shown in Figure 1.
6.3.1.1 Install Zowe Explorer Open VSCode and in the left side tool menu select Extensions. From
there, in the “Search Extensions in Marketplace” search field, type Zowe Explorer. Search results will begin
populating, select “Zowe Explorer” and click install, depicted in Figure 3.
42
Figure 3. Install Zowe Explorer in VSCode
The Zowe communinity have a number of on-line video that walk through the steps required to install,
configure and operate the Zowe Explorer, see Zowe Explorer VSC Extension (part 1).
6.3.2.1 Install IBM Z Open Editor Open VSCode and in the left side tool menu select Extensions.
From there, in the “Search Extensions in Marketplace” search field, type IBM Z Open Editor. Search results
will begin populating, select " IBM Z Open Editor " and click install, depicted in Figure 4.
43
Figure 4. Install IBM Z Open Editor in VSCode
Note : There may be some limitations with IBM Z Open Editor if running a 32-bit Java version on Windows.
6.3.3 Code4z
Code4z is an all-in-one, open-source mainframe extension package for developers working with z/OS appli-
cations, suitable for all levels of mainframe experience, even beginners. Mainframe application developers
can use the Code4z package for a modern, familiar, and seamless experience, which helps to overcome some
developers’ reservations or concerns about the traditional mainframe user experience. To find out more about
Code4z, please visit https://github.com/BroadcomMFD/code4z.
6.3.3.1 Install Code4z Open VSCode and in the left side tool menu select Extensions. From there, in
the “Search Extensions in Marketplace” search field, type Code4z. Search results will begin populating, select
" Code4z " and click install.
6.4 Summary
In this chapter you have been introduced to VSCode and some of the extension tools available to it. We have
walked through the process of installing the pre-requisite software, Node.js and Java SDK, as well as VSCode,
Zowe Explorer, IBM Z Open Editor and Code4z. You have also been briefly introduced to the utility of these
extensions in VSCode. In the subsequent chapters we will delve deeper into how and when to use them and
get some practice through lab assignments.
44
7 Installation of Zowe CLI and Plug-ins
This chapter covers all aspects of the download and installation of Zowe CLI and Zowe CLI plug-ins.
• Install prerequisites - Node.js
• Install Zowe CLI
– Public npm Registry
– Package from Zowe.org
• Install Zowe CLI Plug-ins
– Public npm Registry
– Package from Zowe.org
• Summary
If the command returns an EACCESS error, refer to Resolving EACCESS permissions errors when installing
packages globally in the npm documentation. If other issues are encountered in your environment, please
review known Zowe CLI issues for solutions.
We also highly recommend installing the Secure Credential Store plug-in before using the CLI. The Secure
Credential Store Plug-in for Zowe CLI lets you store your credentials securely in the default credential
manager in your computer’s operating system. On Linux, libsecret will need to be installed.
If running Linux, please run the following command for your Linux distribution:
• Debian/Ubuntu: sudo apt-get install libsecret-1-dev
• Red Hat-based: sudo yum install libsecret-devel
• Arch Linux: sudo pacman -S libsecret
To install the Secure Credential Store Plug-in for Zowe CLI, issue the following command:
zowe plugins install
@zowe / secure - credential - store - for - zowe - cli@zowe - v1 - lts
User profiles, which contain connection information for interacting with various z/OS services, created after
installing the plug-in will automatically store your credentials securely.
45
To securely store credentials in existing user profiles (profiles that you created prior to installing the SCS
plug-in), issue the following command:
zowe scs update
If the command returns an EACCESS error, refer to Resolving EACCESS permissions errors when installing
packages globally in the npm documentation. If other issues are encountered in your environment, please
review known Zowe CLI issues for solutions.
The highly recommended Secure Credential Store Plug-in for Zowe CLI lets you store your credentials securely
in the default credential manager in your computer’s operating system. On Linux, libsecret will need to be
installed.
If running Linux, please run the following command for your Linux distribution:
• Debian/Ubuntu: sudo apt-get install libsecret-1-dev
• Red Hat-based: sudo yum install libsecret-devel
• Arch Linux: sudo pacman -S libsecret
To install the Secure Credential Store Plug-in for Zowe CLI, issue the following command from where you
unzipped the core CLI package contents:
zowe plugins install secure - credential - store - for - zowe - cli . tgz
User profiles, which contain connection information for interacting with various z/OS services, created after
installing the plug-in will automatically store your credentials securely.
To securely store credentials in existing user profiles (profiles that you created prior to installing the SCS
plug-in), issue the following command:
zowe scs update
46
For example,
zowe plugins install @zowe / cics - for - zowe - cli@zowe - v1 - lts
Multiple plug-ins can be installed in a single command. For example, to install all Zowe CLI plug-ins available
from the Zowe organization, you could issue:
zowe plugins install @zowe / cics - for - zowe - cli@zowe - v1 - lts
@zowe / ims - for - zowe - cli@zowe - v1 - lts @zowe / mq - for - zowe - cli@zowe - v1 - lts
@zowe / zos - ftp - for - zowe - cli@zowe - v1 - lts
@zowe / db2 - for - zowe - cli@zowe - v1 - lts
Vendor plug-ins on the registry are installed in the same way. For example, to install the CA Endevor plug-in,
you would issue
zowe plugins install @broadcom / endevor - for - zowe - cli@zowe - v1 - lts
For offline installation of vendor plug-ins, please reach out to the specific vendor for details.
7.4 Summary
In this chapter we walked through the process of installing the prerequisite software, Node.js and npm, as
well as Zowe CLI and various plug-ins.
47
Part 2 - Learning COBOL
8 Basic COBOL
This chapter introduces the basics of COBOL syntax. It then demonstrates how to view and run a basic
COBOL program in VSCode.
• COBOL characteristics
– Enterprise COBOL
– Chapter objectives
• What must a novice COBOL programmer know to be an experienced COBOL program-
mer?
– What are the coding rules and the reference format?
– What is the structure of COBOL?
– What are COBOL reserved words?
– What is a COBOL statement?
– What is the meaning of a scope terminator?
– What is a COBOL sentence?
– What is a COBOL paragraph?
– What is a COBOL section?
• COBOL Divisions
– COBOL Divisions structure
– What are the four Divisions of COBOL?
• PROCEDURE DIVISION explained
• Additional information
– Professional manuals
– Learn more about recent COBOL advancements
• Lab
• Lab - Zowe CLI & Automation
– Zowe CLI - Interactive Usage
– Zowe CLI - Programmatic Usage
48
8.1.2 Chapter objectives
The object of the chapter is to expose the reader to COBOL terminology, coding rules, and syntax while the
remaining chapters include greater detail with labs for practicing what is introduced in this chapter.
8.2.1 What are the coding rules and the reference format?
COBOL source code is column dependent, meaning column rules are strictly enforced. Each COBOL source
code line has five areas, where each of these areas has a beginning and ending column.
COBOL source text must be written in COBOL reference format. Reference format consists of the areas
depicted in Figure 1. in a 72-character line.
49
• Ignored by the compiler.
• Can be blank or optionally used by programmer for any purpose.
50
Example 1. Division -> paragraph -> sentences
51
8.4 PROCEDURE DIVISION explained
The PROCEDURE DIVISION is where the work gets done in the program. Statements are in the PROCE-
DURE DIVISION where they are actions to be taken by the program. The PROCEDURE DIVISION is
required for data to be processed by the program. PROCEDURE DIVISION of a program is divided into
sections and paragraphs, which contain sentences and statements, as described here:
• Section - A logical subdivision of your processing logic. A section has a header and is optionally
followed by one or more paragraphs. A section can be the subject of a PERFORM statement. One type
of section is for declaratives. Declaratives are a set of one or more special purpose sections. Special
purpose sections are exactly what they sound like, sections written for special purposes and may contain
things like description of inputs and outputs. They are written at the beginning of the PROCEDURE
DIVISION, the first of which is preceded by the key word DECLARATIVES and the last of which is
followed by the key word END DECLARATIVES.
• Paragraph - A subdivision of a section, procedure, or program. A paragraph can be the subject of a
statement.
• Sentence - A series of one or more COBOL statements ending with a period.
• Statement - An action to be taken by the program, such as adding two numbers.
• Phrase - A small part of a statement (i.e. subdivision), analogous to an English adjective or preposition
52
• What’s New in Enterprise COBOL for z/OS V6.2:
https://youtu.be/H0iweEbVNFs
• What’s New in Enterprise COBOL for z/OS V6.3:
https://youtu.be/bRLKGeB6W2A
8.6 Lab
In this lab exercise you will connect to an IBM Z system, view a simple COBOL hello world program in
VSCode, submit JCL to compile the COBOL program, and view the output. Refer to “Installation of VSCode
and extensions” to configure VSCode with the Zowe Explorer and Z Open Editor extensions if you have not
already done so.
1. The lab assumes installation of VSCode with Z Open Editor and Zowe Explorer extensions as shown in
Figure 2.
Click the Extensions icon. List should include:
1. IBM Z Open Editor
2. Zowe Explorer
53
3. Zowe Explorer can list Data Sets, Unix System Services (USS) files, and Jobs output as shown in Figure
4. + will appear when hovering to the far right on the DATA SETS line. Click the + to define a
VSCode profile.
54
Figure 8. Specified z/OSMF URL
8. The connection prompts for Username as shown in Figure 9.
55
Figure 13. Accept connections with self-signed certifications
13. Result is Favorites in the Data Sets, Unix System Services, and Jobs sections as shown in Figure 14.
56
16. A prompt to “Select a filter” appears for ID Z99998. Select the + to ‘Create a new filter” as shown in
Figure 17.
57
Figure 21. Z9998.CBL
21. Expand Z99998.JCL to view JCL and select member HELLO which is the JCL to compile and execute
simple ‘Hello World!’ COBOL source code as shown in Figure 22.
58
Figure 25. + Select LearnCOBOL connection
25. As a result, the JCL jobs owned by ID Z99998 appears. HELLOCBL is the JCL job name previously
submitted. Expand HELLOCBL output to view sections of the output as shown in Figure 26.
59
Figure 27. COBOL compiler output
27. View the COBOL program execution by selecting COBRUN:SYSOUT(105) from the LearnCOBOL
in the Jobs section of Zowe Explorer as shown in Figure 28.
60
and Plug-ins” to install Zowe CLI if you have not already done so. Before developing the automation, we will
first leverage the Zowe CLI interactively.
Figure 29. zowe --version command in VS Code Integrated Terminal (Shell selection outlined in red)
2. In order for Zowe CLI to interact with z/OSMF the CLI must know the connection details such as
host, port, username, password, etc. While you could enter this information on each command, Zowe
provides the ability to store this information in configurations commonly known as profiles. Zowe CLI
and the Zowe VS Code Extension share profiles. So if you created a connection profile in the first lab,
you could naturally leverage it here.
To create a LearnCOBOL profile (and overwrite it if it already exists), issue the following command with
your system details (using prompt* will prompt you for certain fields and not show input):
zowe profiles create zosmf LearnCOBOL -- host 192.86.32.250 -- port 10443
-- ru false -- user prompt * -- pass prompt *
Many profiles can be created for interacting with different z/OSMF instances. If this was not your first
profile, you will want to set it as the default for the following lab exercises. Issue the following command:
zowe profiles set zosmf LearnCOBOL
61
Figure 30. Create and set z/OSMF profile (secure credential store plug-in is in use)
3. Confirm you can connect to z/OSMF by issuing the following command:
zowe zosmf check status
4. List data sets under your ID by issuing a command similar to (see sample output in the following
figure):
zowe files list ds " Z80462 .*"
You can also list all members in a partitioned data set by issuing a command similar to (see sample output in
the following figure):
zowe files list am " Z80462 . CBL "
62
5. Next, we will download our COBOL and JCL data set members to our local machine. First, create
and open a new folder in your file explorer. Note that you could also create a workspace to manage
multiple projects. See the following figure for help:
Then open hello.cbl in your file explorer. A completed example is shown in the following figure:
Figure 33. Download and view data set members using the CLI
6. Next, we will submit the job in member Z80462.JCL(HELLO). To submit the job, wait for it to complete,
and view all spool content, issue:
zowe jobs submit ds " Z80462 . JCL ( HELLO ) " -- vasc
We could also perform this step in piecemeal to get the output from a specific spool file. See the next figure
for an example of the upcoming commands. To submit the job and wait for it to enter OUTPUT status,
issue:
63
zowe jobs submit ds " Z80462 . JCL ( HELLO ) " -- wfo
where JOB00906 and 105 are obtained from the previous commands.
Figure 34. Submit a job, wait for it to complete, then list spool files for the job, and view a specific spool file
If desired, you can also easily submit a job, wait for it to complete, and download the spool content using the
following command (see the following figure for the completed state):
zowe jobs submit ds " Z80462 . JCL ( HELLO ) " -d .
64
Figure 35. Submit a job, wait for it to complete, download and view spool files
The Zowe CLI was built with scripting in mind. For example, you can use the --rfj flag to receive output in
JSON format for easy parsing. See the next figure for an example.
Figure 36. The --rfj flag allows for easy programmatic usage
65
1. Since we already have Node and npm installed, let’s just create a node project for our automation. To
initialize a project, issue npm init in your project’s folder and follow the prompts. You can accept
the defaults by just pressing enter. Only the description and author fields should be changed. See the
following figure.
Figure 37. Use of npm init to create package.json for the project
2. Now that we have our package.json simply replace the test script with a clg script that runs the
following zowe command (replace Z80462 with your high level qualifier):
zowe jobs submit ds ' Z80462 . JCL ( HELLO ) ' -d .
You can name the script whatever you want. I only suggested clg because the CLG in the IGYWCLG proc
(which is what the JCL leverages) stands for compile, link, go. Now, simply issue npm run clg in your
terminal to leverage the automation to compile, link and run the COBOL program and download the output
for review. An example of the completed package.json and command execution are shown in the following
figure.
66
Figure 38. Final package.json and npm run clg execution
3. If you prefer a graphical trigger, you can leverage VS Code as shown in the following figure. Essentially,
the CLI enables you to quickly build your own buttons for your custom z/OS tasks. You could also
invoke a script rather than a single command to accomodate more complex scenarios.
67
9 Data division
Understanding COBOL variables and program processing of variables are essential to effectively learning the
COBOL language. An experienced COBOL programmer must master characteristics of COBOL variables
and the program processing using the variables introduced in this chapter. The objective is to introduce the
reader to the basics of COBOL variables while exposing the reader to the many advanced COBOL variable
options.
Following this chapter is a lab available to compile and execute the COBOL source code provided later in the
chapter. Following the successful compile and execution of one provided program, a second provided COBOL
program with a minor change is available to compile. The second program has an embedded error and on
compile will fail. The failed compilation is an opportunity to identify the error associated with the significance
of PICTURE clause data types associated with the operation of the COMPUTE statement (discussed in this
chapter) and how to solve the error.
• Variables / Data-items
– Variable / Data-item name restrictions and data types
• PICTURE clause
– PIC clause symbols and data types
– Coding COBOL variable / data-item names
– PICTURE clause character-string representation
• Literals
– Figurative constants
– Data relationships
– Levels of data
• MOVE and COMPUTE
• Lab
68
When COBOL source code is compiled into an executable program, the COBOL compiler is expecting a
named COBOL variable to possess attributes such as a length and data type. During program execution, the
variable represents a defined area of processing memory where the memory location has a maximum length
and designated data type.
A list of the most common COBOL data types are:
• Numeric (0-9)
• Alphabetic (A-Z), (a-z), or a space
• Alphanumeric Numeric and Alphabetic Combination
69
• PIC clause for a value such as $1,123.45 is coded as follows:
PIC $9,999V99
9.3 Literals
A COBOL literal is constant data value, meaning the value will not change like a variable can. The
COBOL statement, DISPLAY "HELLO WORLD!", is a COBOL reserved word, DISPLAY , followed by a literal,
HELLO WORLD!
9.3.2.1 Level numbers A structured level number hierarchic relationship is available to all DATA
DIVISION sections. Figure 1. shows the level number hierarchic relationship with programmer chosen level
numbers, variable names and PIC clauses in the File Section where “01 PRINT-REC” references the following
“05”-level group of variables and the “01 ACCT-FIELDS” references the following “05”-level group of variables.
Observe 05-level CLIENT-ADDR is further subdivided into several 10-level names. COBOL code referencing
the name CLIENT-ADDR includes the 10-level names.
70
Figure 1. Level number hierarchic relationship
71
Figure 2. MOVE and COMPUTE example
9.5 Lab
Note : It may take a few seconds to load in all segments of this lab. If files are not loading, hit the refresh
button on the list that appears when hovering over the section bar.
1. View the PAYROL00 COBOL source code member in the ‘id’.CBL data set.
2. Submit the JCL member, PAYROL00, from the id.JCL, where id is your id,dropdown. This is where
id.JCL(PAYROL00) compiles and successfully executes the PAYROL00. program.
72
Note : If you receive this error message after submitting the job:
That is because you submitted the job from the .CBL data set and not the .JCL data set.
3. View both compile and execution of PAYROL00 job output, referenced in Figure 4.
73
Figure 7. Compare return codes
74
10 File handling
The previous chapter and lab focused on variables and moving literals into variables, then writing variable
content using the COBOL DISPLAY statement. This section introduces reading records from files into
variables, moving the variables to output variables, and writing the output variables to a different file. A
simple COBOL program to read each record from a file and write each record to a different file is used to
illustrate COBOL code necessary to read records from an input external data source and write records to an
output external data source.
An experienced COBOL programmer can answer the question, “How does an Enterprise COBOL program
read data from an input external data source and write data to an output external data source?” The
objective of this chapter is to provide enough comprehensive information for the reader to be able to answer
that question.
• COBOL code used for sequential file handling
– COBOL inputs and outputs
– FILE-CONTROL paragraph
– COBOL external data source
– Data sets, records, and fields
– Blocks
– ASSIGN clause
• PROCEDURE DIVISION sequential file handling
– Open input and output for read and write
– Close input and output
• COBOL programming techniques to read and write records sequentially
– READ-NEXT-RECORD paragraph execution
– READ-RECORD paragraph
– WRITE-RECORD paragraph
– Iterative processing of READ-NEXT-RECORD paragraph
• Lab
75
– WRITE FROM statement
Figure 1. FILE-CONTROL
While SELECT gives a name to an internal file and ASSIGN gives a name to the external dataset name,
a COBOL program needs more information about both. The COBOL compiler is given more information
about both in the DATA DIVISION, FILE SECTION.
The COBOL reserved word ‘FD’ is used to give the COBOL compiler more information about internal file
names in the FILE-SECTION. The code below the FD statement is the record layout. The record layout
consists of level numbers, variable names, data types, and lengths as shown in Figure 2.
Figure 2. FILE-SECTION
76
10.1.3 COBOL external data source
Enterprise COBOL source code compiles and executes on IBM Z Mainframe hardware where z/OS is the
operating system software. z/OS stores data in both data sets and Unix files. z/OS includes many data
storage methods. This chapter will focus on the z/OS sequential data storage method. A sequential dataset
is a collection of records.
10.1.5 Blocks
Each record read by the program can result in disk storage access. A program typically reads 1 record at a
time in sequential order until all records are read. When a record is read, the record retrieved from disk is
stored in memory for program access. When each next record read requires the need to retrieve the record
from disk, system performance is impacted negatively. Records can be blocked where a block is a group
of records. The result is when the first record is read, then an entire block of records is read into memory
assuming the program will be reading the second, third, etc. records avoiding unnecessary disk retrievals and
negative system performance. The memory holding a record or block of records to be read by the program is
known as a buffer. COBOL BLOCK CONTAINS clause is available to specify the size of the block in the
buffer. Observe Figure 3.
77
//** ACCTREC ** DD DSN = MY . DATA , DISP = SHR
Figure 4. OPEN-FILES
Figure 5. CLOSE-STOP
78
10.3 COBOL programming techniques to read and write records sequentially
When reading records, the program needs to first check for no records to be read or check for no more
records to be read. If a record exists, then the fields in the read record populate variable names defined by
the FD clause. COBOL uses a PERFORM statement for iteration. In computer programming, iterative
is used to describe a situation in which a sequence of instructions or statements can be executed multiple
times. One pass through the sequence is called an iteration. Iterative execution is also called a loop. In
other programming languages, ‘DO’ or ‘FOR’ statements are used for iterative execution. COBOL uses a
PERFORM statement for iterative execution. Figure 6. shows four programmer chosen paragraph names in
the PROCEDURE DIVISION.
• READ-NEXT-RECORD
• CLOSE-STOP
• READ-RECORD
• WRITE-RECORD
READ-NEXT-RECORD repeatedly executes READ-RECORD and WRITE-RECORD until a last record is
encountered. When the last record is encountered, then CLOSE-STOP is executed stopping the program.
79
10.3.2 READ-RECORD paragraph
The READ-RECORD paragraph executes the COBOL READ statement resulting in the external sequential
file populating the variables associated with ACCT-REC internal file name. If ‘AT END’ of records read, then
Y is moved into the LASTREC variable. The READ statement is terminated by an explicit scope terminator,
END-READ. The paragraph is terminated by an implicit scope terminator, (.) period. Control is returned to
READ-NEXT-RECORD paragraph to execute the next statement, PERFORM WRITE-RECORD.
10.4 Lab
The lab associated with this chapter demonstrates the ‘end-of-file’ COBOL coding technique for reading all
data records from a sequential file. If a step has an asterisk (*) next to it, it will have a hint associated at
80
the end of the lab content.
1. If not already, open VSCode and select Zowe Explorer from the left sidebar.
Note : If you are opening a new instance of VSCode (i.e. you closed out of it after the previous usage),
you may need to ‘Select a filter’ again. You can do so by selecting the search icon next to your named
connection in the DATA SETS section and then reselecting the filter previously used. It should be in the
listed filters after you have selected the search symbol.
2. View these COBOL source code members listed in the id.CBL data set:
• CBL0001
• CBL0002
3. View these three JCL members in the id.JCL data set:
• CBL0001J
• CBL0002J
• CBL0003J
Figure 8. Id.JCL(CBL0001J).jcl
4. Submit job, JCL(CBL0001J), within the DATA SET section.
5. View that job output using the JOBS section.
• COBRUN:SYSPRINT(101) - COBOL program compiler output
• RUN:PRTLINE(103) - COBOL program execution output, shown in Figure 9.
81
Figure 9. RUN:PRTLINE(103) for JCL(CBL0001J)
6. Submit job, JCL(CBL0002J), within the DATA SET section.
7. View that job output using the JOBS section.
• COBRUN:SYSPRINT(101) - COBOL program compiler output
Locate COBOL compiler severe message IGYPS2121-S within the output file referred to in step 7,
shown in Figure 10.
82
Figure 11. RUN:SYSOUT(104) message
12. Fix this error by editing JCL(CBL0003J):
• Determine the DDNAME needed, but missing or misspelled.
• Correct it within the code and save
13. Re-submit job, JCL(CBL0003J), using the DATA SET section.
14. View CBL0003J output using the JOBS section, your output should look like Figure 12.
• RUN:PRTLINE - COBOL program execution output (if correction is successful)
83
11 Program structure
In this chapter we discuss the concept of structured programming and how it relates to COBOL. We highlight
the key techniques within the COBOL language that allow you to write good well-structured programs.
• Styles of programming
– What is structured programming
– What is Object Orientated Programming
– COBOL programming style
• Structure of the Procedure Division
– Program control and flow through a basic program
– Inline and out of line perform statements
– Using performs to code a loop
– Learning bad behavior using the GO TO keyword
• Paragraphs as blocks of code
– Designing the content of a paragraph
– Order and naming of paragraphs
• Program control with paragraphs
– PERFORM TIMES
– PERFORM THROUGH
– PERFORM UNTIL
– PERFORM VARYING
• Using subprograms
– Specifying the target program
– Specifying program variables
– Specifying the return value
• Summary
84
analyze and read. Although COBOL does contain these structures, it is important to use them sparingly and
not as the backbone of well-structured code.
Well-structured code is both easy to understand and to maintain. It is highly likely that at some point in
your career you will be required to read and work from someone else’s code, often a decade after it was
originally written. It would be extremely helpful to you if the original author structured their code well and
likewise if it is your code someone else is reading.
...
85
STOP RUN .
86
PERFORM VARYING COUNTER FROM 01 BY 1 UNTIL COUNTER EQUAL 11
MOVE COUNTER TO MSG - TO - WRITE
WRITE PRINT - REC
END - PERFORM .
Example 5. GO TO example
If we were to compile and run the program, you would see that although the job ABENDS (abnormally ends)
with a 4038-abend code, it did execute some of the code and wrote the first two lines of the output. If you
were to look at the output in more detail, you would see a message like the following:
IGZ0037S The flow of control in program TOTEN1 proceeded beyond the last
line of the program .
87
0 01 FLAG PIC 9(1) VALUE 1.
88
Note: A paragraph can also be ended by END-PROGRAM, END-METHOD, END FACTORY OR END-
OBJECT. Most of these are used within Object Orientated COBOL which is not discussed here.
Considering that a program can be made up of multiple paragraphs and that the PERFORM keyword can
be used to call the paragraph, either conditionally or as part of a loop, it is easy to see that good paragraph
design really helps makes your COBOL more structured and readable.
89
PERFORM 4000 - READ - RECORD
END - PERFORM .
*
3000 - CLOSE - STOP .
CLOSE ACCT - REC .
CLOSE PRINT - LINE .
STOP RUN .
*
4000 - READ - RECORD .
READ ACCT - REC
AT END MOVE 'Y ' TO LASTREC
END - READ .
*
5000 - WRITE - RECORD .
MOVE ACCT - N - TO ACCT - NO - O .
MOVE ACCT - LIMIT TO ACCT - LIMIT - O .
MOVE ACCT - BALANCE TO ACCT - BALANCE - O .
MOVE LAST - NAME TO LAST - NAME - O .
MOVE FIRST - NAME TO FIRST - NAME - O .
MOVE COMMENTS TO COMMENTS - O .
WRITE PRINT - REC .
90
11.4.1 PERFORM TIMES
Perhaps the simplest way of repeating a perform statement is to use the TIMES keyword to perform a
paragraph or sections of code a static number of times, shown in Example 10.
PERFORM 10 TIMES
MOVE FIELD - A TO FIELD - B
WRITE RECORD
END - PERFORM .
91
Example 13. PERFORM UNTIL
This would be equivalent to the Java code:
while ( counter != 10) {
// counter ++
// move counter to msg - to - write
// write print - rec
}
92
// write print - rec
}
}
93
Note: When passing variables either BY REFERENCE or BY CONTENT, note you can send data items of
any level. Which means you can pass entire data structures, handy for dealing with common records.
You might also see the phrase, BY VALUE, being used in a CALL sentence. BY VALUE is similar to BY
CONTENT, as a copy of the content of the variable is passed. The difference is that only a subset of COBOL
datatypes are supported and you can only specify elementary data-items. This is because BY VALUE is
primarily used when COBOL is calling a program of another language (such as C).
11.6 Summary
In summary, this chapter should provide the necessary foundation to understand structured programming
and how it relates to COBOL and its importance to understanding and maintaining code. Many examples of
how, when and why to implement key techniques have been provided and explained for further understanding.
You should be able to identify the basic differences between structured programming (COBOL) and OO
programming (Java). You should also understand the general concept of the best practices in the structure of
the Procedure Division with reference to the design and content of paragraphs, program control options and
ways to call other programs within the same system.
94
12 File output
Designing a structured layout that is easy to read and understand is required to format output. Designing a
structured layout involves column headings and variable alignment using spaces, numeric format, currency
format, etc. This chapter aims to explain this concept utilizing example COBOL code to design column
headings and align data names under the such headings. At the end of the chapter you are asked to complete
a lab that practices implementation of the components covered.
A capability of COBOL data output formatting that is worth noting but not covered in this chapter is that
COBOL is a web enabled computer language. COBOL includes easy and quick transformation of existing
COBOL code to write JSON (JavaScript Object Notation) where the output is sub-sequentially formatted for
a browser, a smartphone, etc. Frequently, the critical data accessed by a smart phone, such as a bank balance,
is stored and controlled by z/OS where a COBOL program is responsible for retrieving and returning the
bank balance to the smart phone.
• Review of COBOL write output process
– ENVIRONMENT DIVISION
• FILE DESCRIPTOR
– FILLER
• Report and column headers
– HEADER-2
• PROCEDURE DIVISION
– MOVE sentence
– PRINT-REC FROM sentences
• Lab
95
12.2.1 FILLER
Observe the data name FILLER. While most data fields have unique names, FILLER is a COBOL reserved
word data name, that is useful for output formatting. This is in part because FILLER allocates memory
space without the need for a name. Also, FILLER allocated memory has a defined length in the output line
and may contain spaces or any literal. Figure 2. shows multiple VALUE SPACES for FILLER. SPACES
create white space between data-items in the output which is valuable in keeping the code readable. More
specifically in Figure 2. FILLER PIC X(02) VALUE SPACES, represents the output line containing two
spaces.
Figure 2. FILLER
96
Figure 3. Designed output structure layout
12.3.1 HEADER-2
HEADER-2 includes the year, month, day of the report together with FILLER area, creating blank spaces
between the year, month, and day, as you can see in Figure 3. Figure 4. is an example of the data name
layout used to store the values of CURRENT-DATE. The information COBOL provides in CURRENT-DATE
is used to populate the output file in HEADER-2.
97
Figure 5. Execution logic to write header layout structure
12.5 Lab
This lab utilizes two COBOL programs, CBL0004 and CBL0005, located within your id.CBL data set, as
well as two JCL jobs, CBL0004J and CBL0005J, located within your id.JCL data set. The JCL jobs are used
to compile and execute the COBOL programs, as discussed in previous chapters. #### Using VSCode and
Zowe Explorer
1. Submit job: CBL0004J
2. Observe the report written with headers like Figure 6. below.
98
4. Observe the report data lines are written without dollar currency symbol, illustrated in Figure 7.
99
13 Conditional expressions
This chapter dives into how programs make decisions based upon the programmer written logic. Specifically,
programs make these decisions within the PROCEDURE DIVISION of the source code. We will expand on
several topics regarding conditional expressions written in COBOL through useful explanations, examples
and eventually practicing implementation through a lab.
• Boolean logic, operators, operands, and identifiers
– COBOL conditional expressions and operators
– Examples of conditional expressions using Boolean operators
• Conditional expression reserved words and terminology
– IF, EVALUATE, PERFORM and SEARCH
– Conditional states
– Conditional names
• Conditional operators
• Conditional expressions
– IF ELSE (THEN) statements
– EVALUATE statements
– PERFORM statements
– SEARCH statements
• Conditions
– Relation conditions
– Class conditions
– Sign conditions
• Lab
100
A list of COBOL Boolean relational operators for each of the common type of COBOL conditional expressions
are represented in Figures 1, 2 and 3 below.
101
This conditional expression evaluates to false because while 5 > 1 is true, 1 > 2 is false. The AND operation
requires both expressions to be true to return true for the compounded condition expression. Let’s show
another implementation, this time using the OR Boolean operator.
IF (5 > 1 OR 1 > 2)THEN .... ELSE ....
This conditional expression evaluates to true because while 1 > 2 is false, 5 > 1 is true. The OR operation
requires only one of the expressions to be true to return true for the entire compounded condition expression.
More conditional operators used for relation, class, and sign conditions are discussed further on in the chapter.
102
MOVE 'TX ' TO USA - STATE .
....
....
IF STATE DISPLAY ' The State is Texas '
ELSE DISPLAY ' The State is not Texas '
END - IF .
103
Relational operator Can be written Meaning
IS LESS THAN OR EQUAL TO IS <= Is less than or equal to
104
13.4.3 PERFORM statements
A PERFORM with UNTIL phrase is a conditional expression. In the UNTIL phrase format, the procedures
referred to are performed until the condition specified by the UNTIL phrase evaluates to true. Using the
FACIAL-EXP conditional-name, the SAY-SOMETHING-DIFFERENT paragraph is executed continuously
UNTIL FACIAL-EXP contains ‘HAPPY’, observe Example 5.
PERFORM SAY - SOMETHING - DIFFERENT BY FACIAL - EXP UNTIL ' HAPPY '
END - PERFORM .
13.5 Conditions
A conditional expression can be specified in either simple conditions or complex conditions. Both simple
and complex conditions can be enclosed within any number of paired parentheses; the parentheses, however,
do not change whether the condition is simple or complex. This section will cover three of the five simple
conditions:
• Relation
• Class
• Sign
105
• Numeric
– IS NUMERIC or IS NOT NUMERIC
• Alphabetic
– IS ALPHABETIC or IS NOT ALPHABETIC
– IS ALPHABETIC-LOWER / ALPHABETIC-UPPER
– IS NOT ALPHABETIC-LOWER / ALPHABETIC-UPPER
• DBCS
– IS DBCS or IS NOT DBCS
– IS KANJI or IS NOT KANJI
13.6 Lab
This lab requires two COBOL programs, CBL0006 and CBL0007 and two respective JCL Jobs, CBL0006J
and CBL0007J, to compile and execute the COBOL programs. All of which are provided to you in your
VSCode - Zowe Explorer. #### Using VSCode and Zowe Explorer:
1. Take a moment and look over the source code of the two COBOL programs provided: CBL0006 and
CBL0007.
2. Compare CBL0006 with CBL0005 from the previous lab. Do you notice the differences?
a. Observe the new CLIENTS-PER-STATE line within the WORKING-STORAGE > PROCEDURE
DIVISION.
b. Observe the new paragraph IS-STATE-VIRGINIA within that same division.
c. This paragraph checks whether the client is from Virginia. If that condition is met (true) then the
program should add 1 to the clients from Virginia total.
d. Program writes “Virginia Clients = “, in last line of report.
3. Submit CBL0006J
4. View the job output from the JOBS section and verify the steps mentioned above were executed.
106
5. Submit CBL0007J
6. Find the compile error, IGYPS2113-E, in the job output.
7. Go ahead and modify id.CBL(CBL0007) to correct the syntax error outlined by the IGYPS2113-E
message.*
8. Re-submit CBL0007J
9. Validate that the syntax error was corrected by getting an error free output file.
107
14 Arithmetic expressions
This chapter aims to introduce the concept of implementing arithmetic expressions in COBOL programs.
We will review the basic concept of arithmetic expressions, operators, statements, limitations, statement
operands, as well as precedence of operation within the expressions. You will be able to follow along with a
comprehensive example exhibiting the usage of arithmetic expressions in a COBOL program that you have
seen in previous chapters and labs. Following the chapter is a lab to practice the implementation of what you
have learned.
• What is an arithmetic expression?
– Arithmetic operators
– Arithmetic statements
• Arithmetic expression precedence rules
– Parentheses
• Arithmetic expression limitations
• Arithmetic statement operands
– Size of operands
• Examples of COBOL arithmetic statements
• Lab
108
Binary operator Meaning Unary operator Meaning
- Subtraction - Multiplication by -1
Multiplication
/ Division
Exponentiation
14.2.1 Parentheses
Parentheses are used to denote modifications to normal order of operations (precedence rules). An arithmetic
expression within the parentheses is evaluated first and result is used in the rest of the expression. When
expressions are contained within nested parentheses, evaluation proceeds from the least inclusive to the most
inclusive set. That means you work from the inner most expression within parentheses to the outer most.
The precedence for how to solve an arithmetic expression in Enterprise COBOL with parentheses is:
1. Parentheses (simplify the expression inside them)
2. Unary operator
3. Exponents
4. Multiplication and division (from left to right)
5. Addition and subtraction (from left to right)
Parentheses either eliminate ambiguities in logic where consecutive operations appear at the same hierarchic
level or modify the normal hierarchic sequence of execution when necessary. When the order of consecutive
109
operations at the same hierarchic level is not completely specified by parentheses, the order is from left to
right.
An arithmetic expression can begin only with a left parenthesis, a unary operator, or an operand (that is, an
identifier or a literal). It can end only with a right parenthesis or an operand. An arithmetic expression must
contain at least one reference to an identifier or a literal.
There must be a one-to-one correspondence between left and right parentheses in an arithmetic expression,
with each left parenthesis placed to the left of its corresponding right parenthesis. If the first operator in
an arithmetic expression is a unary operator, it must be immediately preceded by a left parenthesis if that
arithmetic expression immediately follows an identifier or another arithmetic expression.
110
ROUNDING and ON SIZE ERROR handling.
Figure 3. READ-NEXT-RECORD.
Figure 4. is an example of two COMPUTE statements in the paragraph, LIMIT-BALANCE-TOTAL. Notice
that the results of the COMPUTE statements are to add client ACCT-LIMIT to the current TLIMIT and
add client ACCT-BALANCE to TBALANCE totals each time the paragraph is executed, which is one time
for each client record read in our example.
111
Figure 5. WRITE-TLIMIT-TBALANCE
14.6 Lab
This lab requires two COBOL programs, CBL0008 and CBL0009 and two respective JCL Jobs, CBL0008J
and CBL0009J, to compile and execute the COBOL programs. All of which are provided to you in your
VSCode - Zowe Explorer. #### Using VSCode and Zowe Explorer
1. Take a moment and look over the source code of the two COBOL programs provided: CBL0008 and
CBL0009.
2. Submit CBL0008J
3. Observe report written with trailers consisting of limit and balance totals at the bottom of the output.
112
15 Data types
A COBOL programmer must be aware that the computer stored internal data representation and formatting
can differ, where the difference must be defined in the COBOL source code. Understanding the computer’s
internal data representation requires familiarity with binary, hexadecimal, ASCII, and EBCDIC. Packed-
Decimal is needed to explain COBOL Computational and Display data format. This chapter aims to
familiarize the reader with these different “types” of data representation.
• Data representation
– Numerical value representation
– Text representations
• COBOL DISPLAY vs COMPUTATIONAL
• Lab
113
COMP-3 exactly represents values with decimal places. A COMP-3 value can have up to 31 decimal digits.
#### COMP-4
COMP-4 is only capable of representing integers. Compared to COMP-1 and COMP-2, COMP-4 can store
and compute with integer values exactly (unless a division is involved). Although COMP-3 can also be used
to represent integer values, COMP-4 is more compact. #### COMP-5
COMP-5 is based on COMP-4, but with the flexibility of specifying the position of a decimal point. COMP-5
has the space efficiency of COMP-4, and the exactness of COMP-3. Unlike COMP-3, however, a COMP-5
value cannot exceed 18 decimal digits.
15.1.2.1 ASCII American Standard Code for Information Interchange, ASCII, is another binary digit
character encoding standard.
15.1.2.2 EBCDIC vs ASCII Why are these two standards when they seemingly perform the same
function?
EBCDIC is a standard that traces its root to punch cards designed in 1931. ASCII, on the other hand, is a
standard that was created, unrelated to IBM punch cards, in 1967. A COBOL program natively understands
EBCDIC, and it can comfortably process data originally captured in punch cards as early as 1931.
ASCII is mostly utilized by non-IBM computers.
COBOL can encode and process text data in EBCDIC or ASCII. This means a COBOL program can
simultaneously process data captured in a census many decades ago while exporting data to a cloud service
utilizing ASCII or Unicode. It is important to point out, however, that the programmer must have the
awareness and choose the appropriate encoding.
15.3 Lab
Many of the previous COBOL lab programs you have worked with thus far are reading records containing two
packed decimal fields, the client account limit and the client account balance. In the Arithmetic expressions
lab, the total of all client account limits and balances used a COMPUTE statement, where the COMP-3
fields contained the packed decimal internal data.
What happens when an internal packed decimal field is not described using COMP-3? Without using COMP-3
to describe the field, the COBOL program treats the data as DISPLAY data (EBCDIC format). This lab
demonstrates what happens during program execution without using COMP-3.
114
15.3.0.1 Using VSCode and Zowe Explorer
1. Submit the job, id.JCL(CBL0010J)
2. Observe that the compile of the COBOL source was successful, however, also observe that the execution
of the job failed. How can you tell?
There’s no CC code next to CBL0010J(JOB#), instead there is an ABENDU4038 message. U4038 is a
common user code error typically involving a mismatch between the external data and the COBOL
representation of the data.
3. Read the execution SYSOUT message carefully. The SYSOUT message mistakenly believes the records
are 174 characters in length while the program believes the records are 170 characters in length.
Explanation: Packed decimal (COMP-3) expands into two numbers where only one number would
typically exist. If the program reads a packed decimal field without describing the field as COMP-3, then
program execution becomes confused about the size of the record because the PIC clause, S9(7)V99, is
expecting to store seven numbers plus a sign digit when only three word positions are read. Therefore,
execution reports a four-record length position discrepancy.
4. Edit id.CBL(CBL0010) to identify and correct the source code problem.*
5. Submit id.JCL(CBL0010J) and verify correction is successful with a CC 0000 code.
Lab Hints:
The ACCT-LIMIT PIC clause in the ACCT-FIELDS paragraph should be the same as the PIC clause for
ACCT-BALANCE.
115
16 Intrinsic functions
Today’s COBOL is not your parents COBOL. Today’s COBOL includes decades of feature/function rich
advancements and performance improvements. Decades of industry specifications are applied to COBOL
to address the growing needs of businesses. What Enterprise COBOL for z/OS promised and delivered, is
decades of upward compatibility with new releases of hardware and operating system software. The original
DNA of COBOL evolved into a powerful, maintainable, trusted, and time-tested computer language with no
end in sight.
Among the new COBOL capabilities is JSON GENERATE and JSON PARSE, providing an easy to use
coding mechanism to transform DATA DIVISION defined data-items into JSON for a browser, a smart phone,
or any IoT (Internet of Things) device to format in addition to transforming JSON received from a browser,
a smart phone, or any IoT device into DATA DIVISION defined data-items for processing. Frequently, the
critical data accessed by a smart phone, such as a bank balance, is stored and controlled by z/OS where a
COBOL program is responsible for retrieving and returning the bank balance to the smart phone. COBOL
has become a web enabled computer language.
Previous COBOL industry specifications included intrinsic functions, which remain largely relevant today.
An experienced COBOL programmer needs to be familiar with intrinsic functions and stay aware of any new
intrinsic functions introduced. This chapter aims to cover the foundation of intrinsic functions and their
usage in COBOL.
• What is an intrinsic function?
– Intrinsic function syntax
– Categories of intrinsic functions
• Intrinsic functions in Enterprise COBOL for z/OS V6.3
– Mathematical example
– Statistical example
– Date/time example
– Financial example
– Character-handling example
• Use of intrinsic functions with reference modifiers
• Lab
116
01 Item -1 Pic x (30) Value " Hello World !".
01 Item -2 Pic x (30) .
. . .
Display Item -1
Display Function Upper - case ( Item -1)
Display Function Lower - case ( Item -1)
Move Function Upper - case ( Item -1) to Item -2
Display Item -2
117
Example 2. Mathematical intrinsic function
118
16.2.5 Character-handling example
Example 6. shows used of COBOL function UPPER-CASE where an string or alphabetic variable processed
by UPPER-CASE will translate any lower case characters to upper case.
MOVE FUNCTION UPPER - CASE (" This is shouting !") TO SOME - FIELD
DISPLAY SOME - FIELD
Output - THIS IS SHOUTING !
LNAME (1:1)
LNAME (4:2)
16.4 Lab
This lab contains data that includes a last name, where last name is all upper-case. It demonstrates the use
of intrinsic functions together with reference modification to lower-case the last name characters, except the
first character of the last name.
This lab requires two COBOL programs, CBL0011 and CBL0012 and two respective JCL Jobs, CBL0011J
and CBL0012J, to compile and execute the COBOL programs. All of which are provided to you in your
VSCode - Zowe Explorer. #### Using VSCode and Zowe Explorer
1. Submit job, CBL0011J.
2. Observe the report output, last name, with first character upper-case and the remaining characters
lower-case.
Figure 1. , below, illustrates the difference in output from the Data types lab compared to this lab.
Notice that in the previous lab, the last names were listed in all capitalized characters, whereas, as
previously stated, this lab output has only the first character of the last name capitalized.
119
3. Observe the PROCEDURE DIVISION intrinsic function, lower-case, within the WRITE-RECORD
paragraph. This intrinsic function is paired with a reference modification resulting in output of last
name with upper-case first character and the remainder in lower-case.
4. Submit CBL0012J
5. Observe the compile error.
Previous lab programs made use of a date/time intrinsic function. The date/time intrinsic function in this
lab has a syntax error that needs to be identified and corrected.
6. Modify id.CBL(CBL0012) correcting compile error.*
7. Re-submit CBL0012J
8. Corrected CBL0012 source code should compile and execute the program successfully. A successful
compile will result in the same output as CBL0011J.
Lab Hints
Refer to CBL0011 line 120 for the proper formatting of the function-name causing the compile error.
120
Part 3 - VSCode alternatives and testing
17 Installing IBM Developer for Z
This chapter covers all aspects of download and installation of IBM Developer for z/OS and any prerequisites
that are needed. It includes:
• Install prerequisites
– Hardware prerequisites
– Software prerequisites
– Download and install IBM’s Installation Manager
• Install product offerings through IM
• Summary
121
• Admin install: imLauncherWindows.bat
The process of installing Installation Manager runs unattended. After it’s finished, click Restart Installation
Manager to install the product.
122
Figure 2. Configuration options
9. Click Next and then Finish
Note: The version numbers in our examples are provided purely for reference and may not reflect the latest
versions of the software.
17.3 Summary
In this chapter we have walked through the process of downloading and installing IBM’s Installation Manage.
Which was subsequently used to walk through a series of dialogs to install IDz.
123
18 Enabling IBM Developer for Z to work with COBOL
In this chapter we will explain how to use IDz and its COBOL-specific language-sensitive-editor as an
alternative to other editors mentioned in this book. We will also cover how using the editor can help you
develop COBOL source code in a feature rich environment.
• Introduction to IDz
– What is IDz?
– IDz architecture
– Installing the IDz client
• Basic editing in IDz
– Launch IDz
– Overview of the IDz/Eclipse workspace and tools
– Accessing code on the mainframe - open a COBOL program
– COBOL program syntax highlighting
– Navigating within a COBOL file
– Working with COBOL source
– Saving your work
– Working in Full Screen Mode
– Code-completion (Content Assist)
– Handling syntax errors - the IDz COBOL Parser
• Access to batch jobs - launch and view results in JES
• Summary
124
• Drag and drop files from one z/OS logical partition (LPAR) to another or from workstation to z/OS
and vice versa.
• Intelligent and advanced remote edit / save and compile.
125
Figure 2. IDz workspace directory selection
Note: a “Workspace” is a collection of folders on your PC that contain and manage your IDz client
development environment, tools, preferences, etc.
126
• The Workspace contains several Perspectives and a perspective is a defined layout for your tools - which
are called Views.
• A View is a singular tool for working on some aspect of a z/OS application. There are hundreds of IDz
Views, each has a purpose, and in this book, we will use a subset of these views:
– Editor - a view used to create or modify code
– Remote Systems - a view for accessing code that resides on a mainframe
– Properties - a view that shows you the attributes of something (often a file characteristics)
– z/OS Projects - a view used to organize specific files for faster access
127
Figure 5. Warning message
128
Figure 6. CBL0001 sample program
129
Figure 7. Outline view hyper-links
### Working with COBOL source
The Editor contains several dozen tools for doing efficient/effective development work with COBOL programs.
None of the tools are difficult to use, but in this book, we concentrate on the tools & techniques needed for
introductory COBOL programming.
Before doing any development, you could press (simultaneously) Ctrl+Shift+M. This hot-key combination
turns on COBOL line-number management - and will keep the sequence numbers in columns 7380 from
shifting to the left and causing syntax errors. #### Basic source editing functionality:
• How to change an existing line:
– Select a line with your mouse cursor and type-over the existing statement.
– Note that the standard MS-Windows Shift+Home, Shift+End keys work.
• How to delete a line:
– To Delete a line, select the line and delete it with the Delete key on your PC.
– Or select the line and press: Ctrl+X , this will cut the line copying it to your clipboard.
• How to add a line:
130
– To add a line, click your mouse-cursor at the right-most end of the line (but to the left of the
green COBOL sequence numbers in columns 73 80) and press Enter.
131
Figure 9. Double-Click the Editor View tab to enter Full-Screen mode
132
Figure 12. Pressing Ctrl+Spacebar to view & select COBOL keywords
133
2. We then modified portions of the file in order to build the program/code, shown in Figure 14.
3. Submit the JCL to a z/OS subsystem called JES (Job Entry Subsystem) by right clicking and selecting
Submit from the menu that appears, as shown in Figure 14.
Fig-
ure 14. Submitting a JCL file
4. After submitting the JCL, there will be a prompt to locate the job from a job submission confirmation
pop-up, see Figure 15. Here, you would select Locate Job .
134
Figure 15. Locate the Job after submission
5. Then navigate down to the JES elements in the Remote Systems view, open the job like Figure 16
shows and inspect the job results.
18.4 Summary
In this chapter, you have been able to go through some of the key editing features of the IDz. These
capabilities make editing COBOL, PL/I, JCL, Assembler, SQL and several other z/OS software languages
(Java, JavaScript, HTLM, JSON, etc.) a little easier.
We’ve covered, in this chapter, less than 5% of what IDz has to offer for the z/OS professional. To learn more:
• IBM instructional videos on IDz:
https://developer.ibm.com/mainframe/videos/
• Ongoing IBM (free) Remote Instructor-led training on IDz:
https://developer.ibm.com/mainframe/idzrdz-remote-training/
135
19 Using ISPF to work with COBOL
In this chapter we will explain how to use the tools of ISPF to develop COBOL source code, submit and
manage jobs.
• Introduction to TSO/ISPF
– What is TSO/ISPF?
– TSO vs. ISPF
– TSO/ISPF in the real world
– ISPF emulation architecture
– Accessing the 3270-Emulator
• Basic editing
– Launch IDz
– Access TSO/ISPF from IDz
– Log in to ISPF
• Overview of the ISPF primary option menu
– What if my cursor becomes stuck in the user interface?
– Edit entry panel
– ISPF edit
– Navigating within a COBOL file
– Working with COBOL source - Prefix Area
– Saving your work
• Access to batch jobs - launch and view results in JES
– Steps - using the same basic workflow as edit
• Summary
136
19.1.3 TSO/ISPF in the real world
Every company’s ISPF uses a base set of tools and features, but then customizes the interface; adding, changing
or uninstalling features they feel are necessary for optimal use in their business/technical environment.
Standard ISPF functionality includes:
• Access to MVS files, z/OS Unix and JES artifacts using 3270-data stream (character-based) emulator.
– Note that there are several ISPF emulation packages available. In this chapter, we’ll be demon-
strating and discussing ISPF using IDz’s “Host Connection Emulation”, which is a free component
of IDz.
– Ultimately, all the host ISPF software functionality is the same, so it won’t matter much which
product you use.
• Issue z/OS commands directly.
• Submit and manage z/OS “batch jobs” - executables that run unattended on the mainframe.
• Create new z/OS Datasets, members, Unix files and folders.
• Edit MVS files and Datasets.
– Primary focus of this chapter.
You would be responsible for installing the emulator on your machine. Your company’s systems administration
staff would be responsible for installing and configuring the server listener on z/OS. In this book you
spent nearly 100% of your time performing COBOL development activities, primarily; program edit and
compile/link/run coding and testing programs.
The ISPF Emulation architecture is depicted in Figure 1. Note that definitions of terms like RACF/ACF-2
and Top Secret (along with JES, CICS, REXX, etc.) can be found on the web.
137
Figure 1. ISPF Emulation-z/OS architecture
138
Figure 2. Accessing IDz’s built-in emulator
139
Figure 5. TSO “waiting for Enter messages or”prompts"
Note: The TSO system messages may contain important information, such as the disposition of a submitted
job.
140
Every shop will have some small variation on the ISPF primary menu, but for now let’s type the number two
on the Option line and press Enter, as shown in Figure 7.
•
Figure 8. IDz 3270 control keys
141
This will bring up the PDS member selection screen (Figure 10. ). Note that you did not have to enter:
.CBL. This is because ISPF knows your TSO logon and automatically prefixes it before file names on the
dialog input lines, if the file name isn’t surrounded by apostrophes.
On the selection screen, hit the tab key three times and type an S next to CBL0001, then press Enter .
This will open CBL0001 with the ISPF screen where we can edit the source, shown in Figure 12.
Figure 9. Edit (option 2) dialog (entry panel) - where you select a file to edit
Figure 10. The PDS member selection screen - where you select (S) the file you want to edit
When the file initially opens you will probably get some warning text, which can be removed by typing res
on the command line and pressing Enter , shown in Figure 11.
142
Figure 12. ISPF editor
143
Figure 13. Issuing command line commands
144
Figure 14. Series of Prefix Area commands “stacked” or issued simultaneously
145
JCL = Job Control Language - A mainframe computing language that controls the running of “batch”
jobs. A JCL file consists of JCL statements.
JES = Job Entry Subsystem - An area in a mainframe that handles the running of “batch jobs”.
Batch Job - Work done on a mainframe in a non-interactive mode - overnight financial processing, updates
to online databases and systems, etc.
146
19.5 Summary
In this chapter we have walked through some of the editing features using TSO/ISPF and the ISPF editor.
These capabilities ease editing COBOL, PL/I, JCL, Assembler, SQL and several other z/OS software languages
(REXX, CLIST, etc.).
We’ve covered in this chapter less than 5% of what ISPF offers for the z/OS professional. To learn more,
there are several quality books on the subject and videos available on YouTube.
• A link to an excellent instructional video on ISPF:
https://www.youtube.com/watch?v=vOiHiI7b9iY
147
20 Testing
In this chapter, we focus on the importance of thoroughly testing software to ensure its quality. No language
or program is exempt from the importance of testing and automated testing, including programs written in
COBOL. The chapter explains how this can only be achieved in an effective and efficient way by automating
the testing as part of a continuous delivery pipeline and introduces a framework that can enable such
automation.
We will look at some of the background to software testing and the different types of testing, the value to an
enterprise of using a continuous integration/continuous delivery pipeline, why automation is vital in CI/CD
pipelines, and the risks of not adopting automation.
• Importance of testing
– What is testing and why do it?
– What is unit testing?
– What is function/integration/system testing?
– The role of exploratory testing
• Basics of continuous integration, continuous delivery
– Introduction to DevOps and CI/CD pipelines
– Focus on efficiency and automation through the pipeline
– Tests as the quality gatekeeper through phases of the pipeline
– Managing the pipeline when test cases fail
• Testing on z/OS
– Importance of testing on z/OS
– Challenges for test automation on z/OS
• Why does this matter?
– Value of automated testing in continuous delivery
– Dangers of not automating testing
– Risks of not adopting continuous delivery
– Use of automated testing for system reliability
• How can test automation be achieved on z/OS?
148
Put simply, software testing can be described as verification of the system or application under test. Cem
Kaner offers this definition:
“Software testing is an empirical technical investigation conducted to provide stakeholders with information
about the quality of the product or service under test.”
20.1.2 What is unit testing?
Unit testing is the earliest phase of testing and validates that an individual unit or component of a software
solution performs as designed. Unit testing is typically carried out by the developer who wrote the code
within the unit or component under test, along with other early validation activities such as static analysis
and code review. That is not to say that the unit tests created by the developer might also be re-run at later
stages in the software lifecycle, to validate that the individual units still behave as intended.
Unit testing is important because the earlier defects can be found (or avoided), the less resource is required
to resolve them. A problem found early might be corrected by simple editing in minutes, whereas the same
problem found later might require a lot of rewriting and re-testing. Unit testing also often takes advantage of
the developer’s knowledge of the internals of the unit or units being tested.
The unit tests that are created as part of unit testing can also be very important, if they are designed in such
a way that they can be run and re-run later in the development cycle, to validate that the behavior of the
software units is still correct.
149
Figure 1. Agile Testing Quadrants (from http://tryqa.com/what-are-test-pyramid-and-testing-quadrants-in-
agile-testing-methodology/ )
Martin Fowler and Mike Kohn have discussed the concept of a Test Pyramid (see ’The Practical Test Pyramid’:
https://martinfowler.com/articles/practical-test-pyramid.html), which emphasizes the importance of a
wide base of many small unit tests, then built upon that a set of equally important but less numerous tests
that Mike Cohn called ‘Service Tests’. At the top of the pyramid are ‘End to End tests’, which include user
interface tests, and which test the entire system from end to end. Service tests covers a similar scope of
testing as Integration Testing but is a term which has not gained much traction, and in our usage Integration
Testing covers all the pyramid above the unit tests.
This chapter is not going to attempt to provide definitive definitions of the various types of testing but will
use ‘Integration Testing’ as an umbrella term to cover much of the testing that occurs after development and
which lends itself to automation. This is where individual units of software are tested together, as well as
being tested with other components including external parts of the system. Such tests are usually run in an
environment that matches some aspects of the ultimate target environment for the software. Included within
‘Integration Testing’ are regression testing, functional testing, system testing, U.I. testing, end-to-end testing,
user acceptance testing, performance testing.
A distinction should be made between types of testing and types of tests . Unit tests for example can, and
should, be run during later test phases, especially as part of regression testing.
150
product’, which is covered nicely in this post: https://www.testingexcellence.com/exploratory-testing-
important-agile-projects/ .
Exploratory testing is often referred to as being a ‘thinking’ activity. It is also sometimes referred to as
ad-hoc testing, but in reality, it is a much more directed and organized activity than being purely ad-hoc.
This type of testing makes the best use of the skills of the tester, but clearly by its very nature does not lend
itself to automation. The value of automation of testing lies in freeing the tester from the need to manually
carry out repetitive and un-thinking testing.
151
Figure 2. Representation of a DevOps pipeline
In Figure 2, after planning for the next release, based on user input, and potentially analyzing the code to
understand where to introduce the changes, the coding phase begins. The developer will write, build and
unit test the code, gradually adding in function and ensuring that it works as an individual unit as intended,
using their preferred IDE and preferred tools for source code management, dependency resolution, etc. When
the code is ready, it will be delivered into the pipeline, which uses an artifact repository to manage the
process. The software now enters the testing phases, where the test environments are provisioned (or might
already exist), the code changes are deployed into the environment to be tested, and tests are run. The tests
might, themselves, drive the provisioning and deployment, or this might be done separately. This phase of
the pipeline is an iterative process, moving through different levels of testing, often in different environments.
When failures occur, they need to be efficiently diagnosed, and if needed, the code will be amended, rebuilt,
and unit tested again. Feedback from users will be sought during this phase, to ensure that what is being
delivered meets their needs. When the code change has successfully passed all the required phases of testing,
it will be released to production. The software changes and the production environment will continue to be
monitored and planning for the next release can begin. Figure 2 illustrates some of the tools and products
that might be used to implement the various stages of the pipeline.
Some of these building blocks are probably in place at many enterprises, but it is likely that most of the
activities are carried out in a manual way and it is the lack of automation of those steps that slows delivery.
A DevOps pipeline can only be efficient, or indeed practical, if it can be automated.
152
This testing also needs to be carried out continuously, as each change is delivered. ‘Continuous testing’
has been described as being a process of “testing early, testing often, testing everywhere, and automate”
(https://www.guru99.com/continuous-testing.html).
A key principle of the move to DevOps and a CI/CD pipeline is that as much of the testing as possible needs
to be automated. Also, it is not just the tests themselves that need to be automated, but also the checking of
whether the tests have passed.
Some quotes on the importance of test automation:
“To achieve such speed and agility, it is important to automate all the testing processes and configure
them to run automatically when the deployment is completed in the QA environment.” From https:
//www.softwaretestinghelp.com/devops-and-software-testing/
“Test automation has become crucial to keep quality control intact while maintaining the speed of releases.”
From https://dzone.com/articles/role-of-test-automation-in-devops
DevOps can simply not succeed if it still requires a large number of test cases to be run manually.
However, not all testing can or should be automated. Exploratory testing might well follow different paths as
a result of what is discovered during the process. Penetration testing often relies on innovation and trying
something new, which is difficult to automate. User acceptance testing will often involve users interacting
with the system in a flexible way.
Testing versus Checking
Testing is an interactive activity that involves evaluating whether software meets its purpose, by exploring
and experimenting with its behavior. This requires human creativity and cannot be automated. What is
possible to automate is the checking that the software meets these expectations that we have discovered
by testing. James Bach and Michael Bolton introduced this distinction between testing and checking (see
https://www.satisfice.com/blog/archives/856): “we distinguish between aspects of the testing process that
machines can do versus those that only skilled humans can do. We have done this linguistically by adapting
the ordinary English word “checking” to refer to what tools can do.".
When we speak of testing in this chapter from this point on, we are referring to what would more strictly be
called checking, rather than testing.
The key point is that anything that lends itself to automation should be automated, to allow time for these
other activities where automation is genuinely not appropriate. The fact that something is quite difficult to
automate should not be used as an excuse for failing to automate it.
153
to relying on the inherent reliability, security and resilience of the platform, such companies also carry out
extensive testing before introducing any change.
154
to respond very rapidly to new market opportunities and threats, and to have confidence in the quality and
robustness of the services that you provide.
155