-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmsSimple.rpgle
141 lines (94 loc) · 3.02 KB
/
msSimple.rpgle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<%@ language="RPGLE" pgmtype="srvpgm" pgmopt="export(*ALL)" %>
<%
ctl-opt copyright('System & Method (C), 2019');
ctl-opt decEdit('0,') datEdit(*YMD.) nomain;
ctl-opt bndDir('NOXDB' );
/* -----------------------------------------------------------------------------
CRTICEPGM STMF('/www/IceBreak-Samples/msSimple.rpgle') SVRID(samples)
By Date PTF Description
------ ---------- ------- ---------------------------------------------------
NLI 22.06.2019 New program
----------------------------------------------------------------------------- */
/include noxDB
/include qasphdr,iceUtility
/* -------------------------------------------------------------------- *\
The mother of all samples: hellow world
http://my_ibm_i:60060/router/msSimple/Hello?payload={
"message":"My name is John"
}
\* -------------------------------------------------------------------- */
dcl-proc HelloWim export;
dcl-pi *n pointer;
pInput pointer value;
end-pi;
dcl-s pOutput pointer;
pOutput = json_newObject();
json_setStr (pOutput: 'text' : 'Hello world ');
json_setDate (pOutput: 'date' : %date());
json_setTime (pOutput: 'time' : %time());
json_setStr (pOutput: 'message' : json_getStr(pInput : 'message'));
return pOutput;
end-proc;
/* -------------------------------------------------------------------- *\
returns sum of x and y
http://my_ibm_i:60060/router?payload={
"action":"msSimple.sum",
"x": 123,
"y": 456
}
\* -------------------------------------------------------------------- */
dcl-proc sum export;
dcl-pi *n pointer;
pInput pointer value;
end-pi;
dcl-s pOutput pointer;
dcl-s x int(10);
dcl-s y int(10);
x = json_getnum(pInput : 'x');
y = json_getnum(pInput : 'y');
pOutput = json_newObject();
json_setInt(pOutput : 'sum' : x + y);
return pOutput;
end-proc;
/* -------------------------------------------------------------------- *\
division - can it handle divide by zero?
http://my_ibm_i:60060/router/msSimple/divide?payload={
"x": 125,
"y": 10
}
\* -------------------------------------------------------------------- */
dcl-proc divide export;
dcl-pi *n pointer;
pInput pointer value;
end-pi;
dcl-s pOutput pointer;
dcl-s x int(10);
dcl-s y int(10);
x = json_getnum(pInput : 'x');
y = json_getnum(pInput : 'y');
pOutput = json_newObject();
json_setInt(pOutput : 'divide' : x / y);
return pOutput;
end-proc;
/* -------------------------------------------------------------------- *\
List products
http://my_ibm_i:60060/router/msSimple/products?payload={}
\* -------------------------------------------------------------------- */
dcl-proc products export;
dcl-pi *n pointer;
pInput pointer value;
end-pi;
dcl-s pResultSet pointer;
dcl-s sqlStmt varchar(4096);
sqlStmt = (`
select *
from icproduct
`);
pResultSet = json_sqlResultSet (
sqlStmt
: 1
: 5
: JSON_META + JSON_TOTALROWS
);
return pResultSet;
end-proc;