Progress
Programming
Handbook


Application Messages

Within an application you might want to pass a message from one procedure back to the procedure that called it. For example, if a subprocedure encounters an error, you might want to pass a message about the error back to the caller. You can pass such as message on the RETURN statement. For example, p-retstr.p tries to find a customer record in the database and returns either the customer name or a message indicating why the record is not available:

p–retstr.p
DEFINE PARAMETER BUFFER cust-buf FOR customer. 
DEFINE INPUT PARAMETER  cnum     AS INTEGER. 
FIND cust-buf WHERE cust-num = cnum NO-ERROR. 
IF NOT AVAILABLE cust-buf 
THEN DO: 
    IF LOCKED cust-buf 
    THEN RETURN "Record is locked.". 
    ELSE RETURN "Record not found.". 
END. 
RETURN cust-buf.name. 

The calling procedure can read a returned message by using the RETURN–VALUE function. For example, p-retval.p runs p-retstr.p and displays the returned value in a frame:

p–retval.p
DEFINE VARIABLE i AS INTEGER. 
FORM 
  customer.cust-num customer.name 
  WITH FRAME name-frame DOWN. 
FIND FIRST customer. 
DISPLAY cust-num name WITH FRAME name-frame. 
DO i = cust-num + 1 TO CURRENT-VALUE(next-cust-num): 
   DOWN WITH FRAME name-frame. 
   RUN p-retstr.p (BUFFER customer, i). 
   DISPLAY i @ customer.cust-num 
           RETURN-VALUE @ customer.name WITH FRAME name-frame. 
END. 

This procedure displays all customer numbers from the first to the current value of the next–cust–num sequence. For each number it displays either the customer name or a message indicating the status of that record.

NOTE: If you have a procedure which does not end with the RETURN statement, the value in RETURN–VALUE will be the value of the last executed RETURN statement. RETURN–VALUE is not cleared if there is no RETURN statement. If no value was reurned by the most recently executed RETURN statement, RETURN–VALUE returns an empty string (“”).

For more information on the RETURN statement and the RETURN–VALUE function, see the Progress Language Reference .


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095