Start of change

GETENV scalar function

The GETENV scalar function retrieves the value of an environment variable for the current job.

The function is implemented using the getenv() API. The result is similar to the QSYS2.ENVIRONMENT_VARIABLE_INFO view and the Work with Environment Var (WRKENVVAR) CL command.

The function requires that Option 13 (System Openness Includes) of the IBM i operating system is installed.

Authorization: See Note below.

Read syntax diagramSkip visual syntax diagramGETENV( ENVIRONMENT_VARIABLE_NAME =>  environment-variable-name)
The schema is SYSTOOLS.
environment-variable-name
An expression that returns the name of an environment variable.

The result of the function is a variable-length character string that contains the value of the environment variable, from 0 to 1024 characters in length. If the environment variable is not found, the function returns the null value.

Note

This function is provided in the SYSTOOLS schema as an example of how to embed a C interface within SQL PL code. Similar to other Db2® for i provided tools within SYSTOOLS, the SQL source can be extracted and used as a model for building similar helper functions, or to create a customized version within a user-specified schema.

Services provided in SYSTOOLS have authorization requirements that are determined by the interfaces used to implement the service. To understand the authority requirements, extract the SQL for the service and examine the implementation.

Example

  • Get the value of MY_ENVVAR for the current job.
    VALUES SYSTOOLS.GETENV('MY_ENVVAR');
End of change