Addressing Environment Variables with $setting

You can use $setting to retrieve and set environment variables or their platform-specific equivalents —data areas and environment variables on iSeries . On Windows and Unix, it is only possible to address environment variables for the current process.

Retrieve environment variables:

ReturnedValue = $setting(Source, RetrieveProfile, "ENVVARS | ENVDATA")

vEnvVariables = $setting ("", "u*", "ENVVARS") 
vEnvVar = $setting ("", "SRC", "ENVDATA")

Add or change a setting:

$setting (Source, EnvironmentVariable, "ENVDATA") = Value

$setting ("GLOBAL", "MYAPP", "ENVDATA") = "abcd"

Parameters

Parameters

Parameter

Data Type

Description

ENVDATA

String

Get or set an environment variable, logical, or data area. Wildcards are not allowed. The maximum length that can be assigned to an environment variable is 4096 bytes.

ENVVARS

String

Get a list of environment variables, data areas (iSeries). Wildcards can be used.

RetrieveProfile

String

Profile to retrieve one or more environment variables or their equivalent. To retrieve multiple sections or settings, you can use the GOLD * and GOLD ? characters. The profile must match the Topic.

Source

String

Location of the environment variable or equivalent construct.

  • Empty string ("")—default source, which are environment variables for the current process.

  • Platform-specific location or keyword on iSeries:

    • LibraryName—data area

    • *SYS—system-level environment variable

    • *SYSVAL—system-level environment variable

    • *JOB—job-level environment variable; same as empty string

Addressing Environment Variables

To address environment variables (or their equivalent constructs), you need to specify the Source as an empty string ("") or a platform-specific source, and the Topic as ENVARS or ENVDATA.

Note:  On Windows and Unix, you can retrieve both system and local (process-specific) environment variables, but you can only set them for the current process.

$setting("",EnvironmentVariable,ENVDATA)

$setting("",RetrieveProfile,ENVVARS)

On iSeries:

$setting(LibraryName | *SYS | *JOB | *SYSVAL,Setting,ENVDATA)

$setting(LibraryName | *SYS | *JOB | *SYSVAL,RetrieveProfile,ENVVARS)

For example:

  • Retrieve a list of variables within the current process . For example, to get a list of all environment variables that start with an A:

    vEnvVars = $setting ("", "A*", "ENVVARS")
  • Retrieve the value of a specific environment variable:

    vEnvVar = $setting ("", "SRC", "ENVDATA")
  • Modify or add a specific environment variable (or symbol, logical, or data area)

    $setting ("", "SRC", "ENVDATA") = "c:\u10303"