In this tutorial, you will create a Processing Sequence that combines the things covered in the earlier tutorials in this set. The objective is to create a Processing Sequence that can:
- Receive and load the JSON request
- Interrogate the Tutorial Orders database to retrieve the requested batch and order number
- Prepare the JSON response containing the selected data matching the request
When complete, you should run your Processing Sequence to test it and verify the results.
As this is an advanced tutorial, it will not provide step-by-step instructions to build the Processing Sequence. Instead, this tutorial will focus on the relationship between the Processing Sequence and the JSM Binding Scripts and simply give you some outline suggestions for creating your own final solution.
The processing sequence can be broken up into the following sections:
1. Build the input path of the JSON file
Use the PATHMAKE activity to build the path and file name of the JSON input file.
2. Retrieve the Batch / Order from REQUESTTUTORD.JSON file by calling the JSM_BINDSCRIPT REQUESTTUTORDJSON
Click the Details tab. Then click the Activities tab in the left pane and locate the JSM_BINDSCRIPT activity and drag and drop it into your Processing Sequence.
Note that an informational message 'Iterator item is empty' appears in the Errors tab. This is normal and can be ignored. The JSM_BINDSCRIPT activity is defined as an iterator activity to facilitate its use with more complex solutions. For this part of the tutorial, we have no need to use the iterator capability.
In the Configurations tab in the left pane, locate the 'REQUESTTUTORDJSON' Binding Script configuration you created in JSM023.
Drag and drop the 'REQUESTTUTORDJSON' configuration into the JSMBINDCONFIG parameter of the JSM_BINDSCRIPT activity.
3. Connect to the server
The SQL_CONNECT activity connects you to the database library as defined in the Database Configuration. If you have not already created a database configuration refer to the section Database Configuration in the LANSA Composer documentation.
3a. Prepare the query appropriate to the platform
This part of the code is building the query string (&MY_QUERY). The Processing Sequence first establishes whether this is an IBM i connection or Windows connection. Depending on the environment and whether an OrderNumber has been entered in the REQUESTTUTORD.JSON file will govern how the query string is constructed.
The SUBSTITUTE activity is used to map the variable &BCHNUM_IN &ORDNUM_IN into the &1 and &2 positions in the query string variable &MY_QUERY. Remember these variables will have been populated in the preceding JSM_BINDSCRIPT activity from the variables #DXBINDFA & #DXBINDFB
3b. Execute a query to select the DISTINCT batch numbers present in the tutorial orders header file (TUTORDH)
The SQL_QUERY activity will run the query as defined in the &MY_QUERY variable. A list of rows on TUTORDH that satisfy the BatchNumber and optionally the OrderNumber is returned.
The variable &ROWS_H is a count of the rows in the list. The variables &BCHNUM_H_OUT, &ORDNUM_H_OUT, &CUSNUM_H_OUT, &ORDDTA_H_OUT are individual lists that contain each rows individual variable.
Row No | BCHNUM_H_OUT | ORDNUM_H_OUT | CUSNUM_H_OUT | ORDDTA_H_OUT |
|---|---|---|---|---|
1 | ABC | 1 | COLES | 15/11/2015 |
2 | ABC | 2 | IGA | 25/11/2015 |
4. For each Batch / Orders found TUTORDH
Read through each row of the returned list. For each row read, copy each variable (identified by the index &COUNT_H). These variables will be used later in the JSM Binding Script
4a. Build a list of Batch / Orders / Lines using SQL over TUTORDL
As in the previous step, this part of the code is building the query string (&MY_QUERY) depending on the environment.
The SUBSTITUTE activity is used to map the variable &BCHNUM_H and &ORDNUM_H into the &1 and &2 positions in query string variable &MY_QUERY. Remember these variables will have been populated from the returned TUTORDH list.
4b. Build output path of the JSON file
Use the CONCAT & PATHMAKE activities to build the path and file name of the JSON output file. The structure of the JSON output file will be RESPONSETUTORD_BatchNumber_OrderNumber.JSON.
4c. Uses the RESPONSETUTORDJSON JSM binding script configuration to write the response
This is in two parts:
a) Single fragment for the selected TUTORDH
A single fragment is written for the TUTORDHRESPONSE. The processing sequence manages the writing of these single fragments by reading the lists entry (by row) and writing them to output fields This will write the fields defined in the preceding Receive Binding list. (&BCHNUM_H, CUSUM_H, ORDNUM_H, ORDDATH,)
b) Multiple fragments for the selected TUTORDL records.
Multiple fragments will be written for TUTORDLRESPONSE. The processing sequence manages the writing of these multiple fragments by reading the lists entry (by row) and writing them to output fields. This will write the fields defined in the preceeding Receive Binding list. (&BCHNUM_L, ORDNUM_L, ORDLIN_L, LINPAR_L, LINPRC_L, LINQTY_L & LINQTY_L).
When you created the JSM Binding script for TUTORDRESPONSE you included two special JSM Directives. These were Perform Iteration and Branch to Label.
The Perform Iteration has a label called LINES. The Branch to Label.directive instructs the JSM Binding script to branch to the label LINES. The Perform Iteration has an ON NIL command that passes control to label WRITE when there are no more fragments to process.
The WRITE label writes all of the created fragments to the output JSON file.
5. Disconnect from the server
The SQL_DISCONNECT activity disconnects you from the database library.
That completes the JSM Binding Script tutorials.








