SETJSMO to Open/close JSM
* =======================================================
* Process ........: SET_MOD
* Function .......: SETJSMO
* Created on .....: 19/10/01 at 11:41:13
* Description ....: Function Skeleton
* Version.........: 1
*
* Full Description:
*
* This function is used only as a common interface
* to OPEN and CLOSE the Java Services Manager.
* It is called from all the JSM example functions when
* they need to OPEN and CLOSE JSM.
*
* Disclaimer: The following material is supplied as an
* example only. No warranty is expressed or implied.
*
* ======================================================*
FUNCTION OPTIONS(*DIRECT *HEAVYUSAGE)
*
DEFINE FIELD(#W_REFCOUN) REFFLD(#STD_NUM)
DEFINE FIELD(#W_ACTION) TYPE(*CHAR) LENGTH(005)
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
DEF_COND NAME(*FIRSTOPEN) COND('#W_REFCOUN = 0')
DEF_COND NAME(*LASTOPEN) COND('#W_REFCOUN *LE 0')
GROUP_BY NAME(#S_EXCHFLD) FIELDS(#S_JSMSTS #S_JSMMSG #W_ACTION)
*
CHANGE FIELD(#S_JSMSTS #S_JSMMSG) TO(*BLANKS)
*
CASE OF_FIELD(#W_ACTION)
WHEN VALUE_IS('= OPEN')
* Open service only if it hasn't been opened already. The
* reference counter #W_REFCOUN is used to keep count
* of OPEN and CLOSE requests. It will only OPEN the first
* and CLOSE the last
IF COND(*FIRSTOPEN)
USE BUILTIN(JSM_OPEN) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ENDIF
*
CHANGE FIELD(#W_REFCOUN) TO('#W_REFCOUN + 1')
WHEN VALUE_IS('= CLOSE')
* CLOSE only if there are no other current functions
* running. Each time a CLOSE is requested, the reference
* counter is decreased in 1.
CHANGE FIELD(#W_REFCOUN) TO('#W_REFCOUN - 1')
IF COND(*LASTOPEN)
CHANGE FIELD(#W_REFCOUN) TO(*ZEROS)
USE BUILTIN(JSM_CLOSE) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ENDIF
WHEN VALUE_IS('= ABORT')
USE BUILTIN(BCONCAT) WITH_ARGS(*FUNCTION 'received a request to Abort. Review' 'previous messages. Will try to CLOSE first.') TO_GET(#MSGDTA)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(JSM_CLOSE) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ABORT
ENDCASE
*
EXCHANGE FIELDS(#S_EXCHFLD)
RETURN
*
* Check the status of the JSM command issued
*
SUBROUTINE NAME(CHECK_STS)
*
IF COND('#S_JSMSTS *NE OK')
USE BUILTIN(BCONCAT) WITH_ARGS('Error Status Code: ' #S_JSMSTS) TO_GET(#MSGDTA)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(BCONCAT) WITH_ARGS('Error Message: ' #S_JSMMSG) TO_GET(#MSGDTA)
USE BUILTIN(BCONCAT) WITH_ARGS(*FUNCTION 'received an error while' 'doing a' #W_ACTION '. Review previous messages.') TO_GET(#MSGDTA)
ABORT MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDIF
*
ENDROUTINE
* =======================================================
* Process ........: SET_MOD
* Function .......: SETJSMO
* Created on .....: 19/10/01 at 11:41:13
* Description ....: Function Skeleton
* Version.........: 1
*
* Full Description:
*
* This function is used only as a common interface
* to OPEN and CLOSE the Java Services Manager.
* It is called from all the JSM example functions when
* they need to OPEN and CLOSE JSM.
*
* Disclaimer: The following material is supplied as an
* example only. No warranty is expressed or implied.
*
* ======================================================*
FUNCTION OPTIONS(*DIRECT *HEAVYUSAGE)
*
DEFINE FIELD(#W_REFCOUN) REFFLD(#STD_NUM)
DEFINE FIELD(#W_ACTION) TYPE(*CHAR) LENGTH(005)
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
DEF_COND NAME(*FIRSTOPEN) COND('#W_REFCOUN = 0')
DEF_COND NAME(*LASTOPEN) COND('#W_REFCOUN *LE 0')
GROUP_BY NAME(#S_EXCHFLD) FIELDS(#S_JSMSTS #S_JSMMSG #W_ACTION)
*
CHANGE FIELD(#S_JSMSTS #S_JSMMSG) TO(*BLANKS)
*
CASE OF_FIELD(#W_ACTION)
WHEN VALUE_IS('= OPEN')
* Open service only if it hasn't been opened already. The
* reference counter #W_REFCOUN is used to keep count
* of OPEN and CLOSE requests. It will only OPEN the first
* and CLOSE the last
IF COND(*FIRSTOPEN)
USE BUILTIN(JSM_OPEN) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ENDIF
*
CHANGE FIELD(#W_REFCOUN) TO('#W_REFCOUN + 1')
WHEN VALUE_IS('= CLOSE')
* CLOSE only if there are no other current functions
* running. Each time a CLOSE is requested, the reference
* counter is decreased in 1.
CHANGE FIELD(#W_REFCOUN) TO('#W_REFCOUN - 1')
IF COND(*LASTOPEN)
CHANGE FIELD(#W_REFCOUN) TO(*ZEROS)
USE BUILTIN(JSM_CLOSE) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ENDIF
WHEN VALUE_IS('= ABORT')
USE BUILTIN(BCONCAT) WITH_ARGS(*FUNCTION 'received a request to Abort. Review' 'previous messages. Will try to CLOSE first.') TO_GET(#MSGDTA)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(JSM_CLOSE) TO_GET(#S_JSMSTS #S_JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS)
ABORT
ENDCASE
*
EXCHANGE FIELDS(#S_EXCHFLD)
RETURN
*
* Check the status of the JSM command issued
*
SUBROUTINE NAME(CHECK_STS)
*
IF COND('#S_JSMSTS *NE OK')
USE BUILTIN(BCONCAT) WITH_ARGS('Error Status Code: ' #S_JSMSTS) TO_GET(#MSGDTA)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(BCONCAT) WITH_ARGS('Error Message: ' #S_JSMMSG) TO_GET(#MSGDTA)
USE BUILTIN(BCONCAT) WITH_ARGS(*FUNCTION 'received an error while' 'doing a' #W_ACTION '. Review previous messages.') TO_GET(#MSGDTA)
ABORT MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDIF
*
ENDROUTINE