IBMi(AS/400) Reverse API Cobol Client Deployment
This guide provides step-by-step instructions for compiling and deploying an OpenLegacy-generated COBOL program with HTTP API support on IBM i using the HTTPAPI library.
Prerequisites
Make sure you have the following:
- IBM i (iSeries/AS400) OS version 7.1 or newer
- ILE COBOL compiler
- HTTPAPI library installed and in your library list - Follow the link above. Download and follow the installation instructions HTTPAPI
- OLREVAPI RPGLE service program (compiled)
OLAPICPY.CPY
copybook file from OpenLegacy- The COBOL program source generated by OpenLegacy
- The minimal permissions needed are *USE authority on each library and required source, *ADD and *OBJMGT authority on the target library for creating or updating objects, and *USE authority on all referenced modules and service programs.
Step 1: Configure API Parameters
Edit the OLAPICPY.CPY
copybook to specify your server URL and any required API key.
Set the API Endpoint
Locate or add URL:
05 OLREVAPI-URL PIC X(512) VALUE
Multi-line URL: To break a long URL into multiple lines, continue with a hyphen in column 7 of each following line:
05 OLREVAPI-URL PIC X(512) VALUE 'https://'
- 'your-api-url.amazonaws.com'
- '/apps/your-api-uri'.
Use Environment Variables
To set the URL at runtime via an environment variable:
05 OLREVAPI-URL PIC X(512) VALUE "ENVVAR:YOUR_ENV".
Set the API Key
If your API requires an x-api-key
:
05 OLREVAPI-API-KEY PIC X(32) VALUE 'your-api-key'.
Copy the updated OLAPICPY.CPY
to your source physical file member (e.g., MYLIB/QCBLLESRC
).
Step 2: Update the COBOL Program
Copy your COBOL source to the correct member in your source physical file.*
Step 3: Create the COBOL Module
Add the Library where you copied the copybook from Step 1
ADDLIBLE MYLIB
Run the following command to compile your COBOL module:
CRTCBLMOD MODULE(MYLIB/COBOL_CLIENT)
SRCFILE(MYLIB/QCBLLESRC) SRCMBR(COBOL_CLIENT)
OUTPUT(*PRINT) DBGVIEW(*ALL)
PGMINFO(*PCML *MODULE)
Replace MYLIB
and COBOL_CLIENT
with your actual library and program names.
Explanation: This command compiles your COBOL source member into an ILE module on IBM i. The module is an intermediate compiled object, which you will later bind with other required modules and service programs. Setting
DBGVIEW(*ALL)
enables comprehensive debugging information for troubleshooting.PGMINFO(*PCML *MODULE)
includes metadata useful for interoperability and debugging.
Step 4: Add the HTTPAPI Library
Before linking, add HTTPAPI to your library list:
ADDLIBLE LIBHTTP
Explanation: The IBM i system uses a library list to locate required objects during compilation and binding. Adding the HTTPAPI library makes its service programs (such as
HTTPAPIR4
) available for linking, ensuring your program can call HTTP functions at runtime.
Step 5: Link and Create the Program
Finish by creating the program and binding the necessary modules and service programs:
CRTPGM PGM(MYLIB/COBOL_CLIENT)
MODULE(MYLIB/COBOL_CLIENT SERVICE_LIB/OLREVAPI)
BNDSRVPGM((HTTPAPIR4 *IMMED))
Replace MYLIB
and COBOL_CLIENT
with your actual library and program names.
Replace SERVICE_LIB
as appropriate for your system.
Explanation: This step links your COBOL module (
MYLIB/COBOL_CLIENT
) and the OLREVAPI service program (SERVICE_LIB/OLREVAPI
) into an executable ILE program. TheBNDSRVPGM((HTTPAPIR4 *IMMED))
directive immediately binds the HTTPAPI runtime service, enabling REST/HTTP calls from your COBOL logic. Confirm all libraries and object names are correct before running this command.
Updated about 12 hours ago