Calling JAVA from CLLE
In this topic, we will walk through how to invoke a Java program from a CL program on IBM i. This is useful for integrating Java-based logic into legacy RPG or CL workflows.
Step 1: Define the Java Classpath
Before calling the Java program, we need to set the CLASSPATH environment variable to include all necessary JAR files and directories.
CHGVAR VAR(&CP) +
VALUE ('/$/VendorASN/bin:/$/jars/activation. +
jar:/$/jars/ccf.jar:/$/jars/ccf2.jar:')
Note: Use CHGVAR to dynamically build the classpath string. Make sure all paths are accessible and correct. Here VendorASN is project name and bin contains all the libraries used by project.
Step 2: Set the Environment Variable
Use ADDENVVAR to set the CLASSPATH environment variable for the job.
ADDENVVAR ENVVAR(CLASSPATH) VALUE(&CP) REPLACE(*YES)
This ensures the Java runtime knows where to find your classes and libraries.
Step 3: Call the Java Program
Use the RUNJVA command to invoke your Java class. Here’s how:
RUNJVA CLASS (main.DoImport) CLASSPATH(&CP) + CHKPATH(*IGNORE) OPTIMIZE (40) + PROP ((java.awt.headless 'true')) + JOB(ASN001C1) OUTPUT(*PRINT)
Explanation:
CLASS(main.DoImport): Specifies the Java class to run. CLASSPATH(&CP): Uses the classpath we defined earlier. CHKPATH(*IGNORE): Ignores path checking. OPTIMIZE (40): Sets optimization level. PROP(...): Sets Java system properties. - JOB(...): Runs under a specific job name. - OUTPUT(*PRINT): Sends output to spool file.
Step 4: Handle Errors Gracefully
Use MONMSG to catch and handle Java-related errors.
MONMSG MSGID(JVAB534 JVAB535 JVAB537 JVAB539 JVAB53A +
JVAB53B JVAB53D JVAB546 JVA0122) EXEC(DO)
Customize the EXEC(DO) block to log errors or notify users.
Summary
This approach allows seamless integration of Java logic into IBM i workflows. Whether you are processing files, sending emails, or interacting with external systems, Java can extend the capabilities of your CL programs.
Java JAR setup in IFS
Folder Structure Setup
Begin by creating a folder with the project name in the home directory. Inside this folder, create the following subfolders:
- Config – for configuration files
- Logs – for log files
- Lib – for library files including the JAR file
Shell Script Setup
Create a file named ‘start.sh’ in the project folder. This script is used to start the Java application. Below is an example command for the JavaPoc project, which should be the content of start.sh file:
cd /home/ JavaPoc && /QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/jre/bin/java -Xquickstart -Xshareclasses:nonfatal -Xscmx128m -jar lib/programmers.io-JavaPOC.jar
Modify the folder name and JAR file name according to your project setup.
Configuration File Setup
In the ‘Config’ folder, create a file named ‘application.yml’ with the following content:
spring:
main:
banner-mode: "off"
output:
ansi:
enabled: never
logging:
file: logs/JavaPoc.log
Ensure the syntax remains unchanged and update the log file name as per your project.
Library Folder
Place the required JAR file in the ‘Lib’ folder. This JAR file contains the compiled Java application.
IBM i Command Execution
Execute the following commands on the IBM i system to set environment variables and submit jobs:
ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) VALUE(*NONE)
SBMJOB CMD(QSH CMD('/home/JavaPoc/start.sh')) JOB(JavaPoc) JOBQ(QSYSNOMAX)
Update the folder names and job names accordingly to match your specific project setup.
Final Notes
This document outlines the steps required to set up a Java Jar on IFS. Each step is crucial for ensuring the application runs smoothly on the IBM i system. Make sure to customize folder names, file names, and job names as per your project requirements.
Running Node js in IBM i
Overview
IBM i is a robust business platform known for its stability, security, and integrated database. Modernizing with Node.js allows leveraging agile web technologies without sacrificing the strengths of IBM i. Node.js is a high-performance, event-driven JavaScript runtime built for scalable network applications, and it integrates seamlessly with IBM i resources and legacy programs.
Why Choose Node.js on IBM i?
Business and Technical Advantages:
- Modernization: Bridges legacy RPG/Cobol with new web, API, and mobile experiences—without a full platform migration
- Performance: Node.js uses a non-blocking I/O model, handling many simultaneous requests efficiently.
- Open Source Ecosystem: Access to npm’s extensive package library fast-tracks development and innovation
- Integration: Directly interact with Db2 for i, RPG service programs, and other IBM i resources
- Cost Efficiency: Modernizes interfaces without rewriting stable business logic.
- DevOps & Automation: Native support for CI/CD pipelines using tools like Jenkins and Git
- Future-proofing: Ensures IBM i systems remain competitive by enabling cloud-ready, scalable apps
Environment Prerequisites
- IBM i Version: 7.2 or newer (recommended for better open source support).
- Open Source Environment: Must be enabled (via yum package manager).
- Network Access: Ensure SSH is enabled for remote terminal access (STRTCPSVR *SSHD command).
Node.js Installation and Configuration
Install Node.js on IBM i
- Start Open Source Package Management:
- Using IBM Access Client Solutions (ACS), select your LPAR, go to “Actions > Management > Open Source Package Management”.
- Install Node.js Using yum:
- Open a PASE or SSH terminal.
-
Set the environment path (if needed):
PATH=/QOpenSys/pkgs/bin:$PATH export PATH -
Run:
yum install nodejs22
NOTE: Node installation is one time only.
-
To verify:
node -v npm -v -
If multiple Node.js versions are present:
alternatives --config node
Set Up Project Directory
- Open a PASE shell or SSH terminal (CALL QP2TERM).
- Create and enter your Node.js project directory:
mkdir mynodeapp cd mynodeapp
- Initialize the project:
init -y
- Install required npm modules:
npm install express
For database or IBM i integration(the below includes ODBC):
yum install ibm-iaccess
Sample Node.js Application
Example: Express Web Server
Note: Please change CCSID of your IFS file to UTF-8(ccsid-1208), then add the contents in file. create an IFS file named app.cjs, without writing any entry, save and exit
Execute the given CL command:
CHGATR OBJ('/your/file/path/app.cjs') ATR(*CCSID) VALUE(1208)Then, write the below contents into app.cjs file, if browsing through green screen.
const express = require('express'); const PORT = 3000; const app = express(); app.get('/', (req, res) => { res.send('Hello world!'); }); app.listen(PORT, () => { console.log(`Listening on port ${PORT}.`); });Save as app.cjs in your project directory. ( .cjs is to specify the environment that it is common js type file if /$your_path/package.json file does not have “type” : “module” being mentioned )
Running the Node.js Application
Start PASE/SSH Terminal
- 5250 Session:
CALL QP2TERM
- Or, SSH Terminal
Launch App
In your project directory:
node app.cjs
You should see the “Listening on port 3000” log.
Run as a Background Service
Optionally, execute Node.js in the background using a shell script:
-
Create start_node.sh in IFS working directory having below content:
#!/bin/bash node app.cjs >> ‘/path/to/logfile/data.log’ 2>&1 & echo "Node.js script finished. Output logged to data.log file"Here, 1st line is to inform the operating system which interpreter should be used to execute the script.
2nd line breakdown of each component:
- node app.cjs: This part executes the Node.js application specified in the app.cjs file.
- >> ‘/path/to/logfile/data.log’: This redirects the standard output (stdout) of the node app.cjs command to a file specified, or, creating if doesn’t already exists.
- 2>&1: This redirects the standard error (stderr) to the same location as the standard output (stdout). File descriptor 2 represents stderr, and 1 represents stdout. The & before 1 indicates that 1 is a file descriptor, not a file name.
- &: This symbol at the end of the command tells the shell to run the preceding command in the background. This frees up the terminal, allowing you to execute other commands while the Node.js application continues running independently.
3rd line is to simply notify given message in interactive screen.
-
Make script executable:
chmod +x /path/to/your/sh_file/start_node.sh
-
Run script:
./start_node.sh
Verify Running Process(if long running process):
ps -ef | grep node
Accessing IBM i-specific Resources in Node.js
Install the IBM i toolkits:
npm install itoolkit odbc
Verify if ODBC driver is installed by executing command in QP2TERM/PASE env:
odbcinst -j
If nothing is display in response, install odbc using the below script:
yum install ibm-iaccess
Verify ODBC driver installation, by executing script:
odbcinst -j
Example: Query the local DB2 database
Create a node.js file named run_qry.js in your working IFS directory with the below content:
const odbc = require('odbc'); odbc.connect('DSN=*LOCAL', (error, connection) => { if (error) throw error; connection.query('SELECT * FROM PIOLIB.TESTFILE', (error, result) => { if (error) throw error; console.log(result); }); });Note: Please change CCSID of your IFS file to UTF-8(ccsid-1208), then add the contents in file.
Make sure ODBC is installed, Then, invoke the below script:
node run_qry.js
Additional Configuration
- Adjust firewall rules to open selected Node.js ports.
- Integrate with IBM HTTP Server for i using FastCGI add-on for advanced web setups.
- Use update-alternatives to switch Node.js versions if multiple are installed
- 5250 Session:
Running Python in IBM i
Introduction
Python is a versatile and widely used open-source programming language that has been officially integrated into the IBM i operating system. This integration allows developers to leverage Python’s extensive libraries and modern programming paradigms to build applications, utilities, and integrations that interact with traditional IBM i resources like DB2 for i, RPG, and CL programs.
Python on IBM i runs within the Portable Application Solutions Environment (PASE), which is an AIX-like environment that allows the system to run applications compiled for AIX. This enables the use of open-source tools and languages, including Python, on IBM i.
Importance of Python Integration in IBM i
The integration of Python with IBM i is crucial for a number of reasons:
- Modernization: It allows IBM i shops to modernize their application development by using a popular, agile, and expressive language.
- Access to Open Source Ecosystem: Python provides access to a massive ecosystem of libraries and frameworks for web development, data analysis, automation, and more. This allows developers to quickly build powerful new functions on IBM i.
- Interoperability: Extensions like itoolkit and ibm_db enable Python scripts to seamlessly interact with DB2 for i, call RPG programs, and execute CL commands.
- Automation: Python is an excellent tool for automating system administration tasks, data transfers, and other operational processes on the IBM i.
Installing Python in IBM i
The recommended method for installing Python on IBM i is by using the yum package manager. This approach is much more streamlined than manual installation.
- Ensure PASE and yum are available: Python requires the Portable Application Solutions Environment (PASE), which is available through product numbers 5770SS1 option 33 and 5733SC1. You will also need the yum package manager. If yum is not installed, you can install it via the “Open Source Package Management” option in IBM i Access Client Solutions (ACS) or by following the instructions from IBM.
- Open a shell session: You can access the PASE environment by using one of the following
methods:
- SSH: Connect to your IBM i system via SSH.
- QP2TERM: Run the CALL QP2TERM command from a 5250 session.
- QSH: Use the qsh command from the 5250 command line.
- Install Python: Use the yum command to install the desired version of Python. For example,
to install Python 3.9, you would run:
yum install python39
This command will install Python and its dependencies from the IBM i open source repositories. Note that yum install python3* is also a valid command.
- Add to PATH (Optional but Recommended):To make it easier to run Python commands, you can
add the directory /QOpenSys/pkgs/bin to your system’s PATH environment variable.
This allows you to run python39 or python3 without specifying the full path.
PATH=/QOpenSys/pkgs/bin:$PATH export PATH
- Package Management with pip:
The Python package installer, pip, is available and works as expected on IBM i. It is used to install
third-party libraries and packages from the Python Package Index (PyPI).
Use the pip command to install a package. It’s best practice to use the versioned command with pip to ensure
you are using the correct Python environment.
python -m pip install
Validating Python Installed Version
To verify that Python has been installed correctly and to check its version, you can use a simple command in your shell session.
python --version
Creating Python Scripts
Python scripts are plain text files with a .py extension. You can create and edit these files using a variety of methods:
- Integrated File System (IFS): You can use an IFS-aware text editor, such as VS Code with the IBM i extensions, or even the EDTF command from a 5250 session.
- CL Command: The EDTF STMF(‘/path/to/your_script.py’) command can be used to create and edit files directly on the IFS.
- Network Drive: If you have the IFS mapped as a network drive, you can use any local text editor to create and save the file.
When creating your script, it’s best practice to set the CCSID of the file to a Unicode-friendly encoding like 1208 (UTF-8). This helps prevent issues with special characters.
Here is a simple “Hello, World!” example script (hello.py):
# hello.py
print("Hello, IBM i World!")
Executing Python Scripts
Once your Python script is created, you can execute it from the PASE environment using a shell session (SSH, QP2TERM, etc.).
The basic command for executing a Python script is:
Python /path/to/your_script.py
A simple way to run a Python script from a CL program is to use :
QSH CMD('python3 /path/to/your_script.py')
Here are some of the most practical uses of Python scripts for IBM i automation:
- Database Operations and Data Integration
- ETL (Extract, Transform, Load) Processes:Python’s data manipulation libraries like pandas can be used to extract data from DB2 for i, transform it, and load it into another database (e.g., SQL Server, Oracle, or a data warehouse) or vice versa. This is crucial for integrating IBM i data with other enterprise systems.
- Automated Reporting: Python scripts can query DB2 for i, perform complex calculations, and then generate reports in various formats like Excel spreadsheets (openpyxl, pandas), CSV, or PDF. These reports can be automatically emailed to stakeholders, eliminating manual report generation.
- Data Synchronization: Python can be used to keep data in sync between IBM i and other platforms. For example, a script could monitor a table on IBM i for new records and automatically push them to a REST API or a cloud service.
- File and Spool File Management
- Automated File Transfers: Python’s built-in ftplib or a more secure library like paramiko (for SFTP) can be used to automate file transfers between IBM i and other servers. This is perfect for scheduling the delivery of reports or the collection of data files.
- Spool File Conversion and Distribution: Scripts can read and process spool files (like invoices or reports) on IBM i, convert them to modern formats like PDF, and then automatically email or archive them. This can significantly reduce the need for physical printing and manual handling.
- System and Job Management
- Monitoring and Alerting: A Python script can monitor system performance metrics, job logs, or specific data queues. If a certain condition is met (e.g., a job fails, a disk threshold is reached), the script can send an email, a text message, or an alert to a monitoring system.
- Scheduled Job Submission: While CL is used for job scheduling, Python scripts can be triggered to submit jobs and perform pre- or post-job checks and actions. This allows for more complex, conditional workflows.
- Automated Cleanup Tasks: Scripts can be set up to clean up old files, clear temporary libraries, or perform routine maintenance on a schedule, ensuring system health and performance.
- Application Modernization and Integration
- Web Services and API Integration: A major use case is for Python to act as a bridge between the traditional IBM i environment and modern APIs. A Python script running on IBM i can call a REST API to get or send data, allowing legacy RPG or CL programs to interact with cloud services like Salesforce or ServiceNow without being rewritten.
- Calling RPG and CL Programs: Python scripts can seamlessly interact with traditional IBM i programs using tools like the itoolkit or by calling them from the command line. This allows developers to create modern interfaces or automation tools that leverage existing business logic.
- Development and DevOps
- Automated Testing: Python can be used to write automated test scripts that interact with IBM i applications. This can include anything from database integrity checks to screen scraping for verifying application behavior, which is essential for a robust CI/CD pipeline.
- Source Code Management: Python scripts can be used to pull source members from IBM i libraries to a local machine and commit them to a Git repository, and also to push them back to the IBM i. This helps to modernize the development process and provides a clear version history for source code.
Key Enablers for Python on IBM i
- IBM i Open Source Technologies: IBM has made it easy to install and use Python and other open-source languages directly on the IBM i operating system via the yum package manager.
- ODBC/JDBC Drivers and Libraries: The IBM i Access ODBC driver and Python libraries like pyodbc or ibm_db provide a robust way to connect to and interact with the DB2 for i database.
- Python Toolkits: The itoolkit (Python XMLSERVICE Toolkit) is a powerful library that allows Python to call and execute IBM i commands and programs, making it a central component for automation.