In the beginning . . . FOR EACH CUSTOMER
- Last Updated: December 14, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
In the beginning . . . FOR EACH CUSTOMER
There's a prototypical ABL procedure often used as an example, one that could not be simpler, but that shows a lot about the power of the language. It has appeared on coffee mugs and tee shirts for decades. Here it is:
|
You can't get much simpler than that, but it would take hours to explain in detail everything that this little procedure does for you. To summarize:
-
Customer is the name of a table in the Sports2020 sample database
that you will connect to. The
FOR EACHstatement starts a block of code that opens a query on that database table and returns each record in the table, one at a time, in each iteration of the block. - Each Customer record is displayed on the screen in turn. The
code takes formatting and label information from the database schema
definition and uses it to create a default display format for all
the fields in the table.
DISPLAY Customermeans display all the fields in the table. - As each record is displayed, the display moves down a row to display the next Customer. The effect is more like what you would see in a report rather than a browse or other grid control.
- The block of code—everything from the
FOR EACHstatement through theENDstatement—iterates once for each Customer record (hence the syntaxFOR EACH). All the code in between (in this case just aDISPLAYstatement) is executed for each customer retrieved. - When the display gets to the bottom of the available display area, it automatically pauses, with a message prompting you to press the space bar to see the next set of rows.
- When you press the space bar, the display clears and a new set of rows appears.
- When the ABL Virtual Machine (AVM) detects the end of the record set (all the Customer records in this case), it terminates the procedure with the message "Procedure complete. Press space bar to continue."
- If you get tired of looking at customers (there are several hundred in the table), you can press the ESCAPE key to terminate the procedure.