how to run a function in a persistent procedure

jmac13

Member
Hi all,

I'm using open edge 10.2b and im trying to run a function from a persistent procedure but cant work out how. Prob just being a bit dense:

Code:
if not valid-handle(hanGradeUtils) then                    
    run gui_utils\grdUtils.p persistent set hanGradeUtils.   
 
intGrade =  run GetNextGradeCode() in hanGradeUtils.
/*The Above errors not sure how the run it? just want the return value to go into intgrade*/


Any help would be great cheers
 
Is it a function or an internal procedure? If a function, then you don't run it, but you do have to forward reference it. If an IP, those don't return values except through output parameters.

Of course, you could make the PP a class and have a method which returned a value.
 
We always have the function forward declarations in an include. If something is passed to the include, it is defined in that thing otherwise it is simply the forward declaration for the function library. The nice thing about this is that your function prototypes are checked when compiling.

Code:
FUNCTION GetNextGradeCode RETURNS INTEGER &IF '{1}' = '' &THEN FORWARD. &ELSE IN {1}. &ENDIF

This can then be included by grdUtils.p

Code:
{ gui_utils/forward/grdutils.i }

FUNCTION GetNextGradeCode RETURNS INTEGER (
):
   RETURN 100.
END FUNCTION.

The user of the function then looks like:

Code:
DEFINE VARIABLE hanGradeUtils AS HANDLE NO-UNDO.

{ gui_utils/forward/grdutils.i hanGradeUtils }

IF NOT VALID-HANDLE( hanGradeUtils ) THEN
   RUN gui_utils/grdutils.p PERSISTENT SET hanGradeUtils.

intGrade = GetNextGradeCode().

Several other observations:

  1. prefix function names with the library name (in this case it would be grdutilsGetNextGradeCode)
  2. never use back slashes in file names - forward slashes work just fine and will also work on *nix
  3. always lower case all file names - also for *nix
If you are never planning on doing anything with Unix / Linux you can of course forget #2 and #3.
 
cheers for all ur help I used Cringers way in the end.. I have a real hate of include files

Interesting, I have a real hate of dynamic-function calls and will only use them if there is no other way. Perhaps you prefer end users running into your coding mistakes instead of the compiler?

If you are passing static temp-tables around I suppose you copy / paste the definition into all programs using this too?
 
Well I'd say i wouldnt be able to use the procedure if there was a compile error... and yes include files have their uses its just i dont find them that good they can make whats happening in the code unclear as its off in a .i somewhere and if you change the .i you have to then recompile all the programs with that .i in.

Anyway thanks for you help I'm sure I'll be using a include soon no doubt
 
Yes, you do need to change the code that uses an include that contains relevant changes or it will not compile - this is an advantage.

The code with the dynamic-functions will compile fine if you change the signature of the function - it does not matter if the function does not even exist or has mismatch parameters since no compile time check is done. Instead it will throw run-time errors at your user.

Compile time checks (which is also provided by classes) are good.
 
well yes i agree with what ur saying.. but it also works on the flip side... If wish to change how the function is calculating something then I don’t have to change all the programs. Where I work its very much a manual process to go round all these programs with the .i files in which is a pain in the backside. They both have advantages and disadvantages I’ll never like include files mainly cause appbuilder is rubbish at showing them. Anyway will leave it at that as this isn’t what the thread was about cheers


 
And, of course, if one encapsulates things like temp-table usage in a class, then there is no need for the include file to pass the definition!
 
Back
Top