COBOL and PL/I preprocessor support by IBM Z® Open Editor
by Ankit Kumar
10 December 2024
I remember sweating through my eyebrows trying to recall the conventional code while writing my final Computer Science paper in High School - that was 11 years back. Happy spirited, youthful me thought things would change in Engineering College; but no - Pseudo Code was still a nightmare.
Years later, here I am, redeeming myself - writing this blog as a member of the team that developed Preprocessor support for COBOL and PL/I. We, at IBM, have packaged brevity and precision for mainframe developers. You can write non standard COBOL code (custom statements) and IBM Z® Open Editor will ensure that everything gets converted to standard COBOL code and your code is a success (Well, you need to ensure that your preprocessor does not have any errors, that’s not on us!)
If you are new to IBM Z® Open Editor - it is a Visual Studio Code extension that combines the out-of-the-box capabilities of VS Code with language support for popular z/OS® programming languages. IBM Z® Open Editor uses Zowe Explorer APIs for interacting with z/OS® and has been doing so since the beginning
When do you use the Preprocessor?
Use a preprocessor when you want to use custom syntax instead of the ones written in stone. You can extend COBOL and PL/I to integrate with other technologies with custom statements. These statements often have to be translated to complex standard COBOL or PL/I and a preprocessor support will help to keep development simple. Check out the example preprocessor and code samples in our Github repository at https://github.com/ibm/zopeneditor-sample/tree/wazi-main/preprocessor. Review the Readme file in this folder with detailed instructions for building and running the sample.
Can you use the Preprocessor on your machine and on z/OS® systems?
Absolutely! You can execute it on your machine (local) and on z/OS® systems (remote) - we are bringing the full package for you!
What do you need to integrate your Preprocessor with IBM Z® Open Editor?
Locally, the preprocessor should run on your development machine and be executable via the command line, producing an output file with valid COBOL by appending a new file extension to the program file name.
Remotely, it should execute on a z/OS® machine, typically using a REXX
or CLIST
program. A configured RSE API or z/OSMF Zowe profile must be available, and the processor should run via a Zowe TSO command, generating an output data member with valid COBOL or PL/I. The program file needs to reside in a recognized PDS for COBOL (or PL/I), with the corresponding language support active in IBM Z® Open Editor.
What is a ZAPP Profile and why do you need it?
Using ZAPP (Z APPlication) files is a new approach for simplifying how developers and teams of developers can configure their application code for editing in IBM Z® Open Editor.To specify command lines for executing a preprocessor in the background and integrating the output with the editor. ZAPP files support variable substitution. You can define variables inside VS Code settings and use those variables inside a ZAPP file.
How do you run the preprocessor?
One can run the preprocessor the old fashioned way, by doing Right-click and selecting Execute local preprocessor command
for local files and Execute remote preprocessor command
for remote files. Or you could Automatically run the preprocessor via the VS Code user setting zopeneditor.autoPreprocessor
. When the preprocessor command runs, a progress dialog with a Cancel
button is displayed. When the preprocessor finishes, it refreshes the editor and any syntax errors that were caused by preprocessor statements should go away or, if they contained problems, will show those instead. If the processor command execution failed and produced errors, a dialog will be shown with a button to open the IBM Z® Open Editor log file viewer which lists the detailed error message produced by the preprocessor command.
Executing local preprocessor.
Executing remote preprocessor.
How do you use the preprocessor output in the editor?
After the preprocessor is executed, you can hover the mouse of preprocessor statements in their program file to see the code that was generated for the statement. You can edit these statements and all other code in the program. Syntax errors for preprocessor statements will not be available until the preprocessor runs again. Syntax errors for other regular COBOL or PL/I code will be shown while typing as usual in IBM Z® Open Editor. To get a side-by-side view of the program before and after preprocessing, you can use the right-click menu option Compare preprocessor input and output files
.
How do you extend the use of preprocessor for expanding PL/I macros?
Developer for z/OS provides a sample REXX exec, FEKRNPLI
, that can be called by the Developer for z/OS client to expand PL/I source by invoking the PL/I compiler which is located by default in FEL.SFELSAMP(FEKRNPLI)
. So, using this exec you can run all the macro statements to resolve them. The execution of preprocessor remains the same and is supported with all the features and functionalities of preprocessing.
Resolving PL/I macros.
Learn More
This blog was meant to give you a high-level overview of what Preprocessor feature brings to the table. Many available actions are not covered here and it is receiving new features and capabilities with each release. Try it out, and if there is a missing feature that you would like to be added, you can create an enhancement request on the IBM Z® Open Editor public repository. For more information on the Preprocessor, see its documentation.