Step 7. Code iiiFN07 Server Database Logic and SET functionality
INT007 - Department List Inquiry
In this step, you will write the RDMLX to access the database file DEPTAB to FETCH the department description, and write the RDMLX for the server side SET.
1. Following the working list definition DEPTMEN_W, define a second working list DEPTDES_W containing field DEPTESC. This is the list which will be returned. Add code to clear both lists. Your code should look like the following:
* The following lists are used by the xml binding map
DEF_LIST NAME(#DEPTMEN_W) FIELDS(#DEPTMENT) TYPE(*WORKING)
DEF_LIST NAME(#DEPTDES_W) FIELDS(#DEPTMENT #DEPTDESC) TYPE(*WORKING)
CLR_LIST #DEPTMEN_W
CLR_LIST NAME(#DEPTDES_W)
Note: by default a working is defined with 50 entries, which is adequate for this application.
2. Continue working with function iiiFN07. The following needs to be added after the receive logic. Add your code before the comment line:
* Bind service to create HTTP response contentWrite the RDMLX code to:
a. SELECTLIST the department codes from list #DEPTMEN_W (the working list received from the client)
b. FETCH the field #DEPTDESC (department description) from file DEPTAB with key #DEPTMENT Check the I/O status of the FETCH operation. If it is not *OKAY, change the department description to the literal 'Department not found'.
c. ADD the entry into the department description working list #DEPTDES_W
d. ENDSELECT
Your RDMLX code might appear as follows:
SELECTLIST NAMED(#DEPTMEN_W)
**********
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT)
IF_STATUS IS_NOT(*OKAY)
CHANGE FIELD(#DEPTDESC) TO('DEPARTMENT NOT FOUND')
ENDIF
ADD_ENTRY TO_LIST(#DEPTDES_W)
ENDSELECT
**********
3. Write the RDMLX to reverse the contents of #STD_TEXT using the REVERSE Built-In Function. Use the Trim intrinsic function to remove any leading or trailing blank spaces in the text.
Your RDMLX code might appear as follows:
********** REVERSE THE STRING
#STD_TEXTS := #STD_TEXTS.Reverse.Trim
**********
4. In your Studio project, expand the folder SAMPLE_RDMLX_OUTBOUND_HTTP.TXT to open it in the test editor.
and double click on the file5. Select the highlighted code:
6. Replace the following code in function iiiFN07 with the code above:
* 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)
7. In the added code DEPARTMENT with DEPTDES_W. Replace whole words only.
list name8. In the CHECK subroutine, add an ABORT command to the IF..ENDIF statement so that the program ends if an error has occurred.
9. Compile the function. If you are using an IBM i JSM Server, check it in and compile on the IBM i.
Your finished RDMLX code might appear as follows:
FUNCTION OPTIONS(*DIRECT)
* The following fields are used by the xml binding map
* #DEPTMENT
* #STD_TEXTS
* The following fragments are used by the xml binding map
GROUP_BY NAME(#LISTREQ) FIELDS(#STD_TEXTS)
* The following lists are used by the xml binding map
DEF_LIST NAME(#DEPTMEN_W) FIELDS(#DEPTMENT) TYPE(*WORKING)
DEF_LIST NAME(#DEPTDES_W) FIELDS(#DEPTMENT #DEPTDESC) TYPE(*WORKING)
CLR_LIST NAMED(#DEPTMEN_W)
CLR_LIST NAMED(#DEPTDES_W)
* 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(IIIPRO05_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 - DEPARTMENTLISTREQUEST
CHANGE FIELD(#JSMXCMD) TO('GET FRAGMENT(DEPARTMENTLISTREQUEST) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Get list - DEPARTMENT
CHANGE FIELD(#JSMXCMD) TO('GET LIST(DEPARTMENT)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #DEPTMEN_W)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
SELECTLIST NAMED(#DEPTMEN_W)
*
FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT)
IF_STATUS IS_NOT(*OKAY)
CHANGE FIELD(#DEPTDESC) TO('DEPARTMENT NOT FOUND')
ENDIF
ADD_ENTRY TO_LIST(#DEPTDES_W)
ENDSELECT
*
* REVERSE THE STRING
#STD_TEXTS := #STD_TEXTS.Reverse.Trim
*
* <<< Outbound binding logic goes here >>>
*
* Bind service to create HTTP request content
CHANGE FIELD(#JSMXCMD) TO('BIND SERVICE(IIIPRO05_RESPONSE) TYPE(*OUTBOUND)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Set fragment - DEPARTMENTLISTRESPONSE
CHANGE FIELD(#JSMXCMD) TO('SET FRAGMENT(DEPARTMENTLISTRESPONSE) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMXSTS #JSMXMSG)
* Set list - DEPARTMENT
CHANGE FIELD(#JSMXCMD) TO('SET LIST(DEPARTMENT)')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMXSTS #JSMXMSG #DEPTDES_W)
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 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)
ABORT
ENDIF
ENDROUTINE