Step 1 Create a Function using Template JSMXSKEL

LANSA Integrator

Step 1. Create a Function using Template JSMXSKEL

INT002 - Getting Started with Basic JSM Operations

In this step, you will create a test function using the template JSMXSKEL to Open and Close the JSM and load the FTPService service. If you do not have a copy of JSMXSKEL, you must first create it using the instructions in Create RDMLX Templates.

1.  Using the LANSA development environment, sign on to the partition nominated for the tutorials (usually DEM).

2.  Check if fields JSMXCMD, JSMXHDLE1, JSMSTS and JSMMSG are defined in the Repository as these fields are required by the JSMXSKEL template. If these fields do not exist, you may create them as follows:

  • JSMXCMD STRING(65535,0) (Must be an RDMLX field)
  • JSMXHDLE1 ALPHA(4,0)
  • JSMXSTS ALPHA(20,0)
  • JSMXMSG ALPHA(200,0)

3.  Create a new LANSA process named iiiPRO01 JSM Test Process, where iii is your unique 3 characters. (If the process already exists, select a different set of characters for iii.)

4.  Create a new function named iiiFN01 JSM Open/Close, belonging to process iiiPRO01. Make sure that the 'Enabled for RDMLX' checkbox is checked. Specify that the function is to be generated from an application template (from the 'Template' dropdown, select JSMXSKEL).

5.  Answer the template question as shown in the table below.

Question

Answer

Comments

Do you wish to load a JSM Service?

FTPSERVICE

 

 

  

6.  Edit your iiiFN01 function and examine the generated RDMLX code.

     The function might appear something like the following:

* ====================================================

*  Process ........:  JMIPRO01
*  Function .......:  JMIFN01
*  Created on .....:  08/11/13  at  14:27:55
*  Description ....:  JSM Open/Close
*  Template........:  JSMXSKEL
* ====================================================
FUNCTION OPTIONS(*DIRECT)
*  OPEN JSM AND VERIFY STATUS
USE BUILTIN(JSMX_OPEN) TO_GET(#JSMSTS #JSMMSG #JSMXHDLE1)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
* BUILD THE SERVICE LOAD COMMAND
#JSMXCMD := 'SERVICE_LOAD'
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD 'SERVICE' 'FTPSERVICE')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
*     YOUR OWN LOGIC HERE
*
* UNLOAD SERVICE
#JSMXCMD := 'SERVICE_UNLOAD'
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
* CLOSE JSM AND VERIFY STATUS
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
*
RETURN
* Subroutine to build JSM commands. existing JSM command
SUBROUTINE NAME(KEYWRD) PARMS((#W_CMDX *BOTH) (#W_KEYWRD *RECEIVED) (#W_KEYVAL *RECEIVED))
DEFINE FIELD(#W_CMDX) REFFLD(#JSMXCMD)
DEFINE FIELD(#W_KEYWRD) REFFLD(#STD_TEXT)
DEFINE FIELD(#W_KEYVAL) REFFLD(#STD_TEXTL)
#W_CMDX += ' ' + #W_KEYWRD + '(' + #W_KEYVAL + ')'
ENDROUTINE
*  Check the status of the JSM command issued
*
SUBROUTINE NAME(CHECK_STS) PARMS(#W_HDLE)
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
DEFINE FIELD(#W_HDLE) TYPE(*CHAR) LENGTH(4)
IF COND('#JSMSTS *NE OK')
#MSGDTA := 'Error Status Code: ' + #JSMSTS
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
#MSGDTA := 'Error Message: ' + #JSMMSG
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDIF
ENDROUTINE
 

     Notice the commands used to Open JSMX, Load the FTPService Service, Unload the Service and Close JSMX.

  • Notice the use of the KEYWRD subroutine for an easy way to build the JSM command keywords and their values. Details of the KEYWRD subroutine are explained in INT003 - Using the FTP Service .
  • Notice the use of the CHECK_STS subroutine after each JSM command for error handling. This routine simply formats the error message. It does not ABORT the function when an error occurs.
  • The CHECK_STS subroutine requires a parameter that specifies Handle to check status on, since multiple connections to the JSM server could be open at the same time.