Queries are often initiated programmatically. For example, to create a menu item or button that operators can press to execute a query, write the appropriate menu item command or When-Button-Pressed trigger.
To place a form in Enter Query mode programmatically, call the ENTER_QUERY Built-in procedure. Operators can then specify query conditions before executing the query with a menu or button command. To execute a query immediately, call the Built-in procedure EXECUTE_QUERY.
In some situations, it may be best to write a trigger that executes either the ENTER_QUERY or EXECUTE_QUERY procedure, depending on whether or not the form is already in Enter Query mode. To make this work, read the value of the SYSTEM.MODE system variable to determine if the form is in Normal mode or Enter Query mode:
IF System.Mode = 'NORMAL' THEN Enter_Query;ELSE Execute_Query;
To execute a query programmatically, the block to be queried must be the current block. When necessary, navigate to the desired block before executing the query:
IF System.Cursor_Block != 'ORD_BLK' THEN Go_Block('ord_blk'); Execute_Query;END IF;