If you plan to use Java, setting your Java environment by job on the AS/400 is as important as setting your job environment for other AS/400 jobs. AS/400 jobs you run now focus on setting library lists to find your data files and programs. Java jobs have other parameters that you need to focus on. Key parameters for any AS/400 Java job at a minimum are CLASSPATH, QIBM_MULTI_THREADED.
CLASSPATH determines your class `search list' at runtime. When your application needs to load a class it searches the current classpath, including directories, zip and jar files, to find the class. If the classpath is not defined correctly for the job, your classes won't load.
QIBM_MULTI_THREADED determines whether your application runs in a multithreaded environment. This is NOT a simple choice for Java. Using QSHELL's AJAR utility requires setting this to TRUE. On the other hand, some Java applications are sensitive to this option and will fail to run normally if the option is true. For example, Domino for AS/400 at version 5.02 would lock up running Java applications in some circumstances if this were set to TRUE.
While there are many options for setting classpath on the AS/400, a common need is to set the classpath at runtime for the job. Without using QSHELL scripts or setting default system values for these parameters, you will want to use IBM's commands ADDENVVAR and RMVENVVAR. There is no CHGENVVAR. Using the ideas below you can write your own CHGJVAVAR command.
Sample program to set Java job environment dynamically.
Below is a simple CL program I launch automatically when I sign on interactively. The same program can also be run in a batch job to set these parameters or, even, through a stored procedure job to set the classpath when you call a Java application as a stored procedure. It's quite flexible.Given that ADDENVVAR fails IF the environment variable you are defining already exists and we don't have the CHGJVAVAR command I suggested above, you must first do a RMVENVVAR prior to adding the variable in case it already exists for the job. If you attempt RMVENVVAR and the variable hasn't been defined, it generates a different error that is sent to QSYSOPR automatically requiring a reply. The sample program handles this by receiving the error message in the program and providing a default reply `I' to ignore the error and continue processing the CL program. It allows the program to effectively perform a change environment variable even though we don't have the command.
The code for the START program is below:
/*------------------------------------------------------------------*/
/* START SET STARTUP ENV FOR AS/400 JAVA JOBS */
/* */
/* F10 REMOVE CURRENT JOB ENVIRONMENT VARIABLES */
/* F20 SET NEW JOB ENVIRONMENT VARIABLES �/�� �/�� */
/* ERR ERROR HANDLER */
/* */
/* */
/* THIS SOFTWARE IS DISTRIBUTED AS IS WITHOUT ANY WARRANTIES */
/* */
/* CAPE COD BAY SYSTEMS - www.ccbsnet.com jemason@ebt-now.com �/�� */
/*------------------------------------------------------------------*/
/* 0001 09/00 JMASON INITIAL CREATE */
/*------------------------------------------------------------------*/
PGM
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSG) TYPE(*CHAR) LEN(256)
DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGLEN) TYPE(*DEC) LEN(5 0)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(256)
DCL VAR(&MSGDTALEN) TYPE(*DEC) LEN(5 0)
DCL VAR(&MSGSEV) TYPE(*DEC) LEN(2 0)
DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
DCL VAR(&RTNTYPE) TYPE(*CHAR) LEN(2) /* 05 = inq */
DCL VAR(&SEV) TYPE(*DEC) LEN(2 0)
DCL VAR(&KEYVAR) TYPE(*CHAR) LEN(4)
MONMSG MSGID(CPF0000)
/* F10 REMOVE CURRENT JOB ENVIRONMENT VARIABLES */
RMVENVVAR ENVVAR(CLASSPATH)
MONMSG MSGID(CPFA981) EXEC(DO)
RCVMSG MSGQ(*PGMQ) KEYVAR(&KEYVAR) MSG(&MSG) +
MSGLEN(&MSGLEN) MSGDTA(&MSGDTA) +
MSGDTALEN(&MSGDTALEN) MSGID(&MSGID) +
SEV(&SEV) RTNTYPE(&RTNTYPE) MSGF(&MSGF)
IF COND(&RTNTYPE = "05") THEN(DO)
SNDRPY MSGKEY(&KEYVAR) MSGQ(START) RPY('I')
ENDDO
ENDDO
RMVENVVAR ENVVAR(QIBM_MULTI_THREADED)
MONMSG MSGID(CPFA981) EXEC(DO)
RCVMSG MSGQ(*PGMQ) KEYVAR(&KEYVAR) MSG(&MSG) +
MSGLEN(&MSGLEN) MSGDTA(&MSGDTA) +
MSGDTALEN(&MSGDTALEN) MSGID(&MSGID) +
SEV(&SEV) RTNTYPE(&RTNTYPE) MSGF(&MSGF)
IF COND(&RTNTYPE = "05") THEN(DO)
SNDRPY MSGKEY(&KEYVAR) MSGQ(START) RPY('I')
ENDDO
ENDDO
/* F20 SET NEW JOB ENVIRONMENT VARIABLES */
ADDENVVAR ENVVAR(CLASSPATH) +
VALUE('.:/tmp/jmason:QIBM/ProdData/HTTP/Pub+
lic/jt*00/lib/jt400.jar')
ADDENVVAR ENVVAR(QIBM_MULTI_THREADED) VALUE(Y)
CHGJOB OUTQ(JMASON/JMASON)
CHGCURLIB CURLIB(JMASON)
GOTO CMDLBL(END)
/* ERR: STD ERROR HANDLING */
ERR:
RCVMSG KEYVAR(&KEYVAR) MSG(&MSG) MSGLEN(&MSGLEN) +
MSGDTA(&MSGDTA) MSGDTALEN(&MSGDTALEN) +
MSGID(&MSGID) SEV(&SEV) RTNTYPE(&RTNTYPE) +
MSGF(&MSGF)
IF COND(&RTNTYPE = "05") THEN(DO)
SNDRPY MSGKEY(&KEYVAR) MSGQ(START) RPY('I')
ENDDO
SNDPGMMSG MSGID(&MSGID) MSGF(&MSGF) MSGDTA(&MSGDTA) +
MSGTYPE(*STATUS)
/* */
END:
ENDPGM
The sample screens below show the result of running the START program above for both CLASSPATH and QIBM_MULTI_THREADED. You can use the WRKENVVAR command to view the same results on your system.
//==============================================================================
Print Key Output Page 1
5769SS1 V4R4M0 990521 S102A2HM 09/26/00 10:31:10
Display Device . . . . . : QPADEV0001
User . . . . . . . . . . : LOTUS
Work with Object Links
Directory . . . . : /QIBM/ProdData/HTTP/Public/jt400/lib
Type options, press Enter.
3=Copy 4=Remove 5=Next level 7=Rename 8=Display attributes
11=Change current directory ...
Opt Object link Type Attribute Text *
data400.jar STMF
jt400.jar STMF
jt400.zip STMF
jt400Access.zip STMF
jui400.jar STMF
uitools.jar STMF *
util400.jar STMF
x4j400.jar STMF
QSF610665769JC1000 > STMF
More...
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F12=Cancel F17=Position to
F22=Display entire field F23=More options
==============================================================================//
//==============================================================================
Print Key Output Page 1
5769SS1 V4R4M0 990521 S102A2HM 09/26/00 10:41:56
Display Device . . . . . : QPADEV0001
User . . . . . . . . . . : LOTUS
Work with Environment Vars (*JOB)
Type options, press Enter.
1=Add 2=Change 4=Remove 5=Display details 6=Print
Opt Name Value
CLASSPATH '.:/tmp/jmason:QIBM/ProdData/HTTP/P' >
QIBM_MULTI_THREADED 'Y' *
*
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F11=Display CCSIDs
F12=Cancel F16=Print list F17=Top F18=Bottom F22=Display entire field
(C) COPYRIGHT IBM CORP. 1980, 1999.
==============================================================================//
----------------------------------------------
About the authors: Jim Mason is president of Cape Code Bay Systems, an IBM and Lotus business partner focused on delivering e-business application solutions for AS/400 customers. David Slater is Worldwide AS/400 Application Development Market Manager at IBM Canada.
This was first published in December 2000