...
The custData
as returned from that REST service might be a JSON object like this:
...
Code Block | ||
---|---|---|
| ||
{ "custno": 1234, |
...
"name": "Industrial Supply Ltd", |
...
"street": "123 Sesame Street", |
...
"city": "New York", |
...
"state": "NY", |
...
"postal": "12345-4321" |
...
} |
Use plugin "Call IBM i Program" to call the IBM i program. For the parameter definition, if the "data type" is "data stucture", the "elements" question is displayed. Click button "Define subfields..." to display a dialog where you can define the data structure subfields, as defined in the RPG code. For the "argument value" question, specify the work variable custData
.
...
Code Block |
---|
Fcustadrp if e k disk * D custnoIn s 4s 0 * D custDataOut ds D custno 4s 0 D name 30 D street 30 D city 20 D state 2 D postal 10 * C *entry plist C parm custnoIn C parm custDataOut * C clear custDataOut C custnoIn chain custadrp C move *on *inlr C return |
You can create a PAPI file, define a "get" route, with the Input Parameters and Output Parameters as shown below.
...
The JSON data returned should be like this:
Code Block | ||
---|---|---|
| ||
{
"data": {
"custno": 1234,
"name": "My Company ",
"street": "123 Sesame Street ",
"city": "New York ",
"state": "NY",
"postal": "12345-4321"
}
} |
Notes on data structure parameter:
- The subfield names as defined in low-code dialog "Define Data Structure Fields" do not have to match the field names as defined in the RPG program.
- However, the attributes (data type, length, etc) must match.
- Nested data structures are supported. You can define a subfield as data type "data structure", then right click on the subfield and take option "Add child subfield" to define the subfields for that data structure subfield. Below is an example where the subfield "addr" is a data structure made up of four child subfields.
- If you specify the option "capture output" as "Into work variable":
- You do not have to declare the work variable previously; it's declared for you.
- The work variable is a JavasScript object, with one property for each subfield of the data structure, so in low-code you can refer to each "subfield" as
workvar.subfield
. - In the actual PJS code generated for the plugin, API pjs.toObject() is used to convert the data from the RPG data structure into the JavaScript object
workvar
. You can refer to that API for more information.
- If you have the RPG code for the parameter interface, you do not have to manually define the parameters. You can click button "Extract parameters from RPG code snippet", paste the RPG code, and click button "Generate Parameters". The definitions for all parameters (including data structure parameters) are populated for you in the low-code plugin panel. For a data structure parameter, after it's extracted from the RPG code, you can click button "Define subfields..." to verify that the subfield definitions are correct as extracted.
Info |
---|
"Extract parameters from RPG code snippet" works with both fixed and free format RPG code. If using free format code make sure to either indented each line with seven blanks or add **free before adding in any code. |