Emit Data Structures
In the above example, you unknowingly issued a tree-type data structure using £JAX
/COPY. In this guide you learn how return data structures in RPGLE service.
Emit a Tree Data Structure
The single node of a tree structure is composed by the following attributes:
- object type
- object parameter
- object code
- value
- action
In order to output a tree node, specific £JAX
variables must be set and in the end execute the £JAX_ADDO
routine.
The variables are:
£JAXT1
: object type£JAXP1
: object parameter£JAXK1
: object code£JAXD1
: value£JAXOP
: action£JAXEN
: flag to set that the following node are child nodes
The following service emit a folder like structure using Tree Data Structure.
* import £JAX definitions
D/COPY QILEGEN,£JAX_D
*--------------------------------------------------------------------------------------------*
* M A I N
*--------------------------------------------------------------------------------------------*
* create node 1
C EVAL £JAXT1='J1'
C EVAL £JAXP1='PATHFILE'
C EVAL £JAXK1='/etc/kokos/'
C EVAL £JAXEN='>'
C EXSR £JAX_ADDO
* create node 1.1
C EVAL £JAXT1='J1'
C EVAL £JAXP1='PATHFILE'
C EVAL £JAXK1='/etc/kokos/libs'
C EVAL £JAXEN='>'
C EXSR £JAX_ADDO
* create node 1.1.1
C EVAL £JAXT1='J1'
C EVAL £JAXP1='PATHFILE'
C EVAL £JAXK1='/etc/kokos/libs/kokos-dsl-master'
C EXSR £JAX_ADDO
* create node 1.1.2
C EVAL £JAXT1='J1'
C EVAL £JAXP1='PATHFILE'
C EVAL £JAXK1='/etc/kokos/libs/kokos-dsl-develop'
C EXSR £JAX_ADDO
* close node 1.1
C EXSR £JAX_CLOO
* create node 1.2
C EVAL £JAXT1='J1'
C EVAL £JAXP1='PATHFILE'
C EVAL £JAXK1='/etc/kokos/configs'
C EXSR £JAX_ADDO
* close first node
C EXSR £JAX_CLOO
*
C SETON LR
*--------------------------------------------------------------------------------------------*
* Import £JAX implementations
C/COPY QILEGEN,£JAX_C
Result:
J1;PATHFILE;/etc/kokos/
|
└─── J1;PATHFILE;/etc/kokos/libs
| |
| └───J 1;PATHFILE;/etc/kokos/libs/kokos-dsl-master
| |
| └─── J1;PATHFILE;/etc/kokos/libs/kokos-dsl-develop
|
└─── J1;PATHFILE;/etc/kokos/configs
EXSR £JAX_ADDO
allows to write a node but the node can be a child node. £JAXEN = '>'
causes subsequent nodes to be children. To stop the writing of child nodes you can use EXSR £JAX_CLOO
. If the node hasn't child nodes you can omit EXSR £JAX_CLOO
.
Emit a Data Table Structure
The data table is based on columns and rows and each rows contais cells. To emit a Data Table you can emit data in two steps:
- create and emit the data grid
- create and emit row by row
The method to emit data structure is the same as Tree. You can evaluate some variables and execute a specified routine.
To properly create the data table grid you must define an array with size as number of columns and CTDATA PERRCD(1)
specification. The array data is defined in the end of program. Each row is read positionally and converted to the respective column:
- from character 0 to 10: column id
- from character 10 to 39: column description
- from character 39 to 60: object
- from character 60 to 61: input or output
To properly emit the row you must evaluate the £JAXCP
variable inlcuding all cells divided by |
character.
* define an array like variable for the grid. The definition is in bottom of RPGLE source
D SWKCONTACTS S 100 DIM(3) CTDATA PERRCD(1) _£JAXSWK
* import £JAX definitions
D/COPY QILEGEN,£JAX_D
*--------------------------------------------------------------------------------------------*
* M A I N
*--------------------------------------------------------------------------------------------*
* create columns
C EVAL £JAXSWK=SWKCONTACTS
C EXSR £JAX_AGRI
* creare row - Initialization
C EXSR £JAX_ARIG_I
* create first row
C EVAL £JAXCP='COL|ROSMAR|Rossi Mario'
C EXSR £JAX_ARIG
* create second row
C EVAL £JAXCP='COL|BIAMAR|Bianca Maria'
C EXSR £JAX_ARIG
* Cceare row - Finalization
C EXSR £JAX_ARIG_I
*
C SETON LR
*--------------------------------------------------------------------------------------------*
* Import £JAX implementations
C/COPY QILEGEN,£JAX_C
* Define columns
** SWKCONTACTS
TYPE Contact
CODE Code CNCOL
NAM Name
Result:
Contact | Code | Name |
---|---|---|
COL | ROSMAR | Rossi Mario |
COL | BIAMAR | Bianca Maria |