Beginner’s Guide: COBOL Made Easy (Leveraging Open Source Tools)
By: Jessielaine Punongbayan
Tags: Cobol, Open Source, Automation, Zowe, Mainframe

In my previous blog, I talked about Zowe Explorer and the different VSCode extensions that we could use in writing COBOL programs. Today, I want to integrate other open source projects like Zowe CLI and CircleCI to create solutions that can help us in our development.

What is Zowe?

Zowe, a project hosted by Open Mainframe Project, is an open source project that offers modern interfaces to interact with z/OS and allows you to work with z/OS in a way that is similar to what you experience on cloud platforms today. It helps young developers today to interact and work with mainframe using the development tools that they know and love. It is a modern solution for modern mainframe developers

“What is Zowe CLI?”

Zowe CLI is the Zowe Command Line Interface that allows you to access Mainframe through Zowe APIs. It contains different z/OS packages that enables you to get data from datasets, DB2, CICS, MQ, IMS and many more. It also allows you to create plugins so that you can customize the CLI experience based on your needs.

Before we begin…

Disclaimer: I am a Broadcom Software Engineer and I am part of the Zowe Development team. This is my personal point-of-view and my own personal preference. There are other open source tools that you can use to achieve similar results.

Photo by Jose Aragones on Unsplash

I would like to make sure that:

You have Mainframe and Zowe access. If you don’t have one, please read through this blog to obtain one. We are using the same tools. This blog gives you an introduction of the tools that I am using.

Once you are done, let’s move on.

“Mise en place”

Mise en place is a French culinary phrase which means “putting in place” or “everything in its place”. It refers to the setup required before cooking, and is often used in professional kitchens to refer to organizing and arranging the ingredients.

Similar to programming, we need to prepare everything we need before we can start.

What are the things that we need?

We need our modules. I have created the following Source and JCLs and I’ve uploaded it my Github repository:

*****************************************************************

🤓📚 What is a Github Repository? GIT is a version control software. If I am going to put it in a Mainframe reference, Github Repository is like CA Endevor or IBM SCLM.

*****************************************************************

2. We need a goal. In this blog, I have 2 goals:

Goal #1: Use NPM scripts and leverage Zowe CLI commands

Goal #2: Use CircleCI to create a CI/CD that will compile and run our program automatically.

Goal # 1: Scripts

Photo by Luca Bravo on Unsplash

Creating NPM scripts are fairly easy. All I do is create a package.json and write the Zowe CLI commands that I wanted to use.

*****************************************************************

🤓📚 In case you are wondering…

What is NPM? It is a software registry where Open Source developers registers their software packages. Once the software is registered in NPM, other developers can import these packages and use them in their own applications. For more info, please visit their website.

What is a package.json? This is a file that holds various metadata that is used by NPM. It gives out relevant information about the project such as project information, project dependencies and as well as scripts.

What are NPM scripts? Similar to bash scripts or python scripts, NPM scripts are scripts that are executed using NPM RUN <Script Name> . These are added and defined in package.json.

*****************************************************************

To achieve my goal, I would need the following commands:

Upload my program in Mainframe: This can be achieved by running the upload command (file-to-dataset)

zowe files upload ftds <source location> <target location>

Submit my Compiler: In Zowe, you can submit a JCL that is saved in your machine. All you have to do is use the Submit Command (local-file)

zowe jobs submit lf <source location> --directory <output location>

I wanted to download the results after submitting my job. So I will add the directory parameter so it will automatically download the results in the location that I specified.

Submit my Run JCL: Lastly, I want to test my program. Similar to point # 2 I will use the Submit Command (local-file).

⚠️ But did you know that Zowe CLI offers 3 different ways to submit a JCL? You can do it via datasets that resides in mainframe, via local file and via STDIN. Cool right? 😉

For example:

Submitting a job via datasets: zowe zos-jobs submit data-set “ibmuser.cntl(deploy)”

Submitting a job via local-file: zowe zos-jobs submit local-file “iefbr14.txt”

Submitting a job via stdin: zowe zos-jobs submit stdin

I have customized some of my scripts and if you want to know more about it, I have added it in this list.

As a bonus, I also added a build script:

"build": "npm run generate && npm run upload:cobol && npm run compile:cobol && npm run run:cobol"

This script allows me to:

Generate my COBOL Program and JCLs

Upload the COBOL Program to mainframe

Submit my Compiler and

Submit my Run JCL

I wanted to have a “one-click” process to compile and test my program. With the help of NPM scripts and Zowe CLI commands, I am able to do that. This can also help me achieve my Goal # 2.

After this, I commit all my changes to Github and continue working on my next goal.

Goal # 2: CI/CD using CircleCI

I would assume that you know about CircleCI. If not, you check them out in this link. There is also a step-by-step instruction on how to set-up your project here.

Why CircleCI? The reason I chose this tool is because it is free and it is easy to use. Also, they provided docker images where NodeJS and NPM are already installed. This allowed me to focus more on the Zowe installation and testing of my programs.

I have spent a fair amount time trying to figure out the correct way to install Zowe CLI in CircleCI and this is what I ended up having. You may use this config file or you may enhance it (then share it with me afterwards… 😄)

With this configuration, it allowed me to:

Install Zowe CLI

Create a Zowe Profile using my environment variables

Run my build

Similar to the preparation and manual testing that I do in my machine, I built my config file as follows:

Step # 1–3: CircleCI pre-made steps: This will build the docker environment and check-out the code from Github.

Step #4: Check Versions: This is where I check the NodeJS and NPM version that I have.

Step #5: Install Zowe: Using NPM, I installed the latest @zowe/cli package.

Step #6: Install Packages: I installed all the devDependencies I stated in my package.json

Step #7: Compile Scripts: I created some scripts to automatically generate my JCL and Cobol Programs by substituting the variables I have in my config/default.json. In order for this to work, I need to compile it.

To know more information about these scripts, please check out this blog.

Step #8: Create Zowe Profiles: I needed a profile to execute my Zowe CLI commands in mainframe. This is an optional step because the information in the profiles can also be added in the Zowe CLI commands.

Step #9: Build and Test: This executes the “one-click” script that I added earlier. I just wanted it in one step that is why I decided to write it in this way. This can also be separated into multiple steps depending on your preference.

After a successful build, I added a CircleCI badge 😃

and Github Checks.

So now, every time I add changes in my source modules and I commit it to my Github Repository, the CircleCI build will be automatically triggered and I will be updated if it passes or not.

What’s that? What if you are using CA Endevor and your source modules are there? No worries. Here is a blog that uses Zowe CLI and Endevor in building your CI/CD pipeline. 😮

Summary

So what have we learned today?

We learned how to write NPM scripts

We learned that you can use Zowe CLI commands and add it as a script.

We learned that you can combine different NPM scripts to create a “one-click” script so you can build, test and deploy all your modules in one go.

We learned how to create a CircleCI project.

We learned how to create a CircleCi config file that installs Zowe CLI and runs Zowe CLI commands.

We learned to add checks and add a badge for easier verification of CI/CD builds.

I hope you had a fun time learning today! Until next time! 👋