Sure, Jon. I was just enhancing an example I'm going to use at COMMON
PowerUp 19.
Here it is.
We're going to pass in params from a CL to Python, and then get back the
answers by reading a DB file we create for Python to fill in.
*PYTST* is the file, here's its DDS
A*****************************************************************
A* COMPILE OPTION: MAINT(*IMMED)
A R PYTST
A STRINGA 10A
A COLHDG('STRA')
A STRINGB 10A
A COLHDG('STRB')
A K STRINGA
A K STRINGB
A STRINGB 10A
A COLHDG('STRB')
A K STRINGA
A K STRINGB
We're going to use SQL, so after you CRTPF you have to journal PYTST,
Here's the Python code *cltest.py* ... It resides in the IFS in my home
directory /home/JWOEHR ... you will have to change that path in your own CL.
Also you will have to change the libname somelib to the lib you actually
use, see below.
Python code is not compiled, it is interpreted by Python at runtime.
#!/QOpenSys/pkgs/bin/python3
import sys
import ibm_db_dbi
c = ibm_db_dbi.connect()
cur = c.cursor()
cur.execute("delete from *somelib*.pytst")
c.commit()
sql = "insert into *somelib*.pytst VALUES ('" + str(sys.argv[1]) + "', '" +
str(sys.argv[2]) + "')"
cur.execute(sql)
c.commit()
cur.close()
c.close()
Here is the CL *PYTEST*
PGM PARM(&X &Y)
DCL VAR(&X) TYPE(*CHAR) LEN(10)
DCL VAR(&Y) TYPE(*CHAR) LEN(10)
DCL VAR(&PYCMD) TYPE(*CHAR) LEN(200)
DCLF UBLUTEST/PYTST
CHGVAR VAR(&PYCMD) VALUE('/QOpenSys/usr/bin/sh -c +
"*/home/JWOEHR*/cltest.py')
CHGVAR VAR(&PYCMD) VALUE(&PYCMD *BCAT &X *BCAT &Y)
CHGVAR VAR(&PYCMD) VALUE(&PYCMD *BCAT '"> +
*/home/JWOEHR/logs*/cltest_`date +
+%Y%m%d%H%M%S`.log 2>&1')
SNDMSG MSG(&PYCMD) TOUSR(*REQUESTER)
QSH CMD(&PYCMD)
RCVF
SNDMSG MSG(&STRINGA) TOUSR(*REQUESTER)
SNDMSG MSG(&STRINGB) TOUSR(*REQUESTER)
ENDPGM
Compile this to SOMELIB (changing first the absolute path to the python
script embedded in the CL !!) and then
*CALL PGM(SOMELIB/PYTEST) PARM(woogle znorg)*
*(Or whatever two 10-char params you want to pass)*
And Python will read those params and pass them back to you in PYTST which
the CL will then use to SNDMSG to you.
On Fri, Jan 18, 2019 at 3:46 PM Jon Paris <jon.paris@xxxxxxxxxxxxxx> wrote:
Example?
Not getting on your case Jack but I see so much "Oh it is easy in Python"
- but nobody ever shows how in a meaningful manner for an RPGer.
Jon Paris
As an Amazon Associate we earn from qualifying purchases.