MSCZJOB	;GFT,JDS,JKT/MSC;29OCT2009
	;;8.0;KERNEL;**MSC**
	W !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	N MSC
DDS	;
	S DDSFILE=3.081,DR="[MSCZJOBEXAM]",DDSPARM="S"
	D ^DDS K ^TMP("MSCZJOB1",$J) Q
	;
UNLOCK(D0)	;FROM FIELD 2, PAGE 3: UNLOCK THE LOCK
	N X,R,N S R=$G(@MSC@(MSCJOBID,"L",D0)) I R'["^" Q  ;CAN'T SEE IT
	S R=$P(R," ",2),X="L "_R D ^DIM Q:'$D(X)
	S N=$$NSP(MSCJOBD0)
	D UNLOCK^MSCZJOBU(R,N)
	Q
	;
KILL(J)	;FROM FIELD
	D KILL^MSCZJOBU(J)
	Q
	;
COMPMUL	;COMPUTED MULTIPLE FOR MSCZJOBEXAM BLOCK
	N X,D0,J
	S MSC="^TMP(""MSCZJOB1"",$J)" D POLL
	D JOBEXAM^MSCZJOBU(MSC)
	F D0=0:0 S D0=$O(MSCZJOB(D0)) Q:'D0  D
	.S MSCZJOB(D0)=MSCZJOB(D0)_U_$$DEV(D0)_U_$$USER(D0)_U_$$NSP(D0)_U_U_U_U_U_$$ROUTINE(D0)
	.S X=MSCZJOB(D0) X DICMX
	Q
JOB(D0)	Q $P(MSCZJOB(D0),U) ;***
DEV(D0)	Q $$FIND(D0,"I","$PRINCIPAL")
NSP(D0)	N N D  Q N
	.N L,P S N=$$FIND(D0,"I","$ZGBLDIR"),L=$L(N,"/") I L<2 Q
	.F L=L-1:-1:2 S P=$P(N,"/",L) I P'[".",P'["globals" Q
	.S P=1 I $P(N,"/")="" S P=2
	.S N=$P(N,"/",L)
USER(D0)	Q $P($G(^VA(200,+$$FIND(D0,"V","DUZ"),0)),U)
ROUTINE(D0)	Q $$FIND(D0,"V","%ZPOS")
	;
FIND(D0,ARR,KEY)	N I,J,X S X="",J=+MSCZJOB(D0)
	F I=0:0 S I=$O(@MSC@(J,ARR,I)) Q:'I  I $P(^(I),KEY_"=")="" S X=$TR($P(^(I),"=",2),"""") Q
	Q X
	;
COMPSTK	;COMPUTED MULTIPLE FOR MSCZJOBSTACK BLOCK
	S MSC="^TMP(""MSCZJOB1"",$J)" K @MSC@(MSCJOBID) D POLL1
	D JOBEXAM^MSCZJOBU(MSC,MSCJOBID)
	N D0,J S J=MSCJOBID
	F D0=1:1:$O(@MSC@(J,"S",""),-1)  S X="" X DICMX
	Q
	;
STACK(D0)	N X S X=$G(@MSC@(MSCJOBID,"S",D0))
	Q X
	;
COMPVARS	;COMPUTED MULTIPLE FOR MSCZJOBVARS BLOCK
	S MSC="^TMP(""MSCZJOB1"",$J)" K @MSC@(MSCJOBID) D POLL1
	D JOBEXAM^MSCZJOBU(MSC,MSCJOBID)
	N D0,J S J=MSCJOBID
	F D0=1:1:$O(@MSC@(J,"V",""),-1)  S X="" X DICMX
	Q
	;
COMPLKS	;COMPUTED MULTIPLE FOR MSCZJOBLOCKS BLOCK
	S MSC="^TMP(""MSCZJOB1"",$J)" D POLL1
	D JOBEXAM^MSCZJOBU(MSC,MSCJOBID)
	N D0
	F D0=1:1:$$LOCKS  S X="" X DICMX
	Q
	;
LOCKS()	Q +$O(@MSC@(MSCJOBID,"L",""),-1)
	;
POLL	K MSCZJOB ;D HLP^DDSUTL("   POLLING JOBS.....") 
	I $G(^%ZOSF("OS"))["GT.M" D
	.K @MSC
	.D INTRPT^MSCZJOBU("*") ;SETS UP ^TMP
	.N MSCA,I D PIDS^MSCZJOBU(.MSCA)
	.S MSCA="" F I=1:1 S MSCA=$O(MSCA(MSCA)) Q:'MSCA  S MSCZJOB(I)=MSCA ;SETS UP LOCAL ARRAY
	.H 1 ;WAIT FOR POLLING
	D TEST
	Q
	;
POLL1	Q:'$G(MSCJOBID)
	I $G(^%ZOSF("OS"))["GT.M" D
	.K @MSC@(MSCJOBID)
	.D INTRPT^MSCZJOBU(MSCJOBID) ;SETS UP ^TMP(MSCZJOB)
	.H 1 ;WAIT FOR POLLING
	D TEST
	Q
	;
TEST	Q
COMPLK	;COMPUTED MULTIPLE FOR MSCZLOCK BLOCK
	N X,D0,J
	S MSC="^TMP(""MSCZJOB1"",$J)" K @MSC D POLL,JOBEXAM^MSCZJOBU(MSC) S D0=0
	F K=0:0 S K=$O(MSCZJOB(K)) Q:'K  D
	.F J=0:0 S J=$O(^TMP("MSCZJOB1",$J,MSCZJOB(K),"L",J)) Q:'J  S A=$TR(^(J),U,"~") D
	..S D0=D0+1,MSCZLK(D0)=$P(A,"LOCK ",2,9)_U_$$USER(K)_U_$TR($$ROUTINE(K),U,"~")_"^^"_MSCZJOB(K)
	..S X=MSCZLK(D0) X DICMX
	Q
LOCK	;
	S DDSFILE=3.081,DR="[MSCZLOCK]",DDSPARM="S"
	D ^DDS Q
UNL(D0)	;FROM FIELD 2, PAGE 3: UNLOCK THE LOCK
	N X,R,N S R=$P($G(MSCZLK(D0)),U),P=$P($G(MSCZLK(D0)),U,5) ;I R'["^" Q  ;CAN'T SEE IT
	S R=$P(R,"~",2),R="^"_$S(R'["(":$P(R," "),1:$P(R,")")_")"),X="L "_R D ^DIM Q:'$D(X)  ;GOOD SYNTAX?
	S N=$$NSP(D0)
	D UNLOCK^MSCZJOBU(R,N)
