Tutorial Chapter 11: Master/Detail / The Orders Program orders.4gl |
This function retrieves the rows from the items table that match the value of order_num in the order currently displayed on the form. The description and unit values are retrieved from the stock table, using the column stock_num. The value for line_total is calculated and retrieved. After displaying the items on the form, the function order_total is called to calculate the total price of all the items for the current order.
01 FUNCTION items_fetch() 02 DEFINE item_cnt INTEGER, 03 item_rec RECORD 04 stock_num LIKE items.stock_num, 05 description LIKE stock.description, 06 quantity LIKE items.quantity, 07 unit LIKE stock.unit, 08 price LIKE items.price, 09 line_total DECIMAL(9,2) 10 END RECORD 11 12 IF order_rec.order_num IS NULL THEN 13 RETURN 14 END IF 15 16 DECLARE items_curs CURSOR FOR 17 SELECT items.stock_num, 18 stock.description, 19 items.quantity, 20 stock.unit, 21 items.price, 22 items.price * items.quantity line_total 23 FROM items, stock 24 WHERE items.order_num = order_rec.order_num 25 AND items.stock_num = stock.stock_num 26 27 LET item_cnt = 0 28 CALL arr_items.clear() 29 FOREACH items_curs INTO item_rec.* 30 LET item_cnt = item_cnt + 1 31 LET arr_items[item_cnt].* = item_rec.* 32 END FOREACH 33 FREE items_curs 34 35 CALL items_show() 36 CALL order_total(item_cnt) 37 38 END FUNCTION