Retrieving Job Information
Here is a some code that will allow you
to find your AS/400 Job Number and other information as a
stored procedure call. To execute this, first create the following
CL program in the QSYS2 library.
PGM PARM(&JOB &USER &NBR
&LOGLVL &LOGSEV +
&LOGTYPE &OUTQ &OUTQLIB &RUNPTY &TIMESLICE
+
&USRLIBL &CURLIB &SYSLIBL &CURUSER)
DCL VAR(&JOB) TYPE(*CHAR) LEN(10)
DCL VAR(&USER) TYPE(*CHAR) LEN(10)
DCL VAR(&NBR) TYPE(*CHAR) LEN(6)
DCL VAR(&LOGLVL) TYPE(*CHAR) LEN(1)
DCL VAR(&LOGSEV) TYPE(*DEC) LEN(2 0)
DCL VAR(&LOGTYPE) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTQ) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTQLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&RUNPTY) TYPE(*DEC) LEN(2 0)
DCL VAR(&TIMESLICE) TYPE(*DEC) LEN(7 0)
DCL VAR(&USRLIBL) TYPE(*CHAR) LEN(275)
DCL VAR(&CURLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&SYSLIBL) TYPE(*CHAR) LEN(165)
DCL VAR(&CURUSER) TYPE(*CHAR) LEN(10)
RTVJOBA JOB(&JOB) USER(&USER) NBR(&NBR) +
LOGLVL(&LOGLVL) LOGSEV(&LOGSEV) +
LOGTYPE(&LOGTYPE) OUTQ(&OUTQ) +
OUTQLIB(&OUTQLIB) RUNPTY(&RUNPTY) +
TIMESLICE(&TIMESLICE) USRLIBL(&USRLIBL) +
CURLIB(&CURLIB) SYSLIBL(&SYSLIBL) +
CURUSER(&CURUSER) /* Retrieves job + information for calling
program */
ENDPGM
Then you will need to declare the procedure.
Here is the text of the declare procedure statement that can
be executed in SQLThing:
drop procedure qsys2.retjobinfo;
create procedure qsys2.retjobinfo
(inout :job char(10), inout :user char(10),
inout :nbr char(6), inout :loglvl char(1),
inout :logsev decimal(2,0), inout :logtype char(10),
inout :outq char(10), inout :outqlib char(10),
inout :runpty decimal(2,0), inout :timeslice decimal(7,0),
inout :usrlibl char(275), inout :curlib char(10),
inout :syslibl char(165), inout :curuser char(10))
external name qsys2.retjobinfo simple call;
Now, here is the code that executes the procedure
call. Notice the use of the GetParm method to retrieve the
information that was returned to the parameter markers. The
call to BindProcParm with ProcParmDefault is mandatory as
it sets up the maximum possible buffer size.
This example assumes a statement handle s which is in a connected
state.
x = s.ProcPrep("call qsys2.retjobinfo(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
For i = 1 To s.Nparms
s.BindProcParm s.ProcParmDefault(i), i
Next
If s.Execute() Then
JOB = s.GetParm(1)
USER = s.GetParm(2)
NBR = s.GetParm(3)
LOGLVL = s.GetParm(4)
LOGSEV = s.GetParm(5)
LOGTYPE = s.GetParm(6)
OUTQ = s.GetParm(7)
OUTLIB = s.GetParm(8)
RUNPTY = s.GetParm(9)
TIMESLICE = s.GetParm(10)
USRLIB = s.GetParm(11)
CURLIB = s.GetParm(12)
SYSLIBL = s.GetParm(13)
CURUSER = s.GetParm(14)
Else
s.Errd
End If
|