|
| 1 | + |
| 2 | + INCLUDE PLBEQU.INC |
| 3 | + |
| 4 | +DataSet1 DATASET |
| 5 | +JsonText DIM 200 |
| 6 | +FilterExpr DIM 100 |
| 7 | +FindRet DIM 200 |
| 8 | +Prefix7 DIM 7 |
| 9 | +Idx FORM 5 |
| 10 | +Key DIM 40 |
| 11 | +Flags FORM 10 |
| 12 | + |
| 13 | +* Equates (normally from PLBEQU.INC) shown here for clarity only |
| 14 | +DSF_ITEM_GET_ITEM_INFO EQU 4 ;0x00000004 |
| 15 | +DSF_ITEM_GET_NEXT_ITEM EQU 8 ;0x00000008 |
| 16 | +DSF_ITEM_GET_FILTER_SEARCH EQU 32 ;0x00000020 |
| 17 | + |
| 18 | + CREATE DataSet1 |
| 19 | + SETPROP DataSet1, DATATYPE=$DST_JSON |
| 20 | + |
| 21 | +*--------------------------------------------------------------* |
| 22 | +* Load some JSON orders * |
| 23 | +*--------------------------------------------------------------* |
| 24 | + MOVE "{""Orderid"":49,""Prodid"":44,""City"":""Houston"",""Quantity"":40}" TO JsonText |
| 25 | + DataSet1.AddItem USING *Text=JsonText |
| 26 | + |
| 27 | + MOVE "{""Orderid"":111,""Prodid"":50,""City"":""Denver"",""Quantity"":10}" TO JsonText |
| 28 | + DataSet1.AddItem USING *Text=JsonText |
| 29 | + |
| 30 | + MOVE "{""Orderid"":200,""Prodid"":42,""City"":""Houston"",""Quantity"":5}" TO JsonText |
| 31 | + DataSet1.AddItem USING *Text=JsonText |
| 32 | + |
| 33 | +*--------------------------------------------------------------* |
| 34 | +* DATAFILTER: orders with Quantity < 15 * |
| 35 | +*--------------------------------------------------------------* |
| 36 | + MOVE "Quantity < 15" TO FilterExpr |
| 37 | + SETPROP DataSet1, DATAFILTER=FilterExpr |
| 38 | + |
| 39 | +*--------------------------------------------------------------* |
| 40 | +* Find first item matching the DATAFILTER * |
| 41 | +*--------------------------------------------------------------* |
| 42 | + MOVE "1" TO Idx |
| 43 | + MOVE (DSF_ITEM_GET_ITEM_INFO+DSF_ITEM_GET_FILTER_SEARCH + DSF_ITEM_GET_NEXT_ITEM) TO Flags |
| 44 | + |
| 45 | + DataSet1.FindItem GIVING FindRet USING *INDEX=Idx, *FLAGS=Flags |
| 46 | + |
| 47 | +FindLoop |
| 48 | +* If error, FindRet starts with "$ERROR$=nnn" (e.g., 4 or 5) * |
| 49 | + MOVE FindRet TO Prefix7 |
| 50 | + IF (Prefix7 = "$ERROR$") |
| 51 | + GOTO Done |
| 52 | + ENDIF |
| 53 | + |
| 54 | + DISPLAY *N, "Filter match info: ", FindRet |
| 55 | + |
| 56 | +*--------------------------------------------------------------* |
| 57 | +* Find next item matching the DATAFILTER * |
| 58 | +*--------------------------------------------------------------* |
| 59 | + EXPLODE FindRet, "," Into Key,Idx |
| 60 | + |
| 61 | + DataSet1.FindItem GIVING FindRet USING *INDEX=Idx, *FLAGS=Flags |
| 62 | + |
| 63 | + GOTO FindLoop |
| 64 | + |
| 65 | +Done |
| 66 | + PAUSE "5" |
| 67 | + STOP |
0 commit comments