JSM Status and Error Handling
Posted: Wed Mar 29, 2017 4:36 am
In every example I've found in the documentation, after every JSM command the status is checked.
Sometimes, the check just adds a message, sometimes the check adds a message and issues the JSMX_CLOSE command.
However it seems like execution never stops if the status not OK. It just keeps falling through the rest of the commands.
I can understand closing the connection, as that would cause the next command to fail however I don't understand just adding a message.
What is the proper way to handle JSM Status and JSM errors in general? When should I close and when should I leave it?
I've been setting an error status when executing commands like
and checking the status like such
Sometimes, the check just adds a message, sometimes the check adds a message and issues the JSMX_CLOSE command.
However it seems like execution never stops if the status not OK. It just keeps falling through the rest of the commands.
I can understand closing the connection, as that would cause the next command to fail however I don't understand just adding a message.
What is the proper way to handle JSM Status and JSM errors in general? When should I close and when should I leave it?
I've been setting an error status when executing commands like
Code: Select all
mthroutine name(CreatePDF)
define_map for(*RESULT) class(#PRIM_BOLN) name(#hasError)
#hasError := True
* open JSM
#SYS_APPLN.TraceMessageText( "Opening JSM" )
use builtin(JSMX_OPEN) to_get(#JSMXSTS #JSMXMSG #JSMXHDLE)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* load the pdf document service
#JSMXCMD := ('SERVICE_LOAD SERVICE(PDFDOCUMENTSERVICE)')
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* create the document
#JSMXCMD := ('CREATE DOCUMENT(' + #wk_FilePath + ') CONTENT(xml/CMGCCP_Sales_Analysis_Template.xml)')
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* add the header content
#JSMXCMD := ('ADD CONTENT(HEADER)')
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* other content commands omitted
* close the document
#JSMXCMD := CLOSE
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* unload the service
#JSMXCMD := SERVICE_UNLOAD
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif
* close JSM
#SYS_APPLN.TraceMessageText( "Closing JSM" )
use builtin(JSMX_CLOSE) with_args(#JSMXHDLE) to_get(#JSMXSTS #JSMXMSG)
#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG )
#hasError := False
endroutine
Code: Select all
mthroutine name(CheckStatus)
define_map for(*INPUT) class(#JSMXSTS) name(#status)
define_map for(*INPUT) class(#JSMXMSG) name(#message)
define_map for(*RESULT) class(#PRIM_BOLN) name(#hasError)
#hasError := True
#SYS_APPLN.TraceMessageData( "JSM Status:&1" #status )
if (#status <> OK)
#JSMXSTS := #status
#JSMXMSG := #message
add_entry to_list(#JSMXMessages)
* close JSM
#SYS_APPLN.TraceMessageText( "Closing JSM" )
use builtin(JSMX_CLOSE) with_args(#JSMXHDLE) to_get(#JSMXSTS #JSMXMSG)
return
endif
#hasError := False
endroutine