|
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
--
Jack Woehr
Absolute Performance, Inc.
12303 Airport Way, Suite 100
Broomfield, CO 80021
NON-DISCLOSURE NOTICE: This communication including any and all
attachments is for the intended recipient(s) only and may contain
confidential and privileged information. If you are not the intended
recipient of this communication, any disclosure, copying further
distribution or use of this communication is prohibited. If you received
this communication in error, please contact the sender and delete/destroy
all copies of this communication immediately.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.