Progress Programming Tips

By Rod Gaither (rdg@worldinfo.com)


PPT-28  Dealing with static language elements

Tip:

One of the most difficult aspects of using the 4GL is dealing with the
portions that require static or compile time binding.  The most
notable of these is database references.

Several techniques are available to help deal with these limitations.

1.  Include files with parameters (Best)
2.  Preprocessor definitions (Ok)
3.  Code generation (Depends)

The first two of these options rely on Progress preprocessing the
parameters or definitions and doing text substitution for you.  This
is a much bigger help than it may seem at first.  The third allows for
both the greatest flexibility and the greatest difficulties.

1.  Include files

Properly defined include files can separate the logic from the static
db references in an elegant, reusable package that can even make
reading the main program easier.

Syntax example -

{lib/msg.i &table=Customer &field=Name}

2.  Preprocessor definitions

Defining preprocessor variables has the same substitution advantage
but comes with some pros and cons.  On the pro side defining a
preprocessor variable at the top of a program allows it to be used in
multiple places, versus the single instance usage of passed parameters
for include files.  On the con side it promotes the tendency to
reverse the include file situation and put the customization in many
instances of logic causing code duplication as is found in templates. 
This problem can be avoided or at least minimized but shouldn't be
glossed over.

Moral - Don't replace include file techniques with preprocessors
just because preprocessors are newer.  Pay attention to what you are
going to use the static references for and try and create a combined
approach that gives you the benefits of both techniques without the
disadvantages of templates.

Syntax example -

&GLOBAL-DEFINE  MyTable   Customer
&GLOBAL-DEFINE  MyFields  Name CustNo Account

3.  Code generation

For this example code generation is writing a 4GL program to create
another 4GL program or include file.  This program or a program using
the generated include file can either be compiled on the fly or as
part of the normal application compile.  This technique allows you to
do nearly anything, anything you are willing to write a generation
program for anyway.

Compile on the fly -

The biggest problem with this technique is that it can't replace the
requirement for static binding just dynamically respond to a some user
input or database information to create the proper program to be run.
This has a couple of major problems - performance suffers, and the
type of Progress license becomes an issue - run-time won't compile at
all, Query only programs that don't update the DB, etc.  Still for
certain types of activities this technique has its place.  We used it
effectively in v6 days to dynamically prompt for input with the right
format and data type in a reporting tool. (no longer necessary)

Compile with the application -

These generated programs are more common as they don't have the
deployment problems.  You can generate include files to do buffer to
buffer assignments (soon no longer necessary :-)), special temp-table
definitions from real db definitions etc.

Conclusion -

While a pain sometimes, especially record selection criteria!, you can
work around the limitations of static binding with the preprocessor
tools provided and some creative design.

Wisdom:

Where once you were amazed you may now be unimpressed, this is not the
fault of the object in question but rather a change in your
perspective.


Rod Gaither                  | rdg@worldinfo.com
World Information Systems    | (910) 333-2580  Voice
Greensboro, NC               | (910) 333-2584  Fax