Selection fields in an enquiry targeting a Nofile
If you need to give users the ability to filter the enquiry results, you must declare selection fields in the SS and take them in consideration in the subroutine.
Inside the routine, by adding the library for enquiries (I_ENQUIRY.COMMON), you will be able to process selection fields with following common variables:
D.FIELDS : contains the selection fields separated by a FM
D.LOGICAL.OPERANDS : contains selection operators using following equivalences:
1 = EQ 2 = RG 3 = LT 4 = GT 5 = NE 6 = LK 7 = UL 8 = LE 9 = GE 10 = NR
D.RANGE.AND.VALUE : contains values of selection input by the user.
Detailed explanations :
1) Declare selection fields in the Standard Selection of the NOFILE.
15. 3 USR.FIELD.NAME. SELECTION.FIELD.1 16. 3 USR.TYPE....... S 18. 3. 1 USR.VAL.PROG IN2D 20. 3 USR.DISPLAY.FMT 12L
Then in the routine called by the NOFILE: 2) Add the library I_ENQUIRY.COMMON
3) Process selection fields specified by end-user
Y.SEL.CRITERIA = '' Y.FIELD = 'SELECTION.FIELD.1' GOSUB BUILD.CRITERIA.CMD Y.FIELD = 'SELECTION.FIELD.2' GOSUB BUILD.CRITERIA.CMD Y.FIELD = 'SELECTION.FIELD.3' GOSUB BUILD.CRITERIA.CMD Y.SORT.CONDITION = 'BY WHATEVER'
4) BUILD.CRITERIA.CMD:
LOCATE Y.FIELD IN D.FIELDS<1> SETTING POS ELSE RETURN Y.OPERAND = D.LOGICAL.OPERANDS<POS> Y.RANGE.AND.VALUE = D.RANGE.AND.VALUE<POS> Y.I = 0 BEGIN CASE CASE Y.OPERAND = 1 ; * EQual to ALL. Y.SEL.CRITERIA := ' AND ':Y.FIELD:' EQ' LOOP Y.I += 1 Y.X = Y.RANGE.AND.VALUE<1,1,Y.I> WHILE Y.X Y.SEL.CRITERIA := ' ':Y.X REPEAT CASE Y.OPERAND = 2 ; * RanGe Y.SEL.CRITERIA := ' AND ':Y.FIELD:' GE ':Y.RANGE.AND.VALUE<1,1,1> Y.SEL.CRITERIA := ' AND ':Y.FIELD:' LE ':Y.RANGE.AND.VALUE<1,1,2> CASE Y.OPERAND = 3 ; * Less Than Y.SEL.CRITERIA := ' AND ':Y.FIELD:' LT ':Y.RANGE.AND.VALUE<1,1> CASE Y.OPERAND = 4 ; * Greater Than Y.SEL.CRITERIA := ' AND ':Y.FIELD:' GT ':Y.RANGE.AND.VALUE<1,1> CASE Y.OPERAND = 5 ; * Not Equal to LOOP Y.I += 1 Y.X = Y.RANGE.AND.VALUE<1,1,Y.I> WHILE Y.X Y.SEL.CRITERIA := ' AND ':Y.FIELD:' NE ':Y.X REPEAT CASE Y.OPERAND = 6 ; * LiKe Y.SEL.CRITERIA := ' AND ':Y.FIELD:' LIKE' LOOP Y.I += 1 Y.X = Y.RANGE.AND.VALUE<1,1,Y.I> WHILE Y.X Y.SEL.CRITERIA := ' ':Y.X REPEAT CASE Y.OPERAND = 7 ; * UnLike LOOP Y.I += 1 Y.X = Y.RANGE.AND.VALUE<1,1,Y.I> WHILE Y.X Y.SEL.CRITERIA := ' AND ':Y.FIELD:' UNLIKE ':Y.X REPEAT CASE Y.OPERAND = 8 ; * Less than or Equal Y.SEL.CRITERIA := ' AND ':Y.FIELD:' LE ':Y.RANGE.AND.VALUE<1,1> CASE Y.OPERAND = 9 ; * Greater than or Equal Y.SEL.CRITERIA := ' AND ':Y.FIELD:' GE ':Y.RANGE.AND.VALUE<1,1> CASE Y.OPERAND = 10 Y.SEL.CRITERIA := ' AND (':Y.FIELD:' LT ':Y.RANGE.AND.VALUE<1,1,1> Y.SEL.CRITERIA := ' OR ':Y.FIELD:' GT ':Y.RANGE.AND.VALUE<1,1,2>:')' * END CASE RETURN
5) Then add the selection fields in the SELECT command
SEL.CMD = 'SELECT ' : FN.TARGET.FIELD.NAME : ' WITH @ID NE "" ' SEL.CMD := ' ':Y.SEL.CRITERIA SEL.CMD := ' ':Y.SORT.CONDITION
That’s all folks.