functions v procedures

granth

New Member
Apologies for this in advance, I'm not entirely sure myself what I'm try to ask, but here goes...

After 10 years coding in Progress I now find out that functions can return output parameters - something I never realised! Maybe it's because I've never seen a piece of code that uses functions to output values via parameters.

This blurs the distinction between procs and funcs for me now.

I can think of 2 main reasons to use functions over procedures, namely:

1) you can use functions inline
2) they're supposedly faster than procedure calls when used in iterative loops

When either will a func or proc will do, are there any other factors in choosing one over the other.
 
Basic development here regardless of language issues.
If you require a retun value then use a function otherwise use a procedure.
Whilst in your block and you wish to do something that can / will be repeated, or is dynamic then use a function. Eg VAT - always stays the same so price(1) + price(2) + VAT(function) = TOTAL
 
You should always use Procdures for Database modification as Functions don't handle RETURN ERROR correctly. Meaning you can't undo transactions correctly if you have a Error status in our function. i.e RETURN ERROR in a Sub-Procdure will cause the calling Procedures transaction block's UNDO RETRY or if UNDO LEAVE to run correctly while in the a function it does sweet fa which is a pain! as it means you need to code extra checks if using functions.

So to keep it simple functions should only be used for simple calulation or when don't need transaction scope to work! Peronally I consider this a bug in Progess <9, don't know if its been corrected in 10.
 
Back
Top