Try OpenEdge Now
skip to main content
ABL Essentials
Introducing ABL : In the beginning . . . FOR EACH CUSTOMER

In the beginning . . . FOR EACH CUSTOMER

There's a prototypical ABL procedure often used as an example, one that couldn't be simpler, but that shows a lot about the power of the language. It has appeared on coffee mugs and tee shirts for two decades. Here it is:
FOR EACH Customer:
  DISPLAY Customer.
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 Sports2000 sample database that you'll connect to. The FOR EACH statement 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 Customer means 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 EACH statement through the END statement—iterates once for each Customer record (hence the syntax FOR EACH). All the code in between (in this case just a DISPLAY statement) 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.
* Starting your OpenEdge session
* Writing your first procedure