×
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.
Well, I thought I was going to be able to set a job environment variable
that could be used for any program that was called within the job scope.
Apparently, I've missed something in my logic.
I'm developing a multi-client system that establishes library lists and
environment variables via a CL program:
I have most of the programs and modules in a shared library, but some of
the functionality for specific clients will be stored in separate
libraries, i.e. the same program name in two different libraries. The
calls are fine since the library list is set before the initial program
in called. The problem I seem to be experiencing is using the same
service program across multiple libraries. All of the programs in the
shared library can call the functions without issue. As soon as a call
is made to a program in the secondary library that uses the same
functions, I get a pointer error when retrieving the environment
variable that was set for the job. Here's the code for that:
Program:
H nomain
H bnddir('QC2LE')
************************************************************************
**
** This program returns an environment variable's value.
//--------------------------------------------------------------------
* **********************************************************
* Get environment variable.
* **********************************************************
P GetEnvVar B Export
*
D GetEnvVar PI 32767 varying
D EnvVarNam 64 options(*varsize) varying
const
*
D RtnVar s 32767 varying inz
* ---------------------------------------------------------
*
* Test for no input.
*
C if EnvVarNam = *blanks
C return *blanks
C endif
* ---------------------------------------------------------
*
* Get environment variable.
*
C eval pEnvVar = getenv(%trim(EnvVarNam))
*
C if pEnvVar <> *null
C eval RtnVar = %str(pEnvVar)
C else
C eval RtnVar = *blanks
C endif
*
C return RtnVar
*
P GetEnvVar E
**********************************************************
* Get environment variable as indcator.
* **********************************************************
P GetEnvVarInd B Export
*
D GetEnvVarInd PI like(StdInd)
D EnvVarNam 64 options(*varsize) varying
const
*
D RtnInd s like(StdInd) inz
* ---------------------------------------------------------
*
* Test for no input.
*
C if EnvVarNam = *blanks
C return *off
C endif
* ---------------------------------------------------------
*
* Get environment variable.
*
C eval pEnvVar = getenv(%trim(EnvVarNam))
*
C if pEnvVar <> *null
C eval RtnInd = %str(pEnvVar)
C else
C eval RtnInd = *off
C endif
*
C return RtnInd
*
P GetEnvVarInd E
Prototypes (i.e. /copy etsshare/prototypes,m_envvars):
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* Standard type definitions.
* * * * * * * * * * * * * * * * * * * * * * * * * * *
D StdNulPtr S *
D StdInd S 1n Based( StdNulPtr )
D StdInt S 10i 0 Based( StdNulPtr )
D StdPtr S * Based( StdNulPtr )
D StdStr S 256 Based( StdNulPtr )
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* Environment prototypes.
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* ---------------------------------------------------------
*
* Put environment variable.
*
D putenv PR extproc('Qp0zPutEnvNoCCSID')
D like(StdInt)
D i_envVar like(StdPtr) value
D options(*string)
* ---------------------------------------------------------
*
* Get environment variable.
*
D getenv PR extproc('Qp0zGetEnvNoCCSID')
D like(StdPtr)
D i_envVar like(StdPtr) value
D options(*string)
* ---------------------------------------------------------
*
* Get environment variable.
*
D GetEnvVar PR 32767 varying
D EnvVarNam 64 varying const
D options(*varsize)
* ---------------------------------------------------------
*
* Get environment variable as indicator.
*
D GetEnvVarInd PR like(StdInd)
D EnvVarNam 64 varying const
D options(*varsize)
* ---------------------------------------------------------
*
* Delete environment variable.
*
D dltenv PR extproc('Qp0zDltEnv')
D like(StdPtr)
D i_envVar like(StdPtr) value
D options(*string)
* ---------------------------------------------------------
* ---------------------------------------------------------
*
* Environment variable workfields.
*
D EnvVarNam s 64 inz
D pEnvVar s like(StdPtr) inz
D EnvVar s 32767 based(pEnvVar)
The basic purpose is "idiot proof" prepared dynamic SQL queries
regardless of the current library list. For instance, $sqlstr = 'SELECT
somefield from ' + GetEnvVar('_ETS_DATA_LIB') + '/sometable';
It's an extra step for most, but I like to be thorough. :-) The
GetEnvVar('_ETS_DATA_LIB') call should return a value regardless of the
program library, correct? What have I missed in the process? Shouldn't
an environment variable at the job level be available to ANY program
called within the job scope?
Tom Armbruster
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.