EnvironmentVariable class

The IBM® Toolbox for Java™ EnvironmentVariable class and the EnvironmentVariableList class enable you to access and set IBM i system-level environment variables.

Each variable has unique identifiers: the system name and the environment variable name. Each environment variable is associated with a CCSID, which is by default the CCSID of the current job, which describes where the contents of the variable are stored.

Note: Environment variables are different than system values, although they are often used for the same purpose. See SystemValues for more information on how to access system values.

Use an EnvironmentVariable object to perform the following actions on an environment variable:

  • Get and set the name
  • Get and set the system
  • Get and set the value (which allows you to change the CCSID)
  • Refresh the value

Example: Creating, setting, and getting environment variables

The following example creates two EnvironmentVariables and sets and gets their values.
Note: Read the Code example disclaimer for important legal information.
     // Create the system object.
     AS400 system = new AS400("mySystem");

     // Create the foreground color environment variable and set it to red.
     EnvironmentVariable fg = new EnvironmentVariable(system, "FOREGROUND");
     fg.setValue("RED");

     // Create the background color environment variable and get its value.
     EnvironmentVariable bg = new EnvironmentVariable(system, "BACKGROUND");
     String background = bg.getValue();