Consultor Eletrônico



Kbase P25942: How to deal with RETURN-VALUE?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   25/01/2005
Status: Unverified

GOAL:

How to deal with RETURN-VALUE?

GOAL:

How to use the RETURN-VALUE?

FACT(s) (Environment):

Progress 9.1x
OpenEdge 10.x

FIX:

You often need the caller of a procedure to be able to check some status or return code indicating the procedure's result. Below are three techniques with some pros and cons.

1. Use RETURN "Something" and the RETURN-VALUE function.

Advantages
Doesn't add extraneous parameters to procedure calls.
Works for both internal and external procedures without modification.
Requires no extra variable setup or maintenance.
Can be used in a variety of situations, including packed data values.

Disadvantages
Limited to a single string value.
Is impacted by sequence of call/check statements.

2. Use an OUTPUT PARAMETER.

Advantages
Directly ties the return value to the procedure call.
Can use a variety of different data types.

Disadvantages
Requires a variable to return into.
Adds a parameter to the procedure call.

3. Use an externally defined variable or data structure.

Advantages
Allows for more complex return values.
Makes status information visible to more than one place.

Disadvantages
Requires global or shared data with external procedures.
Is very subject to unwanted tampering, value changing.


Each of these methods has its place but a word of caution for 1 and 3. For number 1 be very careful about checking the return-value immediately, without any chance of another run happening (Beware include based runs...). If you don't then the con of being impacted by sequence will make for very difficult to trace bugs. For number 3 the same side effect problem exists and is best used when a general status is being set, rather than a simple success/failure return flag.

Another location to consider putting status and return information is the PRIVATE-DATA attribute available on widgets, system handles, and persistent procedures. This attribute can be used as a persistent, carry it where you go kind of storage.