SET
The SET command is used for two distinct operations. Use the DIR keyword to set the current working directory or alternatively use the LIST or FRAGMENT keywords to populate the outbound document object.
Once you have completed your SET commands your next command would invariably be the WRITE command.
Conditional
SET ---------- LIST ---------- value ---------------------------->
>-- FRAGMENT ------ value ---------------------------->
>-- DIR ----------- value ----------------------------|
Keywords
LIST |
This keyword is used to place a list of values into a JSON document. Refer to the Lists and Variables section below for further details on how to use this keyword. The LIST keyword does not have any relationship with the DIR keyword. This keyword is conditional. |
FRAGMENT |
This keyword is used to place a field or group of fields into a JSON document. Refer to the Lists and Variables section below for further details on how to use this keyword. The FRAGMENT keyword does not have any relationship with the DIR keyword. This keyword is conditional. |
DIR |
This keyword is used to nominate a relative or absolute path to be set as the current directory. The DIR keyword does not have any relationship with the other keywords for the SET command. This keyword is conditional. |
Comments / Warnings
There are two possible ways to add a list of data when creating a JSON document.
1. The most obvious way is to use the SET command described here with the LIST keyword, then specifying the array in a working list. With this approach the section o JSON would need to be defined as a list in the JSON Binding Wizard.
2. Alternatively, the same could be achieved by using the FRAGMENT keyword inside some looping code. Each loop would add a new row to the list. With this approach the section of JSON would need to be defined as a fragment in the JSON Binding Wizard.
Whichever way you choose, you will need to carefully decide whether the relevant section of JSON is defined as a List or a Fragment.
See the Examples following how to do this.
Lists and Variables
If you are using the LIST keyword to create a list in an JSON document, you will need to ensure the following steps are taken in your program.
1. Define a working list that contains the fields that will be passed to the JSON document.
2. Use the SERVICE_LIST keyword with the LIST keyword in the SET command. The service list value should include the names of the fields in the working list without the '#'. The order of the fields should be defined here as they appear in the working list.
3. In the TO_GET portion of the JSM_COMMAND Built-In Function, include the name of the working list that will hold the values to be placed in the JSON document.
If you are using the FRAGMENT keyword to add a field or group of fields, then you will need to add the SERVICE_EXCHANGE keyword with a value of '*FIELD'. How to do this is shown in the Examples following.
Examples
RDML
* Define JSM fields
DEFINE FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(020)
DEFINE FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(256)
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)
* Define Order Line fields
DEFINE FIELD(#LINNUM) TYPE(*DEC) LENGTH(003) DECIMALS(0) COLHDG('Line')
DEFINE FIELD(#PARTNUM) TYPE(*DEC) LENGTH(003) DECIMALS(0) COLHDG('Part #')
DEFINE FIELD(#PARTDSC) TYPE(*CHAR) LENGTH(030) COLHDG('Descrption')
DEFINE FIELD(#PARTAMT) TYPE(*DEC) LENGTH(010) DECIMALS(2) COLHDG('Amount')
DEFINE FIELD(#PARTQTY) TYPE(*DEC) LENGTH(003) DECIMALS(0) COLHDG('Quantity')
* Define the list to hold the order lines
DEF_LIST NAME(#WRKLINES) FIELDS(#LINNUM #PARTNUM #PARTDSC #PARTAMT #PARTQTY) TYPE(*WORKING)
* Set customer details
USE BUILTIN(JSM_COMMAND) WITH_ARGS('SET FRAGMENT(CUSTOMER) SERVICE_EXCHANGE(*FIELD)') TO_GET(#JSMSTS #JSMMSG)
* Set SalesOrder header details
CHANGE FIELD(#JSMCMD) TO('SET FRAGMENT(SALESORDER) SERVICE_EXCHANGE(*FIELD)')
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
CHANGE FIELD(#JSMCMD) TO('SET LIST(LINE) SERVICE_LIST(LINNUM,PARTNUM,PARTDSC,PARTAMT,PARTQTY)')
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #WRKLINES)
RDML
* Define the fields used by the JSM Commands
Define Field(#JSMSTS) Type(*CHAR) Length(020)
Define Field(#JSMMSG) Type(*CHAR) Length(256)
Define Field(#JSMCMD) Type(*CHAR) Length(256)
Define Field(#JSMHND) Type(*CHAR) Length(4)
Define FIELD(#LINENUM) TYPE(*DEC) LENGTH(003) DECIMALS(0) LABEL('Line #')
Define FIELD(#PARTNUM) TYPE(*DEC) LENGTH(003) DECIMALS(0) LABEL('Part #')
Define FIELD(#PARTDSC) TYPE(*CHAR) LENGTH(020) LABEL('Part Desc.')
Define FIELD(#PARTAMT) TYPE(*DEC) LENGTH(010) DECIMALS(2) LABEL('Amount')
Define FIELD(#PARTQTY) TYPE(*DEC) LENGTH(003) DECIMALS(0) LABEL('Quantity')
Define Field(#LINSTAT) Type(*CHAR) Length(20) Label('Line Status')
Def_List Name(#RSPLINES) Fields(#LINENUM #PARTNUM #PARTDSC #PARTAMT #PARTQTY #LINSTAT) Type(*WORKING)
* Set the customer details
#JSMCMD := 'SET FRAGMENT(CUSTOMER) SERVICE_EXCHANGE(*FIELD)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)
* Set the order details by using SET FRAGMENT a number of times
Selectlist Named(#RSPLINES)
#JSMCMD := 'SET FRAGMENT(LINE) SERVICE_EXCHANGE(*FIELD)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)
#JSMCMD := 'SET FRAGMENT(PART) SERVICE_EXCHANGE(*FIELD)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)
Endselect