Progress
Language Tutorial
for Character
Summary
This chapter discussed those features of the Progress 4GL that allow you to control the flow of execution within your application. Here’s a summary of what you’ve learned.
Procedures and Include Files
In the Progress programming model the main procedure can access modules stored in separate subprocedures. A subprocedure can be either an internal or external procedure:
- The main procedure accesses an internal procedure with the RUN statement.
- An external procedure is a procedure file that another procedure calls.
- An internal procedure is a procedure file that is stored with the main procedure in one procedure file.
- A user-defined function is like an internal procedure that has some additional capabilities. It can return a value and the function can be called from within a Progress expression. You use the FUNCTION statement to create a user-defined function.
- An include file is a text file that contains Progress source code. When you reference include files in your procedures, Progress replaces the reference with the contents of the include file at compile time.
Sharing Information between Procedures
There are three basic strategies for passing data between procedures:
- Using shared variables — Shared variables are specially defined variables that more than one procedure can use.
- Using parameters — Parameters are variables in a called procedure or function whose responsibility is to accept an input value from the calling procedure, output a value to the calling procedure, or both. Parameters allow you to pass values to accomplish a run-time task for a procedure or a function.
- Using arguments to pass literals — Literals are programming symbols, such as table names, field names, or variable names. You can replace the literals with argument references in your procedure to make your code more generic. Arguments let you pass literals that allows code to compile.
Blocks
Blocks are structures that let you group segments of code. Typically a block consists of a block header statement, Progress 4GL statements, and an END statement. Progress blocks include:
- Procedure blocks — Encompass the entire procedure file (a .p file), but only those statements that don’t belong to another block actually belong to the procedure block.
- Internal procedure blocks — Begin with the PROCEDURE header statement and are accessed with the RUN statement.
- Trigger blocks — Allow the user to control an application by directing processing with events.
- Control blocks — Have specific implicit properties that affect: loping, frame allocation, and record reading.
The control blocks include:
- DO — Groups statements together for execution as a single unit. It has no implicit block properties.
- REPEAT — Provides implicit looping and frame allocation. It has no explicit terminating condition, but Progress allows a user to end a REPEAT block with the END-ERROR key, or you can end it programmatically with the LEAVE statement.
- FOR EACH — Provides implicit looping, frame allocation, and record reading. Each iteration of the block reads a new record from a database table.
Conditional Processing Statements
There are two statements that allow you to test conditions and define which code branch to execute under which circumstances:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |