It ain't rocket science, but the "environment" seems to have most of us stumped.
For decades, the local data area (LDA) was used in System/3x shops (AS/400/iSeries/System i shops to the newbies out there) to store variables shared between programs. Today, parameter passing has all but eliminated LDA usage except for the millions of lines of legacy code that seem to never go away.
But passing parameters to a Java program is, shall we say, interesting. Why call Java at all? Because IBM decided that enhancing the operating system's feature set with robust interfaces is less important than requiring you to use something for which they've already paid Sun a license fee.
Well, the environment is accessible from CL, C, RPG IV, and Java. You can easily store information in the environment and retrieve it later—in a different program or the same program. The environment exists for each job; it is created (like the LDA) when the job is started and is destroyed (also like the LDA) when the job ends.
Unlike the LDA, the environment can hold up to 15 megabytes of textual data (no, unfortunately packed fields cannot be stored in the environment; it is text-only). In addition, rather than use positional storage locations such as from/to columns, the environment allows you to store information based on an identifier. This identifier is used to store and then later retrieve the information.
To use the environment in CL, the following CL commands are available:
- ADDENVVAR
- CHGENVVAR
- RMVENVVAR
- WRKENVVAR
To use the environment in RPG IV, you use the following APIs:
- putenv()
- getenv()
- Qp0zDltEnv()
- Qp0zPutEnv()
- Qp0zGetEnv()
For more information about the environment and its APIs see my related article.
Java CLASSPATH
About the only time I hear a question about the environment is when someone is interfacing with Java and needs to set the CLASSPATH properly.
The CLASSPATH is an environment variable that Java uses as its version of the library list. That is, Java searches the IFS path directories contained in the CLASSPATH for the various Java classes being used by the Java programs you run.
Normally, you set the CLASSPATH externally to the Java program, which means if you call Java from RPG IV, you need to set the CLASSPATH inside your RPG IV program.
Setting the CLASSPATH is easy using the putenv() C runtime API. But the syntax for the value of CLASSPATH can be confusing, so here's an example:
That's it. The CLASSPATH is set. Now you can call your Java routine. Of course, the CLASSPATH for your own application will be different, just like the library list for any given job could be different.
Two important elements in setting the CLASSPATH will help make this work correctly:
- Be sure to specify CLASSPATH in all uppercase. Environment variables are case-sensitive, so "classpath" is not "CLASSPATH." Such a mistake can turn into a nightmare for programmers.
- The iSeries requires a colon (:) as the separator between directory names in the CLASSPATH, whereas Windows (for example) uses the semicolon. It is critical that you're aware of the locale requirements for your system. If you insert a semicolon and the first entry in the CLASSPATH contains the class you need to start the program running, it may seem to work and then fail later. If the CLASSPATH looks right, but you get the "cannot find class" messages, check the CLASSPATH for semicolons or commas instead of colons.
One last tip: Use the WRKENVVAR to verify that the environment variables are being set correctly. As long as the job hasn't ended, the environment variables should still be there (unless they were removed). You can use WRKENVVAR to verify that your RPG IV program is manipulating the environment variables correctly.
Bob Cozzi is host of iSeriesTV.com, an audio and video podcast/netcast Web site dedicated to the iSeries/System i world. Bob is also the author of several books, including The Modern RPG IV Language and RPG TNT: 101 Tips 'n Techniques for RPG IV. He is also the producer of RPG World, an annual conference for RPG IV programmers.
LATEST COMMENTS
MC Press Online