Function order_fetch

This function retrieves the row from the orders table, and is designed to be reused each time a row is needed. If the retrieval of the row from the orders table is successful, the function items_fetch is called to retrieve the corresponding rows from the items table.

Function order_fetch (orders.4gl):
01 FUNCTION order_fetch(p_fetch_flag)
02   DEFINE p_fetch_flag SMALLINT
03  
04   IF p_fetch_flag = 1 THEN
05      FETCH NEXT order_curs INTO order_rec.*
06   ELSE
07      FETCH PREVIOUS order_curs INTO order_rec.*
08   END IF
09  
10   IF (SQLCA.SQLCODE == NOTFOUND) THEN
11      RETURN FALSE
12   END IF
13  
14   DISPLAY BY NAME order_rec.*
15   CALL items_fetch()
16   RETURN TRUE     
17  
18 END FUNCTION
Note:
  • Line 05 When the parameter passed to this function and stored in the variable p_fetch_flag is 1, the FETCH statement retrieves the next row from the orders table.
  • Line 07 When the parameter passed to this function and stored in p_fetch_flag is not 1, the FETCH statement retrieves the previous row from the orders table.
  • Lines 10 thru 12 return FALSE if no row was found.
  • Line 14 uses DISPLAY BY NAME to display the record order_rec.
  • Line 15 calls the function items_fetch, to fetch all order lines.
  • Line 16 returns TRUE indicating the fetch of the order was successful.