I would typically create an environment variable. These work great for
CGI programs because you can set them in the Apache httpd.conf file, and
they can be set separately for different <Directory>, <Location>, etc
containers as needed.
So for example, I might do something like this:
ScriptAlias /apitest /QSYS.LIB/SKTESTAPI.LIB/MYPGM.PGM
Require all granted
SetEnv API_LOG_FILE /var/apitest/requestData.txt
SetEnv QIBM_CGI_LIBRARY_LIST "TESTDB;SKUTILS"
The important part is API_LOG_FILE -- in this example, programs in the
SKTESTAPI library will log their data to the
/var/apitest/requestData.txt file. If API_LOG_FILE isn't defined for a
program, it would be in "production" mode and wouldn't log anything.
Then in the program I would do something like this:
dcl-pr getenv pointer EXTPROC('getenv');
name pointer value options(*STRING);
dcl-s logFile varchar(2048);
dcl-s ptr pointer;
dcl-s log int(10) inz(-1);
ptr = getenv('API_LOG_FILE');
if ptr = *null;
// no log needed
logFile = %str(ptr);
log = open( logFile
: O_CREAT + O_TRUNC + O_INHERITMODE + O_WRONLY
+ O_TEXTDATA + O_TEXT_CREAT + O_CCSID
I included the prototype for "getenv" (get environment variable) in case
you didn't already have it. Typically, I'd have this in a copybook or
As always, in computer programming, there are many ways to accomplish
the same thing, but this way has always worked nicely for me. It's much
more versatile than something like a data area because it can be defined
in different places with different values in your httpd.conf
On 1/10/2022 11:40 AM, Dave wrote:
At the moment, during testing, each time my CGI programme receives JSON
data, I'm saving it to the IFS.
As I won't need to keep the JSON data once the application is deployed,
would be the best way to dynamically turn on and off the save function ofdata
the program in case it were needed? Seems to me there are many ways of
doing it. I could configure an environment variable, an URL, change a
area, etc. What do you people do ?--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing
To post a message email: WEB400@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: WEB400-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
As an Amazon Associate we earn from qualifying purchases.
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.