Release 10.1A: OpenEdge Development:
Progress 4GL Handbook

> ## Writing your first procedure

> Your first Progress procedure will be a real snowplow exercise, something very simple just to get you started with the language. But before you enter this first procedure, you need to make an adjustment to the code—your first change!

> 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 Progress run-time engine (also known as the interpreter) 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 the Progress 4GL, 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:

> 1. Return to the OpenEdge Desktop and click the icon with the pen and inkwell .

> 2. In the Procedure Editor window that comes up, type your block of code:

> You might notice the following about this code:

> - The words `FOR` and `EACH` are automatically uppercased as you type them, and colored blue as well. This is because the Procedure Editor uses an intelligent edit control that recognizes Progress 4GL syntax. It not only does color-coding, but can also do autocompletion of common syntax, and can accept abbreviations of common language statements, to help speed up your programming. The editor also recognizes the `FOR EACH` statement as being the beginning of a block of code and automatically indents the `DISPLAY` statement, and then unindents the `END` statement to match the beginning of the block.

> - You can type the table name Customer with a capital C, or type it in lower-case, or all in capitals, or however you wish. Progress 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.

> - When you type the field name Name, it is uppercased and colored blue. This is because `NAME` is also a keyword in the 4GL. Progress is relatively forgiving in this way: if the Progress 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 the Progress 4GL keywords, see OpenEdge Development: Progress 4GL Reference .

> | To execute your procedure, press the F2 key on your keyboard. This is the keyboard shortcut for the `RUN` command. Alternatively, you can select Compile Run from the 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. That’s the snowplow part of this exercise. You’ll complete a little test procedure here that shows you a lot about the Progress 4GL, but which doesn’t represent the way you will write really finished applications (just as snowplowing shows you a lot about skiing but doesn’t represent how you will actually ski when you’re an expert). To do that, you work together with the development tools to let the tools do a lot of the work of putting together the user interface for you. After only a few chapters, you’ll be building complete application windows and all the logic that goes on behind them.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095