Elevating IBMi Development: Unleashing the Power of PASE for i System Utility with Python
Introduction:
In the ever-evolving landscape of technology, developers are constantly seeking innovative solutions to enhance their workflow and streamline processes. IBM's Power Systems have long been at the forefront of enterprise computing, and with the introduction of the Portable Application Solutions Environment (PASE) for i, developers now have a powerful ally for seamlessly integrating their Python prowess with the robust IBMi ecosystem.
Understanding PASE for i
PASE for i is a system utility that provides a Unix-like environment on IBM Power Systems. It opens up a realm of possibilities for developers by allowing them to leverage familiar tools and scripting languages, including Python, in the IBMi environment. This bridging of worlds brings forth a multitude of benefits, making development on the IBMi platform more flexible, efficient, and enjoyable.
Harnessing the Power of Python
1. Cross-Platform Compatibility
One of the standout advantages of using Python with PASE for i is the cross-platform compatibility it offers. Python code written for other platforms can be seamlessly adapted and executed on the IBMi system. This means developers can leverage their existing Python skills and codebase, promoting code reuse and reducing development time.
2. Rich Ecosystem of Libraries
Python boasts a vast ecosystem of libraries and frameworks that cater to a wide range of functionalities. By integrating Python with PASE for i, developers can tap into this extensive library pool, bringing advanced capabilities to their IBMi applications. Whether it's data analysis, machine learning, or web development, the possibilities are virtually limitless.
3. Streamlined Development Workflow
PASE for i eliminates the need for developers to switch between different environments, providing a unified and streamlined development workflow. With Python seamlessly integrated into the IBMi ecosystem, developers can code, test, and deploy applications more efficiently, boosting overall productivity.
Getting Started with Python and PASE for i
1. Installing Python on IBMi
Getting started is straightforward. IBM provides clear documentation on installing Python in the PASE environment. Once installed, developers can access the power of Python right from their IBMi command line.
2. Executing Native Commands and Program Calls
Python scripts can interact with native IBMi commands and program calls, enabling developers to automate routine tasks, extract valuable insights, and enhance system management. This integration ensures that the full potential of the IBMi platform is unlocked with the expressive simplicity of Python.
Check out IBM's documentation here
Here is my code to build a data area directly from a python script. The code goes on to display the data area and then change it.
# Documentation on IBM's website
# https://www.ibm.com/docs/en/i/7.3?topic=utilities-pase-i-system-utility
#
# -K forces a joblog
# -i Run the CL command in the same process (IBM i job) where the system utility runs.
# -v Write the complete CL command string to standard output before running the CL command.
# -s Do not process spooled output files produced by the CL command.
# When this option is omitted, spooled output generated by the CL command is converted
# from the job default CCSID to the PASE for i CCSID and written to standard output.
# Then, the spooled output files are deleted.
import subprocess
#command = "system -i 'WRKACTJOB OUTPUT(*PRINT)'"
#command = "system -iKvs 'CRTBNDRPG PGM(KEV/ACTSBS) SRCFILE(KEV/QRPGLESRC) SRCMBR(ACTSBS)'"
library = "KDPQGPL"
objectName = "WORKDTAARA"
ibmiCmd = "CHKOBJ OBJ(" + library + '/' + objectName + ") OBJTYPE(*DTAARA) AUT(*ALL)"
command = "system -i " + "'" + ibmiCmd + "'"
result = subprocess.run(["qsh", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
print("Dataarea does not exists")
# CRTDTAARA DTAARA(KDPQGPL/WRKDTARA) TYPE(*DEC) LEN(10 0) VALUE(0)
# TEXT('Python created data area')
ibmiCmd="CRTDTAARA DTAARA("+library+'/'+objectName+") TYPE(*DEC) LEN(10 0) VALUE(0) TEXT(PYTHON_DATAARA)"
command="system -i "+"'"+ibmiCmd+"'"
print("Building it " + command)
result=subprocess.run(["qsh", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#print(f"Msg: {result.stderr}")
else:
print("Command completed successfully")
#print(f"Msg: {result.stderr}")
#
# get the data area and return + 1 and update it.
#
# DSPDTAARA DTAARA(KDPQGPL/WRKDTARA) OUTPUT(*PRINT)
# CHGDTAARA DTAARA(KDPQGPL/WRKDTARA *ALL) VALUE(2)
ibmiCmd = "DSPDTAARA DTAARA(" + library + '/' + objectName + ")"
command = "system -i " + "'" + ibmiCmd + "'"
result = subprocess.run(["qsh", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout
out = str(output)
# split the output into lines
out1 = out.split("\\n")
# search for "VALUE" and split that line into words. the last word is the DTAARA Value
for i in range(len(out1)):
if "Value" in out1[i]:
#print('Index ' + str(i) + ' in out1 is: ' + out1[i])
out2=out1[i].split()
number=out2[-1]
#print(f"Msg: {result.stderr}")
#print("Number is : " + number)
helperNo = int(number)
helperNo = helperNo + 1
helperStr = str(helperNo)
ibmiCmd = "CHGDTAARA DTAARA(" + library + '/' + objectName + " *ALL) VALUE(" + helperStr + ")"
command = "system -i " + "'" + ibmiCmd + "'"
result = subprocess.run(["qsh", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout
#print(output)
Un-comment some of the "print" statements to see what is going on in the code.
Remember this code runs directly on the IBMi so import it into your IFS home directory and call it from pase "python3 <what ever you call the file>.py"
Conclusion:
In conclusion, the marriage of Python and PASE for i marks a significant stride in enhancing the IBMi development experience. The cross-platform compatibility, rich library ecosystem, and streamlined workflow contribute to a more versatile and powerful development environment. As developers continue to explore new horizons, the combination of Python and PASE for i stands as a testament to IBM's commitment to innovation, providing a bridge between traditional enterprise computing and the dynamic world of modern development.
If you have any questions contact me thru the contact page of the slide in form. If you would like some assistance in developing software written in Python - again use the contact slide in or page.