Extend the sample window to use the queries
- Last Updated: July 22, 2025
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
Now you can try out some of the things you learned about queries.
To extend the sample application window to use some query statements:
- In AppBuilder, open h-CustOrderWin1.w.
This gives you the test procedure with Customer fields and the Order browse but without some of the other graphical objects you added later.
- Extend the window somewhat to the right, then drop two buttons onto the window to the right of the Last button.
- Name the first button
PosButtonand give it a label of Save Position. - Name the second button
ReposButtonand give it a label of Restore Position. - Open the Section Editor and select the Definitions section.
- Define a variable to hold a value for the
Customerquery’sCURRENT-RESULT-ROW:/* Local Variable Definitions --- */ DEFINE VARIABLE iQueryRow AS INTEGER NO-UNDO.Remember that the Definitions section is scoped to the entire procedure file, so anything you define here is available to any trigger or internal procedure inside it.
- Go into the Triggers section for the
PosButtonand give it thisCHOOSEtrigger:DO: iQueryRow = CURRENT-RESULT-ROW('CustQuery'). END. - Define this
CHOOSEtrigger for theReposButton:DO: REPOSITION CustQuery TO ROW iQueryRow. APPLY "CHOOSE" TO BtnNext. END.When you click the Save Position button, your code saves off the current row number from the results list. You can then move around in the query. When you press the Restore Position button, the
Customerquery is repositioned to the row you saved, and theOrderquery is opened for thatCustomer.Why did you need the
APPLY "CHOOSE" TO BtnNextstatement? Remember that when you use theREPOSITIONstatement the AVM positions before the record you want, so you need to execute aGET NEXTto make it available. At the same time, in this case, your code needs to reopen the dependentOrderquery for theCustomeras well. All this is done by the trigger code on the Next button. - Run the procedure and test saving off and restoring the current row.
- Add a fill-in field to give you a reason to test reopening the query with a
different
WHEREclause:- Drop a fill-in on the window. Call it cState and give it a label of New State.
- Write this
LEAVEtrigger for the fill-in field in the Section Editor:DO: OPEN QUERY CustQuery FOR EACH Customer WHERE State = cState:SCREEN-VALUE BY Customer.City. APPLY "CHOOSE" TO BtnFirst. END.
Each time you enter a state abbreviation in the field and tab out of it, the trigger fires and the query is reopened with that new state. Remember that it is not necessary to close a query explicitly if you are immediately going to reopen it, so a
CLOSE QUERY CustQuerystatement here is optional. Also remember that unless you specifically assign it using theASSIGNstatement, the value the user types into the fill-in exists only in the frame’s screen buffer, so you can retrieve it using theSCREEN-VALUEattribute of the field.Similarly for the
CHOOSEtrigger that repositions to the previously saved row, you need to applyCHOOSEto the First button trigger to get the first row for the new query and reopen theOrderquery. - Run your procedure. You can enter a state name and tab out of
the New State field and see the
Customersin that state along with theirOrders:
If you enter an invalid state name, the procedure does not give you any feedback to confirm this. In the next section, you make a few more changes to the procedure to check whether there were any results for the state that is entered. This makes use of the
NUM-RESULTSfunction and also introduces you to another new and useful ABL statement.