× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Jack - I was hoping for something a little more direct though. Using files as a transport vehicle feels a bit like an old batch process. It is fine in a "go create this spreadsheet" type of scenario, but not terribly practical in circumstances such as the OP's original subject.

I'm looking for as close to a call/parm as I can get.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 18, 2019, at 6:24 PM, Jack Woehr <jwoehr@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

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.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.