Streamline your mainframe development with Zowe Explorer & Zowe CLI (a series): Part 2 — COBOL basics

Alex Dumitru
Zowe
Published in
4 min readJul 21, 2020

{Core} In the previous article “Streamline your mainframe development with Zowe Explorer & Zowe CLI” we looked at shell scripting on z/OS Unix. Now let’s take a shot at COBOL. We’ll be covering the Open Mainframe Project’s Zowe Explorer and Command Line Interface (CLI).

I am not a COBOL developer, but I wanted to try it out, so I started the Open Mainframe COBOL training. I am at “Hello World”, and nailing it. So far so good :). But something is still missing…

I have to navigate to different places to get things going. I want to sit with the source code in front and trigger the build automatically without going through the trees, submit the JCL, and check the spool files.

Here I have a similar approach to what I’ve set up in the last article, but with a little twist. Instead of submitting local files, I want to use the JCLs provided. The reason is that the structure of the project is as follows:

HLQ.CBL(MEMBER) - contains source code
HQL.JCL(MEMBER) - contains compilation jobs

and there is a 1 to 1 parity for the member names*. This means I can just extract the member name from CBL dataset and use it to submit the JCL counterpart.

My solution revolves around Powershell, as I said before, and also, I am expecting that you are already comfortable using VS Code, Zowe Explorer and Zowe CLI to work with your z/OS files.

Let’s jump to the implementation:

  • I am creating a new task in VS Code by using Tasks: Open User Tasks from the command palette. There I am adding a new task, which I will call Compile COBOL and set it to run a Powershell script.
  • I am Creating a Powershell script that takes some arguments. In our case, the local file path (mandatory) and an optional one specifying the profile you want to use with Zowe CLI.
  • The helper-functionsmodule was updated with the Get-Member_Name function and params.json is pretty much the same.
  • this needs to be present next to the Powershell script. Otherwise, you might want to check out the official documentation to place it in the default location pointed out by PSModulePath environment variable if you want to import it as any other Powershell module.
  • for the params.json file, I have chosen to structure it this way, because I want to use it with more scrips. You can choose to split it in separate files, or as you see fit. You might have noticed that importing this in Powershell is very easy, and accessing the parameters is equally convenient using the dot notation.
  • Some parameters explained:
    keepSpool (boolean)= choose if you want to keep the downloaded spool files or not
    defaultStdout (string) = path to STDOUT spool file (can vary based on submitted job)
    defaultProfile (string) = if not passed from task, this Zowe CLI profile will be used
    outputJcl (string) = file name where the script will write the templated JCL before submitting
    jobCard (object) = holds parameters relevant to parameterize your JCL job card
  • (optional, but recommended) Bind the task to a keyboard key combo. In order to do that, I am going to the command palette and look for Preferences: Open Keyboard Shortcuts (JSON). In there, I am adding the Compile COBOL task as such:
  • key : add your own combo
  • command : leave unchanged, because it points to VS Code tasks
  • args : has to be the name of your task (see label parameter in your task definition)

And once again, I am done. Now whenever I edit a COBOL source for this project, I only have to press CTRL+SHIFT+C to submit the compilation job on the remote system and get the output in my local VS Code console.

End result**:

Notes:

  • * since this was modeled after the COBOL course, you might need to change a few things here and there. For example, going beyond hello world , for CBL0001 you might need to alter the script and param file. Some compilation jobs actually have an extra “J” appended to the name, so you would need to add some kind of control statement
    if ($memberName.StartsWith("CBL00"){
    $memberName = $memberName + "J"
    }

    after $memberName = Get-Member_Name -localFilePath $args[0]
  • also, the output file for CBL0001 changed, so I added a new param "prtline" : "\\RUN\\PRTLINE.txt" in params.json and also used it in Get-Content-Path ".\$jobid$($params.cblcomp.prtline)" instead of using defaultStdout
  • ** I’ve cut some frames to make the gif faster because there is some wait time (couple of seconds) to get the result in the console

If you enjoyed this blog checkout more Zowe blogs here. Or, ask a question and join the conversation on the Open Mainframe Project Slack Channel #Zowe-dev, #Zowe-user or #Zowe-onboarding. If this is your first time using the OMP slack channel register here.

This blog is part 2 of “Streamline your mainframe development with Zowe Explorer & Zowe CLI (a series)”.

Full list:

--

--

Alex Dumitru
Zowe
Writer for

Software Developer at Broadcom and Zowe Project Contributor.