Step 7 Code iiiFN08 Server Database Logic and SET functionality

LANSA Integrator

Step 7. Code iiiFN08 Server Database Logic and SET functionality

INT008 - Department & Employee Server

In this step, you will write the RDMLX to SELECT using the logical view PSLMST1 (Personnel by Department) to get a list of employees, then SELECT over the file PSLSKL (Personnel Skills) to get a list of that employee's skills. The RDMLX for the server side SET will be performed inline during this internal logic. This is different from previous exercises, where the internal logic and SET commands were separated sequentially.

 In this exercise, you will not be performing each of these commands in sequence, after the internal logic is finished. Instead, the outbound BIND and root fragment SET will come immediately after the inbound BIND and GET commands (before any database accesses). Two more SET commands will go into the outer SELECT statement. Finally, the WRITE and SEND commands will follow the last ENDSELECT.

     The overall structure of the iiiFN08 function is as follows:

1.  JSMX_OPEN

2.    SERVICE_LOAD (HTTPInboundXMLBindService)

3.     BIND (inbound)

4.     GET (department code fragment)

5.     BIND (outbound)

6.     SET (employee list fragment)

7.     SELECT over PSLMST1

        a.  SELECT over PSLSKL

        b.  FETCH from SKLTAB

        c.  ENDSELECT

        d.  SET (employee fragment)

        e.  SET (employee skill list)

8.     ENDSELECT

9.     WRITE

10.   SEND

11.  JSMX_CLOSE

1.  In your function iiiFN08 locate the following code and delete it:

* Bind service to create HTTP response content
CHANGE FIELD(#JSMXCMD) TO('BIND SERVICE( <<<outbound.class>>> ) TYPE(*OUTBOUND)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
 

2.  With your iii Training project open in Studio, in the folder Server XML Employees Response /samples / RDMLXopen the file SAMPLE_RDMLX_OUTBOUND_HTTP.txt in the Text Editor. Locate the highlighted code:

     Copy and paste the highlighted code into your function, to replace the deleted code block.

3.  Add a working list definition named EMPWORK to the top of your function containing field SKILDESC. This is the list of skills for each employee, which is to be returned. Your code should look like the following:
DEF_LIST NAME(#EMPWORK) FIELDS(#SKILDESC) TYPE(*WORKING) ENTRYS(*MAX)

4.  After the outbound BIND and SET logic just added, write the RDMLX code to:

a.  SELECT employee numbers and names from the logical file PSLMST1, using the DEPTMENT key field.

b.  Inside the SELECT, set up the field Fullname from the Given Name and Surname fields.

c.  Still within that SELECT loop, CLR_LIST EMPWORK, then SELECT over PSLSKL to get a list of skill codes for each employee, using the employee number.

d.  Inside the inner (nested) SELECT, FETCH the skill description from SKLTAB for each skill code.

e.  ADD the entry into the employee skills working list EMPWORK.

f.  End both SELECTS.

     The RDMLX code might appear as follows:

SELECT FIELDS(#EMPNO #SURNAME #GIVENAME) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT)
#FULLNAME := #GIVENAME + ' ' + #SURNAME
CLR_LIST NAMED(#EMPWORK)
SELECT FIELDS(#SKILCODE) FROM_FILE(PSLSKL) WITH_KEY(#EMPNO)
FETCH FIELDS(#SKILDESC) FROM_FILE(SKLTAB) WITH_KEY(#SKILCODE)
ADD_ENTRY TO_LIST(#EMPWORK)
ENDSELECT

* Set employee fragment

* Set employeeskills list
ENDSELECT
 

     Note: Comments have been added to this code for clarity in the next steps.

5.  As before, you will complete the function by using code generated for you in the SAMPLE_RDMLX_OUTBOUND_HTTP.txt file. Locate the highlighted code:

6.  Copy the highlighted code shown above into your function to replace the comments included in step 4f .

* Set employee fragment

* Set employeeskills list
 

7.  Change the working list name in the TO_GET() keyword to  refer to your list #EMPWORK.  Your code should look like the following:

*set list - EMPLOYEESKILL

CHANGE FIELD(#JSMXCMD) TO('SET LIST(EMPLOYEESKILL)')

USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #EMPWORK)

8.  Review your function's RDMLX code following the last ENDSELECT. You will find that the generated code which you copied initially, already contains the required WRITE, SEND and CLOSE logic.

9.  In the CHECK subroutine, add an ABORT command to the IF..ENDIF statement so that the program ends if an error has occurred.

10.Save and compile the function. If you are using an IBM i JSM Server, check it into the IBM i and compile it.

     Your finished RDMLX code might appear as follows:

FUNCTION OPTIONS(*DIRECT)

* 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(#empwork) FIELDS(#skildesc) ENTRYS(200)

* 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(HTTPInboundXMLBindService) SERVICE_CONTENT(*HTTP) TRACE(*YES)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)

* Bind service to read HTTP request content
CHANGE FIELD(#JSMXCMD) TO('BIND SERVICE(IIIPRO06_REQUEST) 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 - DEPARTMENTREQUEST
CHANGE FIELD(#JSMXCMD) TO('GET FRAGMENT(DEPARTMENTREQUEST) SERVICE_EXCHANGE(*FIELD)')
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(IIIPRO06_RESPONSE) TYPE(*OUTBOUND)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)

* Set fragment - EMPLOYEELIST
CHANGE FIELD(#JSMXCMD) TO('SET FRAGMENT(EMPLOYEELIST) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)

SELECT FIELDS(#EMPNO #SURNAME #GIVENAME) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT)
#FULLNAME := #GIVENAME + ' ' + #SURNAME
CLR_LIST NAMED(#EMPWORK)
SELECT FIELDS(#SKILCODE) FROM_FILE(PSLSKL) WITH_KEY(#EMPNO)
FETCH FIELDS(#SKILDESC) FROM_FILE(SKLTAB) WITH_KEY(#SKILCODE)
ADD_ENTRY TO_LIST(#EMPWORK)
ENDSELECT
* Set fragment - EMPLOYEE
CHANGE FIELD(#JSMXCMD) TO('SET FRAGMENT(EMPLOYEE) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)

* Set list - EMPLOYEESKILL
CHANGE FIELD(#JSMXCMD) TO('SET LIST(EMPLOYEESKILL)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #EMPWORK)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
ENDSELECT

* 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 response content
CHANGE FIELD(#JSMXCMD) TO('SEND')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) 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)

* Check routine
SUBROUTINE NAME(CHECK) PARMS((#JSMXSTS *RECEIVED) (#JSMXMSG *RECEIVED))
IF COND('#JSMXSTS *NE OK')
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMXSTS #JSMXMSG)
ENDIF
ENDROUTINE