Progress
Programming
Handbook


Examples

The following external procedure defines and calls three internal procedures. The external procedure p-intprc.p runs the internal procedure getcust for each customer number you enter. The internal procedure getcust runs getord and getord runs getitem. The result is that you see the orderline and item information if the customer exists and has orders:

p-intprc.p
DEFINE BUFFER cust_buf FOR customer. 
DEFINE BUFFER ord_buf FOR order. 
DEFINE VARIABLE t-i-cust-num LIKE customer.cust-num. 
DEFINE VARIABLE t-i-item-num LIKE item.item-num. 
REPEAT: 
    UPDATE t-i-cust-num. 
    RUN getcust. 
END. 
PROCEDURE getcust: 
   FIND FIRST cust_buf WHERE cust_buf.cust-num = t-i-cust-num NO-ERROR. 
   IF NOT AVAILABLE cust_buf 
   THEN DO: 
      MESSAGE "Customer not found.". 
      RETURN ERROR. 
   END. 
   ELSE DO: 
      FIND FIRST ord_buf OF cust_buf NO-ERROR. 
      IF AVAILABLE ord_buf 
      THEN RUN getord. 
      ELSE MESSAGE "No orders for customer.". 
   END. 
END PROCEDURE. /* getcust */ 
PROCEDURE getord: 
   FOR EACH order-line OF ord_buf: 
      DISPLAY order-line WITH FRAME foo. 
      t-i-item-num = order-line.item-num. 
      RUN getitem. 
   END. 
END PROCEDURE. /* getord */ 
PROCEDURE getitem: 
   FIND FIRST item WHERE item.item-num = t-i-item-num. 
   DISPLAY cust_buf.cust-num cust_buf.name item.item-num item.item-name 
      WITH FRAME foo1. 
END PROCEDURE. /* getitem */ 

The next two procedures duplicate the functionality of p-intprc.p by separating the internal procedures and the update loop into separate external procedures. The procedure defining the internal procedures, p-inprc1.p passes its procedure handle to p-exprc3.p. Thus, p-exprc3.p runs getcust in p-inprc1.p:

p-inprc1.p
DEFINE BUFFER cust_buf FOR customer. 
DEFINE BUFFER ord_buf FOR order. 
DEFINE VARIABLE t-i-item-num LIKE item.item-num. 
RUN p-exprc3.p (INPUT THIS-PROCEDURE). 
PROCEDURE getcust: 
   DEFINE INPUT PARAMETER t-i-cust-num LIKE customer.cust-num. 
   FIND FIRST cust_buf WHERE cust_buf.cust-num = t-i-cust-num NO-ERROR. 
   IF NOT AVAILABLE cust_buf 
   THEN DO: 
      MESSAGE "Customer not found.". 
      RETURN ERROR. 
   END. 
   ELSE DO: 
      FIND FIRST ord_buf OF cust_buf NO-ERROR. 
      IF AVAILABLE ord_buf 
      THEN RUN getord. 
      ELSE MESSAGE "No orders for customer.". 
   END. 
END PROCEDURE. /* getcust */ 
PROCEDURE getord: 
   FOR EACH order-line OF ord_buf: 
      DISPLAY order-line WITH FRAME foo. 
      t-i-item-num = order-line.item-num. 
      RUN getitem. 
   END. 
END PROCEDURE. /* getord */ 
PROCEDURE getitem: 
   FIND FIRST item WHERE item.item-num = t-i-item-num. 
   DISPLAY cust_buf.cust-num cust_buf.name item.item-num item.item-name 
      WITH FRAME foo1. 
END PROCEDURE. /* getitem */ 

p-exprc3.p
DEFINE INPUT PARAMETER db-procs AS HANDLE. 
DEFINE VARIABLE t-i-cust-num LIKE customer.cust-num. 
REPEAT: 
   UPDATE t-i-cust-num. 
   RUN getcust IN db-procs (INPUT t-i-cust-num). 
END. 


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