How to call an RPG program from Python

Hi, I am trying to call an AS400 program from python script with parameters
is it possible? if so how can I do it?

Yes it is possible, but in a more indirect way than you’d think. I don’t know the RPG side of things in-depth, but essentially, Ignition calls a stored procedure in RPG which handles the function call. We have it setup where a JSON string is returned. For example, The Ignition call is a named query

select ignlib.#ignXXXXr(:action,:record) 
from sysibm.sysdummy1

Action is the function or operation required, and record is the parameter list

action = "calculateSALH"
record = "serial:123456789|user:Test User|operation:Cut"

This query will return a JSON string where it can be accessed as a dictionary

result= system.db.runNamedQuery("as400_call",{'action':action,'record':record})
# result = {"Result":{"ErrMsg":"","SALH":1.232}}
json = system.util.jsonDecode(result)
if len(json['Result']['ErrMsg']):    # length is not 0, so no errors occurred
    salh = json['Result']['SALH']

Thanks, this function can come in handy, but in the question I meant how to call an RPG program as you do from the command line as400 with the following string:
“CALL PGM (PGM1) PARM (” test “)”
it’s possible?

The method I described above is probably your best option to use as400 functions from Ignition

For example, if the new operation is something that other users or programs can take advantage of, a UDF can help to reuse it. In addition, the function can be called directly in SQL wherever an expression can be used. The database takes care of many data type promotions of the function arguments automatically. For example, with DECIMAL to DOUBLE, the database allows your function to be applied to different, but compatible data types.

In certain cases, calling the UDF directly from the database engine instead of from your application can have a considerable performance advantage. You will notice this advantage in cases where the function may be used in the qualification of data for further processing. These cases occur when the function is used in row selection processing.

Using user-defined functions - IBM Documentation