Use INDEX-INFORMATION and a MESSAGE with a yes/no answer
- Last Updated: May 6, 2024
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
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:
- Use the
INDEX-INFORMATIONattribute of the query and aMESSAGEstatement 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-INFORMATIONreturns"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
MESSAGEstatement that you have not seen before. If you define aMESSAGEasVIEW-AS ALERT-BOX, you can define the choice buttons that appear in the alert box. As you have seen,OKis the default. Other choices areYES-NO,YES-NO-CANCEL,OK-CANCEL, andRETRY-CANCEL. You can thenSETa 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 theMESSAGEstatement using theAS LOGICALphrase. You can then check the value of the variable to see which choice the user picked. The first choice within any set of buttons returnsyes, the secondno, and if there is a third choice (as inYES-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
MESSAGEstatement 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-STRINGyou saved off earlier. - Reopen the query and
APPLY CHOOSEto 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 “” */ - Save h-CustOrderWin8.w.
- Run the window. The Customer fields initially
come up disabled:
- Click the Filter button. The fields are enabled and blanked
out, and you can enter a value into any one of them:
- Enter a value into a nonindexed field, such as the City. You
get a warning message:
- 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.