IBM Z and LinuxONE - IBM Z

IBM Z

The enterprise platform for mission-critical applications brings next-level data privacy, security, and resiliency to your hybrid multicloud.

 View Only

Introducing COBOL Code Generation in IBM watsonx Code Assistant for Z

By LATRELL FREEMAN posted 20 hours ago

  

We’re excited to introduce a new COBOL code generation capability in IBM watsonx Code Assistant for Z. This blog will walk you through the powerful new features that bring generative AI to mainframe application development. You’ll see how to use natural language to generate COBOL code, leverage in-editor completions to streamline development, and apply AI to make modifications existing programs.

Before we dive into the features, let’s talk about what you’ll need to get started. The COBOL code generation experience is built into Visual Studio Code, and requires the following two extensions:

Z Open Editor – Provides COBOL language server support for syntax validation, code navigation, and editing.

watsonx Code Assistant – Enables the chat interface.

With these installed, you’ll be ready to take full advantage of both natural language prompts and intelligent in-editor suggestions inside your COBOL source files.

Natural Language Meets COBOL

One of the key ways IBM watsonx Code Assistant for Z helps you write COBOL is through its chat interface, where you can use plain English to describe what you want to build or modify. Whether you’re creating new logic or modernizing existing programs, the assistant understands your intent and responds with accurate COBOL code suggestions.

Let’s look at how this works in practice.

To get started, you can prompt the assistant with a request like:

“Generate a cobol program that creates a container with container name as WS-CONTAINER-NM , FROM WS-CHILD-RETURNED-DATA, FLENGTH LENGTH OF WS-CHILD-RETURNED-DATA and WS-CHAN-NAME as channel name”

The assistant will generate a complete COBOL program, along with additional context to explain the code that was generated:

Next, let’s revise the generated code. You can enter a follow-on prompt such as:

“Let's limit the container and channel names to 8 characters”

The assistant will update the relevant sections based on your input. It’s normal, and advised to go through several rounds of follow-ons and refinements until the code meets your expectations. Once you’re satisfied, you can use the “Insert at cursor” button to place the final version directly into your COBOL file.

If you later decide to make further changes to the program you previously inserted, you can simply reference the existing code in your workspace and ask the assistant to update it. For example, you might say:

"Update @CreateContainer.cbl to move CICS PUT CONTAINER to a new paragraph called STORE-DATA, and also create create a CICS GET CONTAINER statement in a separate paragraph called RETRIEVE-DATA"

The AI assistant will analyze the existing logic, understand its structure, and return an updated version of your code.

AI Completions Right Inside Your Editor

Beyond the chat interface, IBM watsonx Code Assistant for Z also enhances your in-editor experience with inline completions for COBOL. These completions are context-aware, meaning they take into account the surrounding code to generate accurate and relevant suggestions.

Multi-line completion can be triggered intentionally to generate full code blocks based on inline comments. Add a comment like:

"* Insert row into Customer table based on customer number"

Then place your cursor below the comment, aligned with your desired indentation, and press Option + , (on Mac) or Alt + , (on Windows). The assistant will suggest multiple lines of code relevant to your intent. While adding a comment is optional, it provides helpful context that can guide the model to generate more accurate and relevant suggestions. Press Tab to accept the suggestion and insert it into your file.

Single-line completion works automatically as you type. For example, begin typing a MOVE statement, and after a short pause, the rest of the statement is predicted and filled in.

Single-line completions can also be triggered when your cursor is on a new line…even before you start typing, allowing the assistant to predict a full statement based on the surrounding context.

These in-editor completions allow for fast, context-aware coding without interrupting your workflow.

Mainframe Meets Modern AI

With these new capabilities, COBOL development becomes faster, easier, and more intuitive. Developers can now rely on a helpful AI assistant not just to write new code, but to modify and improve legacy programs...all from right inside their editor. And this is just the beginning. We’re continuing to evolve with even more enhancements on the way, including support for additional Z languages, the introduction of coding agents, and multilingual support to make the assistant accessible to an even broader range of developers.

0 comments
8 views

Permalink