fgl_getenv( )

 

fgl_getenv( ) takes a character expression argument which is the name of the variable and returns a character string, which is the value of this environment variable.

 

Description: FGL_GETENV()%20function

 

Usage

 

The argument of fgl_getenv( ) must be a character expression that returns the name of an environment variable. To evaluate a call to fgl_getenv( ), 4GL takes the following actions at runtime:

  1. Evaluates the character expression argument of fgl_getenv( )

  2. Searches among environment variables for the returned value

 

If the requested value exists, the function returns it as a character string and then returns control of execution to the calling context.

The identifier of an environment variable is not a 4GL expression, so you typically specify the argument as a quoted string or character variable. For example, this call evaluates the DBFORMAT environment variable:

 

fgl_getenv("DBFORMAT")

 

You can assign the name of the environment variable to a character variable and use that variable as the function argument. If you declare a CHAR or VARCHAR variable called env_var and assign to it the name of an environment variable, a fgl_getenv( ) function call could look like this:

 

fgl_getenv(env_var)

 

If the argument is a character variable, be sure to declare it with sufficient size to store the character value returned by the fgl_getenv( ) function; otherwise 4GL will truncate the returned value.

If the specified environment variable is not defined, fgl_getenv( ) returns a null value. If the environment variable is defined but does not have a value assigned to it, fgl_getenv( ) returns blank spaces.

You can use the fgl_getenv( ) function anywhere within a 4GL program to examine the value of an environment variable.

The example program below displays the value of the user-specified environment variable. The environment variable is  identified by the env_variable character variable, and its contents are stored in a variable called env_path:

 

MAIN

  DEFINE

    env CHAR(500),

    env_variable CHAR(60),

    output_string STRING

  CALL fgl_winprompt(5, 2, "Enter the name of the environment variable", "",  60, 0) returning env_variable

  LET env = fgl_getenv(env_variable)

  IF env is not NULL THEN -- check if environment variable exists

    LET output_string = "The environment variable \""  ,env_variable clipped, "\" is set to:\n\n",  env clipped

    CALL fgl_winmessage("Info",output_string,"info")

  ELSE

    LET output_string = "The environment variable \""  ,env_variable clipped, "\" was not found!"

    CALL fgl_winmessage("Warning",output_string,"warning")

  END IF

END MAIN

 

 

fgl_putenv()

fgl_setenv()