JSM Status and Error Handling

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 657
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

JSM Status and Error Handling

Post by jyoung » 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

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
and checking the status like such

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

User avatar
HMJust
Posts: 51
Joined: Wed May 11, 2016 7:23 pm
Contact:

Re: JSM Status and Error Handling

Post by HMJust » Wed Mar 29, 2017 7:59 pm

It really depends on the kind of error you are experiencing, as I could imagine there would be errors you could use to take an alternative path through execution. Like, "if this fails, then I will make this call instead".

However, I think most cases the proper way would be to close the JSM and end the processing. That is what I do.
I don't know what I am doing, nor how I did it. If it works, luck was involved :geek:

jyoung
Posts: 657
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: JSM Status and Error Handling

Post by jyoung » Thu Mar 30, 2017 12:49 am

Ok thanks.

That is how I am handling all my operations now, I close the connection if status is not ok and bail out of the processing.

Thanks again.

Joe

Post Reply