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

Writing your first procedure

Your first ABL procedure will be very simple to get you started with the language. But before you enter this first procedure, you need to make an adjustment to the code.
There are a fair number of fields in the Customer table, so the resulting formatting of all the fields in a limited display area would be a mess. In fact, one of the fields, the Comments field, is so large that the AVM will balk at displaying it without some guidance from you on how to format and position it.
So it's better to select just a few of the fields from the table to display to make it more manageable. Select the CustNum field, which is the unique customer number, the Name field, which is the customer name, and the City field, which is part of the customer's address.
In ABL, a list of fields is separated by spaces, so the new procedure becomes:
FOR EACH Customer:
  DISPLAY CustNum Name City.
END.
To enter this procedure in the Procedure Editor in the Procedure Editor window, type your block of code:
See Starting your OpenEdge session for how to start the Procedure Editor.
You might notice the following about this code:
*You can type the table name Customer with an uppercase C, or type it in lower-case, or all in uppercase, or however you wish. ABL is entirely case-insensitive when it comes to both language keywords and database table and field names. Uppercasing the keywords is just a convention to aid in code readability, but you could type for each or For Each as well and it would work just the same.
*Typing CustNum in mixed case is just a convention to aid readability.
*The Customer field Name is the same name as the ABL keyword, NAME. ABL is relatively forgiving in this way: if the ABL compiler, which processes the code you type in, can distinguish between a word that is a field name or table name and one that must be a keyword, it will let you use it that way. It's a good idea to avoid using keywords as table or field names in your database definition, though. For a list of all ABL keywords, see OpenEdge Development: ABL Reference.
To execute your procedure, press the F2 key on your keyboard (the keyboard shortcut for the RUN command). Alternatively, you can select Compile > Run from the Procedure Editor menu.
The Procedure Editor shows the first set of customer numbers, names, and cities:
To see the next pages of Customer numbers, names and cities, press the SPACE BAR a few times. Press ESCAPE to terminate the display. Otherwise, the display terminates after the last page of Customers has been displayed.
This little three-line procedure certainly does a lot for you, but it doesn't produce an output display that you would put directly into an application. There are many qualifiers to the DISPLAY keyword in the statement that you can use to adjust its behavior and appearance, some of which you'll see later on in this chapter. Fundamentally, the DISPLAY statement is not intended to produce polished output by itself for a graphical application. There are other statements in the language you can use to define the windows, browses, toolbar buttons, and other features of a complete user interface. You'll get to know those statements in later chapters.
For the purposes of your introduction to the language, leave the display format as it is, so that you can see how the structure of the language itself is put together. You will complete a little test procedure here that shows you a lot about ABL. After only a few chapters, you'll be building complete application windows and all the logic that goes on behind them.