Next, you need to check whether the field the user selected has an index. If not, you need to warn the user that the retrieval will not be indexed, and you need to provide the option of canceling the query.

To add this check and warning to your LEAVE trigger:

  1. Use the INDEX-INFORMATION attribute of the query and a MESSAGE statement that asks a question:
        IF ENTRY(1, hQuery:INDEX-INFORMATION(1)) = "WHOLE-INDEX" THEN
        DO:
          MESSAGE "This query can't use an index. Continue?"
            VIEW-AS ALERT-BOX BUTTONS YES-NO SET lContinue AS LOGICAL.
          IF NOT lContinue THEN
            hQuery:QUERY-PREPARE(cPrepare).

    If INDEX-INFORMATION returns "WHOLE-INDEX" for the first (and, in this case, the only) table in the query, then you know that there is no index the AVM can use to retrieve the selected records, so it has to search the whole primary index.

    To give the user the option of canceling the query, you can use an option on the MESSAGE statement that you have not seen before. If you define a MESSAGE as VIEW-AS ALERT-BOX, you can define the choice buttons that appear in the alert box. As you have seen, OK is the default. Other choices are YES-NO, YES-NO-CANCEL, OK-CANCEL, and RETRY-CANCEL. You can then SET a variable of LOGICAL data type to record the answer. You can use a variable that you defined earlier or you can define it right in the MESSAGE statement using the AS LOGICAL phrase. You can then check the value of the variable to see which choice the user picked. The first choice within any set of buttons returns yes, the second no, and if there is a third choice (as in YES-NO-CANCEL), clicking that button sets the variable to the Unknown value (?).

    You can set other kinds of variables and fields in messages that are not defined as alert boxes, as well. See the MESSAGE statement entry in the ABL Reference for details.

    In this case, if the user decides not to continue, the query is re-prepared using the PREPARE-STRING you saved off earlier.

  2. Reopen the query and APPLY CHOOSE to the First button to display the first matching record and its Orders:
          hQuery:QUERY-OPEN().
          APPLY "CHOOSE" TO btnFirst.
        END. /* END DO IF SCREEN-VALUE Not “” */ 
  3. Save h-CustOrderWin8.w.
  4. Run the window. The Customer fields initially come up disabled:
  5. Click the Filter button. The fields are enabled and blanked out, and you can enter a value into any one of them:
  6. Enter a value into a nonindexed field, such as the City. You get a warning message:
  7. If you answer Yes, the query is prepared and opened:

    If you answer No, the procedure reverts to the previous query or to the default query if this is the first time the query has been re-prepared.