Sample for DATASET · KcsDev1982/sunbelt-plb-samples@ea2eb9d · GitHub
Skip to content

Commit ea2eb9d

Browse files
committed
Sample for DATASET
Samples for the DATASET video
1 parent 662cc38 commit ea2eb9d

4 files changed

Lines changed: 177 additions & 1 deletion

File tree

‎basicsamples/basicsamples.prj‎

Lines changed: 4 additions & 1 deletion

‎basicsamples/dataset2.pls‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
INCLUDE PLBEQU.INC
3+
4+
DataSet1 DATASET
5+
JsonText DIM 500
6+
JsonOut DIM 500
7+
CustKey DIM 20
8+
Flags FORM 5
9+
10+
CREATE DataSet1
11+
SETPROP DataSet1, DATATYPE=$DST_JSON
12+
13+
*--------------------------------------------------------------*
14+
* Add first JSON object *
15+
*--------------------------------------------------------------*
16+
MOVE "{""Name"":""John Doe"",""Age"":30,""Status"":""Active""}" TO JsonText
17+
MOVE "CUST001" TO CustKey
18+
19+
DataSet1.AddItem USING *Text=JsonText, *Key=CustKey
20+
21+
*--------------------------------------------------------------*
22+
* Add second JSON object *
23+
*--------------------------------------------------------------*
24+
MOVE "{""Name"":""Mary Smith"",""Age"":25,""Status"":""Active""}" TO JsonText
25+
MOVE "CUST002" TO CustKey
26+
27+
DataSet1.AddItem USING *Text=JsonText, *Key=CustKey
28+
29+
*--------------------------------------------------------------*
30+
* Retrieve JSON for CUST001 *
31+
*--------------------------------------------------------------*
32+
MOVE "CUST001" TO CustKey
33+
34+
DataSet1.GetItem GIVING JsonOut USING *KEY=CustKey
35+
DISPLAY *N, "JSON Retrieved: ", JsonOut
36+
37+
*--------------------------------------------------------------*
38+
* Update JSON for CUST001 *
39+
*--------------------------------------------------------------*
40+
MOVE "{""Name"":""John Doe"",""Age"":31,""Status"":""Active""}" TO JsonText
41+
42+
DataSet1.UpdateItem USING *Text=JsonText, *Key=CustKey ; Replaces existing
43+
44+
DataSet1.GetItem GIVING JsonOut USING *KEY=CustKey
45+
DISPLAY *N, "JSON Updated: ", JsonOut
46+
47+
*--------------------------------------------------------------*
48+
* Delete CUST002 *
49+
*--------------------------------------------------------------*
50+
MOVE "CUST002" TO CustKey
51+
DataSet1.DeleteItem USING *KEY=CustKey
52+
53+
DISPLAY *N, "Deleted CUST002",*W5
54+
55+
STOP

‎basicsamples/dataset3.pls‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
INCLUDE PLBEQU.INC
3+
4+
DataSet1 DATASET
5+
JsonText DIM 200
6+
FilterExpr DIM 100
7+
Result DIM 200
8+
Prefix7 DIM 7
9+
Count FORM 5
10+
Index FORM 5
11+
12+
CREATE DataSet1
13+
SETPROP DataSet1, DATATYPE=$DST_JSON
14+
15+
*--------------------------------------------------------------*
16+
* Load some JSON orders into the DATASET *
17+
*--------------------------------------------------------------*
18+
MOVE "{""Orderid"":49,""Prodid"":44,""City"":""Houston"",""Quantity"":40}" TO JsonText
19+
DataSet1.AddItem USING *Text=JsonText
20+
21+
MOVE "{""Orderid"":111,""Prodid"":50,""City"":""Denver"",""Quantity"":10}" TO JsonText
22+
DataSet1.AddItem USING *Text=JsonText
23+
24+
MOVE "{""Orderid"":200,""Prodid"":42,""City"":""Houston"",""Quantity"":5}" TO JsonText
25+
DataSet1.AddItem USING *Text=JsonText
26+
27+
*--------------------------------------------------------------*
28+
* Set DATAFILTER: only Houston orders *
29+
*--------------------------------------------------------------*
30+
MOVE "City='Houston'" TO FilterExpr
31+
SETPROP DataSet1, DATAFILTER=FilterExpr
32+
33+
* Get the number of active items in the DATASET (COUNT prop) *
34+
GETPROP DataSet1, COUNT=Count
35+
36+
*--------------------------------------------------------------*
37+
* Loop through all items and show only those matching filter *
38+
*--------------------------------------------------------------*
39+
FOR Index FROM "1" TO Count
40+
DataSet1.GetItem GIVING Result USING *INDEX=Index
41+
42+
* Check if GetItem returned an error ($ERROR$=nnn) *
43+
MOVE Result TO Prefix7
44+
IF (Prefix7 = "$ERROR$")
45+
CONTINUE
46+
ENDIF
47+
48+
DISPLAY *N, "Match (Houston): ", Result
49+
REPEAT
50+
PAUSE "5"
51+
STOP

‎basicsamples/dataset4.pls‎

Lines changed: 67 additions & 0 deletions

0 commit comments

Comments
 (0)