Hello,
On 9/14/2011 4:52 PM, James Lampert wrote:
It looks like I'm going to be needing to check for the existence of a
*STMF in the IFS, from a CL program: it's going to be running in a batch
job, and needs to wait (i.e., DLYJOB) until another job (the one that
spawned it) has created the object (and no, there's no way for the
creating job to actually tell the waiting one that the object has arrived).
HMMM... I'm not sure that this is a good idea. If your timing isn't
good, you could end up processing a "half-written" file. i.e. the batch
job might start writing it (which causes the file to be created) but
your program might process it before it finishes writing it... so
you'll only process half of the data.
Is there a CHKOBJ-equivalent for the IFS? The system in question is at
V6R1. It wouldn't exactly be a hard thing to write (at least, in a
language other than CL), but I'm in no hurry to reinvent any wheels.
There are many ways to see if an object exists, but the access() API is
the "proper" equivalent. (i.e. it's the API designed for such things.)
If you are at V5R4 or higher, you can call the access() API from CL if
you want to. I'd suggest wrapping it in a CMD object to make it easier
to re-use. Here's a quick example (I wrote this just for this
message... took about 5 minutes)
command source:
CMD PROMPT('Check for IFS object')
PARM KWD(OBJ) TYPE(*PNAME) LEN(5000) MIN(1) +
VARY(*YES) EXPR(*YES) +
PROMPT('Object to check for')
program source:
PGM PARM(&PATH_IN)
DCL VAR(&PATH_IN) TYPE(*CHAR) LEN(5002)
DCL VAR(&PATH_LEN) TYPE(*INT) LEN(2) +
STG(*DEFINED) DEFVAR(&PATH_IN 1)
DCL VAR(&PATH_DTA) TYPE(*CHAR) LEN(5000) +
STG(*DEFINED) DEFVAR(&PATH_IN 3)
DCL VAR(&PATHNAME) TYPE(*CHAR) LEN(5001)
DCL VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(x'00')
DCL VAR(&FLAGS) TYPE(*INT) LEN(4) VALUE(0)
DCL VAR(&RC) TYPE(*INT) LEN(4) VALUE(0)
DCL VAR(&P_ERRNO) TYPE(*PTR)
DCL VAR(&ERRNO) TYPE(*INT) LEN(4) +
STG(*BASED) BASPTR(&P_ERRNO)
DCL VAR(&DEC4) TYPE(*DEC) LEN(4 0)
DCL VAR(&CHAR4) TYPE(*CHAR) LEN(4)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
CHGVAR VAR(&PATHNAME) VALUE(%SST(&PATH_DTA 1 &PATH_LEN) +
*CAT &NULL)
CALLPRC PRC('access') +
PARM((&PATHNAME *BYREF) +
(&FLAGS *BYVAL)) +
RTNVAL(&RC)
IF (&RC *NE 0) DO
CALLPRC PRC('__errno') +
RTNVAL(&p_errno)
CHGVAR VAR(&DEC4) VALUE(&errno)
CHGVAR VAR(&CHAR4) VALUE(&DEC4)
CHGVAR VAR(&MSGID) VALUE(CPE *CAT &CHAR4)
SNDPGMMSG MSGID(&MSGID) MSGTYPE(*ESCAPE) MSGF(QCPFMSG)
ENDDO
ENDPGM
To compile it, use:
CRTCLMOD module-name
CRTPGM PGM(your-pgm-name) MODULE(module-name) +
ACTGRP(KLEMENT) BNDDIR(QC2LE)
CRTCMD CMD(your-cmd) PGM(your-pgm-name)
The result should be a command that can check for an IFS object... but,
again, beware of processing the file immediately when it's created,
because it might half-written.
If possible, have the creating job create the file in a temporary
directory, and then "move" it to the proper directory as a last step,
that way you will never get the file when it's only half-written.
As an Amazon Associate we earn from qualifying purchases.