Step by step service implementation
In this chapter we will proceed step by step to modify the X1_X01_03.rpgle
service file that we created in the previous chapter, to include the logic that can perform the required task.
For each step that will be added to the source, a brief explanation of how it works is provided. For this chapter, the user is required to have a basic knowledge of RPGLE programming.
1. Structure of MAIN: logic of the "function-method" matcher
This SELECT-WHEN-OTHER
block is used to direct the flow of execution in function of the £UIBME
value (the function.method value in the FUN).
In our case, we need to check if the value is GET
: if true, then execute a subroutine, FGETACT
.
*--------------------------------------------------------------------------------------------*
C EXSR IMP0
*
C SELECT
C WHEN %TRIM(£UIBME)='GET'
C EXSR FGETACT
*
C ENDSL
*
C EXSR FIN0
*--------------------------------------------------------------------------------------------*
2. Subroutine Creation of the SmeupDataTable
*--------------------------------------------------------------------------------------------*
* GET - Get activities in the form of a data table
*--------------------------------------------------------------------------------------------*
C FGETACT BEGSR
*
* 1. Initialization SmeupDataTable
*
* 2. Reading DB table rows in SmeupDataTable
*
C ENDSR
*--------------------------------------------------------------------------------------------*
- 2.1 Initialization columns SmeupDataTable
The columns of a SmeupDataTable must be defined as an array at the end of the file. Let's start by defining an array in the D
specifications. The array must be 7 elements long, of size 100, and have the specification _£JAXSWK
:
D ACTCLM S 100 DIM(7) CTDATA PERRCD(1) _£JAXSWK
At the bottom of the file we build the array by defining the codes of the columns in the database, the textual description, the data type and the size of the field
** ACTCLM
X1DATE Date D8*YYDM 8
X1DESC Description 50
X1STIM Start I12 6
X1ETIM End I12 6
X1STCT Style category 5
X1CTGR Category 20
X1HOUR Hours NR 4;2
In the FGETACT
subroutine set the columns of the SmeupDataTable by saving the array just created in the variable £JAXSWK
and calling £JAX_AGRI
:
*--------------------------------------------------------------------------------------------*
C FGETACT BEGSR
*
* Create columns
C EVAL £JAXSWK=ACTCLM
C EXSR £JAX_AGRI
*
* 2.2 Reading DB table rows in SmeupDataTable
*
C ENDSR
*--------------------------------------------------------------------------------------------*
- 2.2 Reading DB table rows in SmeupDataTable
As a matter of practice, the keys for performing CRUD operations on databases are defined in the £INIZI
subroutine or in IMP0
.
*--------------------------------------------------------------------------------------------*
C £INIZI BEGSR
*
C KEY0L KLIST
C KFLD X1DATE
*
C ENDSR
*--------------------------------------------------------------------------------------------*
In the D
specification we define the logical file used in read operations. Since we do not need to perform any further operations, it is sufficient to define it as read:
FX1_X010L IF E K DISK
To generate the rows of the matrix, the program performs the following in sequence:
- to define the rows of the matrix by calling
£JAX_ARIG_I
SETLL
operation with the key initialized to zero: the reading index is positioned above the first element of the table;- Endless
DO
cycle (DO *HIVAL
) in which to read the next row (READ
); - for each row read, I build the string
£JAXCP
as a concatenation of the elements of the row read from the database separated by the character|
; - Save the row created by calling
£JAX_ARIG
: the£JAXCP
row is saved as a row in theSmeupDataTable
that will be generated by the service; - Repeat cycle with reading of the next row. It ends at the end of reading the entire database, when the
%EOF
specification is activated;
* Eval Key
* Create row - Initialization
C EXSR £JAX_ARIG_I
*
C EVAL X1DATE='0000000000'
* Load data
C KEY0L SETLL X1_X010L
*
C DO *HIVAL
* Read record
C READ X1_X010L
C IF %EOF
C LEAVE
C ENDIF
* Return record
C EVAL £JAXCP=%TRIM(X1DATE)+'|'+
C %TRIM(X1DESC) +'|'+
C %TRIM(X1STIM) +'|'+
C %TRIM(X1ETIM) +'|'+
C %TRIM(X1STCT) +'|'+
C %TRIM(X1CTGR) +'|'+
C %TRIM(%CHAR(X1HOUR))
C EXSR £JAX_ARIG
*
C ENDDO
Congratulations! You have just completed your first Smeup RPGLE service. In the next chapter you will be able to compare and test your work.