Setting the CLASSPATH for RPG IV Calling Java

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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:

putenv('CLASSPATH=/java/mail:.:activation.jar:mail.jar');

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.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: