Progress Programming Tips

By Rod Gaither (rdg@worldinfo.com)

PPT-33  Using Functions to manage coded message displays

Tip:

Version 8.2 of Progress has added programmer defined functions to the
4GL.  Functions are a welcome addition as they can be used in the
"Right Hand" side of an expression.  In addition to this primary
feature a Function also provides for some predefined indirection when
using a FORWARD declaration.

For an example here are some code fragments that show how to create
and use a function to display messages similar to Progress errors with
a single call.

---- Code insert begins ----

/** mytest.p **/
/** shows using the function call **/

&GLOBAL-DEFINE  RECORD-NOT-AVAILABLE   1

{myfunc.i}  /** The forward declarations and a support function **/

FIND Customer WHERE Cust-Num = 3200 NO-LOCK NO-ERROR.
IF AVAILABLE(Customer)
THEN DO:
  /** Do something with the record **/
END.
ELSE ErrorMsg({&RECORD-NOT-AVAILABLE}).  /** Call message Function **/


/** myfunc.i **/
/** Setup and defines of functions **/

/** Forward and IN Function references **/
FUNCTION GetPPHandle
  RETURNS HANDLE  (INPUT p-name AS CHAR) FORWARD.

FUNCTION ErrorMsg
  RETURNS LOGICAL (INPUT p-num AS INT) IN GetPPHandle("ErrorLib").


/** Real function definition **/
FUNCTION GetPPHandle RETURNS HANDLE (INPUT p-name AS CHAR) :
  /** Fill with whatever technique you want to  **/
  /** locate a specific persistent procedure    **/
  /** Ex - by FILE-NAME or PRIVATE-DATA widget walk etc **/
END FUNCTION.


/** ErrorLib.p **/
/** Procedures and Functions related to error processing **/

/** Define GetErrorText function here **/

FUNCTION ErrorMsg RETURNS LOGICAL (INPUT p-num AS INT) :

  /** Include code to translate number to appropriate message **/ /**
  Perhaps by a call to the GetErrorText function ??  :-)  **/

  MESSAGE GetErrorText(p-num)
    VIEW-AS ALERT-BOX ERROR BUTTONS OK.

END FUNCTION.


---- Code insert ends ----

This example shows a couple of features of using functions.  By
using a helper function to resolve the handle of the ErrorLib
procedure the forward declaration of where the ErrorMsg function is is
determined at run time.  This could also be accomplished by using a
handle variable for either procedures or functions but it illustrates
using a function's return value where normally a variable would be
required.

Notice I didn't have to specify where the function lives everytime I
use it.  That part is remembered from the forward declaration so I
don't have to constantly reference a location.

This whole example did assume that errorlib.p was already running
persistently.  To help guard against this being a problem it would
probably be good to have some initialization logic call a test
function and if necessary run some setup logic.


Wisdom:

Let the programmers be many and the managers few - then all
will be productive.  (The Tao of Programming, Geoffrey James)

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