How Can I Reuse a Filter within a Program?

You can avoid recreating a filter every time you need to use it (for example, if the filter call is inside a loop). That is, you can create the filter before the loop and it remains valid until it is overwritten by a later call to 890-CREATE FILTER.

If the call to 890-CREATE FILTER is outside a loop and is thus not being recreated with each iteration through the loop, there is the limitation that the 890-SET-<Type>-FILTER-VALUE APIs do not allow you to change a value unless you also recreate the filter. To overcome this limitation, use the SETFILTERPARAM function. This function allows you to bind the parameter marker "?" to a working storage location. When you bind the parameter to working storage, the value of the working storage field is re-read every time you call one of the 850-FILTER APIs.

Like the 890-SET-<Type>-FILTER-VALUE APIs, calls to SETFILTERPARAM are matched to parameter markers (?) left to right. So if your FILTER-STRING is:

(GAM-COMPANY = ?) AND (GAM-VAR-LEVELS = ?)

then the first call to SETFILTERPARAM is for the GAM-COMPANY parameter marker and the second call is for the GAM-VAR-LEVELS parameter marker.

One major difference between SETFILTERPARAM and the various 890-SET-<Type>-FILTER-VALUE APIs is that SETFILTERPARAM must be called before 890-CREATE-FILTER . The 890-SET-<Type>-FILTER-VALUE APIs can be called before or after calling 890-CREATE-FILTER .

Another difference is that when you use the SETFILTERPARAM API, the format of the working storage field that you bind to must exactly match the comparison field. That is, if GAM-COMPANY is a PIC 9(4) field, the field that you bind to (GLT-TO-COMPANY in this example) must also be a PIC 9(4) field. The results of binding to a mismatched field are undefined. When you MOVE a value to one of the FILTER-VALUE fields and then call one of the 890-SET-<Type>-FILTER-VALUE APIs, the run-time system will convert the value to the appropriate type.