Step 6 Code iiiFN09 Client GET functionality

LANSA Integrator

Step 6. Code iiiFN09 Client GET functionality

INT009 – Department & Employee Client (Optional)

In this step you will use the inbound part of the RDMLX generated for the Client XML Employees Response solution to complete function iiiFN09.

1.   With your iii Training project open in Studio, expand the folder Solutions / Client XML Employees Response / sample / RDMLX and copy the following code from SAMPLE_RDMLX_INBOUND_HTTP.TXT into function iiiFN09 following the comment * <<< Inbound binding logic goes here >>>

* Bind service to read HTTP request content
CHANGE     FIELD(#JSMXCMD) TO('BIND SERVICE(IIIPRO07_RESPONSE) TYPE(*INBOUND) BINDTRACE(*YES)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Get fragment - EMPLOYEELIST
CHANGE     FIELD(#JSMXCMD) TO('GET FRAGMENT(EMPLOYEELIST) SERVICE_EXCHANGE(*FIELD)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* <<< Enter the fragment loop logic for EMPLOYEE >>>
BEGIN_LOOP /* EMPLOYEE */
* Get fragment - EMPLOYEE
CHANGE     FIELD(#JSMXCMD) TO('GET FRAGMENT(EMPLOYEE) SERVICE_EXCHANGE(*FIELD)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
LEAVE      IF('#JSMXSTS *EQ NOFRAGMENT')
EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Get list - EMPLOYEESKILL
CHANGE     FIELD(#JSMXCMD) TO('GET LIST(EMPLOYEESKILL)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #EMPLOYEESKILL)
EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
END_LOOP /* EMPLOYEE */
 

2.  Change the working list name in the * Get list – EMPLOYEESKILLS logic. The TO_GET keyword needs to refer to your working list #EMPSKILL. (Define at the top of the function the list as DEF_LIST NAME(#empskill) FIELDS(#skildesc) TYPE(*working) ENTRYS(9999) )
Review the code just inserted and note that it includes all the response logic which was outlined in Step 5. i.e.

  • BIND to response service
  • GET employeelist fragment
  • .Loop to GET employee fragment, GET list employeeskill and build skills working list

3. You can improve this logic by handling the condition where an employee has no skills. Add a CONTINUE if JSMXSTS = NOLIST, following the * Get List – EMPLOYEESKILL block of code. This block of code should now look like the following:

* Get list - EMPLOYEESKILL
CHANGE     FIELD(#JSMXCMD) TO('GET LIST(EMPLOYEESKILL)')
USE        BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #EMPLOYEESKILL)

CONTINUE IF('#JSMXSTS *EQ NOLIST')

4.  Your function currently loops and retrieves each employee fragment (EMPNO and FULLNAME) and a list of skills for that employee. Function iiiFN09 needs to save the fullname and skills data into a second working list, which will be returned to the calling display function iiiFN10. Add logic before the END_LOOP to read the #EMPSKILL list and add entries to working list #WL_EMPSKL. Your new code should look like the following:

SELECTLIST NAMED(#empskill)

ADD_ENTRY TO_LIST(#wl_empskl)

ENDSELECT

5.  Add a RETURN command after the JSM CLOSE

6.  The CHECK subroutine from the Studio generated code simply returns to the menu if status is not OK. Replace the routine with the following logic, which will display messages containing the JSM status and the JSM message. This will be useful for testing purposes.

* Check routine
SUBROUTINE NAME(CHECK) PARMS((#JSMXSTS *RECEIVED) (#JSMXMSG *RECEIVED))
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
*
IF COND('#JSMXSTS *NE OK')
#MSGDTA := 'Error Status Code: ' + #JSMXSTS
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
#MSGDTA := 'Error Message: ' + #JSMXMSG
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMXSTS #JSMXMSG)
ABORT
ENDIF
*
ENDROUTINE
 

Your completed RDMLX code might appear as follows:

FUNCTION OPTIONS(*DIRECT) RCV_LIST(#wl_empskl)
* The following fields are used by the xml binding map
* #DEPTMENT
* The following fragments are used by the xml binding map
GROUP_BY NAME(#DEPTREQ) FIELDS(#DEPTMENT)
DEF_LIST NAME(#empskill) FIELDS(#skildesc) TYPE(*working) ENTRYS(9999)
DEF_LIST NAME(#WL_EMPSKL) FIELDS(#FULLNAME #SKILDESC) TYPE(*WORKING) ENTRYS(9999)
* Open service
USE BUILTIN(JSMX_OPEN) TO_GET(#JSMXSTS #JSMXMSG #JSMXHDLE1)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Load service
CHANGE FIELD(#JSMXCMD) TO('SERVICE_LOAD SERVICE(HTTPOutboundXMLBindService) TRACE(*YES)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Bind service to create HTTP request content
CHANGE FIELD(#JSMXCMD) TO('BIND SERVICE(IIIPRO07_REQUEST) TYPE(*OUTBOUND)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Set fragment - DEPARTMENTREQUEST
CHANGE FIELD(#JSMXCMD) TO('SET FRAGMENT(DEPARTMENTREQUEST) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)

* Write content
CHANGE FIELD(#JSMXCMD) TO('WRITE INDENT(*YES) BINDTRACE(*YES)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Send HTTP request content
CHANGE FIELD(#JSMXCMD) TO('SEND HOST(10.44.10.236:80) URI(/cgi-bin/jsmdirect?IIIFN08_SERVICE)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* <<< Inbound binding logic goes here >>>
* Bind service to read HTTP request content
CHANGE FIELD(#JSMXCMD) TO('BIND SERVICE(IIIPRO07_RESPONSE) TYPE(*INBOUND) BINDTRACE(*YES)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Get fragment - EMPLOYEELIST
CHANGE FIELD(#JSMXCMD) TO('GET FRAGMENT(EMPLOYEELIST) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* <<< Enter the fragment loop logic for EMPLOYEE >>>
BEGIN_LOOP /* EMPLOYEE */
* Get fragment - EMPLOYEE
CHANGE FIELD(#JSMXCMD) TO('GET FRAGMENT(EMPLOYEE) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
LEAVE IF('#JSMXSTS *EQ NOFRAGMENT')
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Get list - EMPLOYEESKILL
CHANGE FIELD(#JSMXCMD) TO('GET LIST(EMPLOYEESKILL)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #EMPSKILL)

CONTINUE IF('#JSMXSTS *EQ NOLIST')

EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
SELECTLIST NAMED(#empskill)
ADD_ENTRY TO_LIST(#wl_empskl)
ENDSELECT
END_LOOP /* EMPLOYEE */
* Close binding
CHANGE FIELD(#JSMXCMD) TO('CLOSE')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)* Unload service
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 'SERVICE_UNLOAD') TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Close service
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
RETURN
* Check routine
SUBROUTINE NAME(CHECK) PARMS((#JSMXSTS *RECEIVED) (#JSMXMSG *RECEIVED))
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
*
IF COND('#JSMXSTS *NE OK')
*
#MSGDTA := 'Error Status Code: ' + #JSMXSTS
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
#MSGDTA := 'Error Message: ' + #JSMXMSG
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMXSTS #JSMXMSG)ABORT
*
ENDIF
*
ENDROUTINE
 

6.  Save and compile the function and check in to the server.