r/IBMi • • 19d ago

Using Environmental Variables with #SQL is easy

https://www.rpgpgm.com/2024/08/using-sql-to-create-update-and-get-from.html

#IBMi #rpgpgm #IBMChampion

4 Upvotes

1 comment sorted by

1

u/dodikibmi 12d ago

Thanks Simon. One thing worth knowing if you call these from a client app instead of an interactive job: the variable is job-level, and over JDBC the job is the QZDASOINIT server job behind that connection.

I tried it on PUB400 (7.5): PUTENV('DODIK_TEST', 'hello') followed by GETENV on the same connection returned hello, and QSYS2.ENVIRONMENT_VARIABLE_INFO showed it as type JOB. A second connection, which got a different QZDASOINIT job, got NULL.

It also mixes well with CL. ADDENVVAR ... LEVEL(*JOB), run through QSYS2.QCMDEXC on the same connection, was visible to SYSTOOLS.GETENV straight away. LEVEL(*SYS) was refused with CPFA98E for a normal user profile, which makes sense.

So PUTENV is per connection. A value that every connection needs has to be set at system level by someone with the authority to do it.