Rational Developer for System z

Accessing environment variables in a PL/I sample program

Sometimes it is necessary to dynamically retrieve the value of an environment variable at run time. This topic describes one way to modify the code in one of the PL/I sample projects to enable environment variable access.

This topic involves PL/I Sample 1, which is available through the workbench examples interface. The sample includes one PL/I file, HelloApp.pli.

Accessing environment variables is much easier in PL/I than COBOL, primarily due to the inclusion of built-in functions for setting and retrieving environment variables (PutEnv and GetEnv).

Complete the following instructions to modify a project containing this sample so that HelloApp.pli reads an environment variable and displays its value.

  1. Switch to the z/OS® Projects perspective.
  2. Create a sample project for PL/I Sample 1.
  3. Edit HelloApp.pli to match the following:
    Dcl GetEnv Builtin;
    Dcl theName Char(20) Varying;
    Dcl theValue Char(1000) Varying;
    
    theName = "PATH";
    theValue = GetEnv(theName);
    Put Skip List('Path=' || theValue);
  4. Right-click the project name and select Rebuild Project. If there are no errors, an executable will be created in the BuildOutput folder. The executable is named HelloApp.exe.
  5. To test that the program works, double-click HelloApp.exe. A command shell opens with the prompt Enter a name or Q to quit.

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)