Function order_total

This function calculates the total price for all of the items contained on a single order.

Function order_total (orders.4gl):
01 FUNCTION order_total(arr_length)
02   DEFINE order_total DECIMAL(9,2),
03          i, arr_length SMALLINT
04 
05   LET order_total = 0  
06   IF arr_length > 0 THEN
07      FOR i = 1 TO arr_length 
08         IF arr_items[i].line_total IS NOT NULL THEN    
09           LET order_total = order_total + arr_items[i].line_total 
10         END IF
11      END FOR
12   END IF
13 
14   DISPLAY BY NAME order_total 
15 
16 END FUNCTION
Note:
  • Line 07 thru 11 contain a FOR loop adding the values of line_total from each item in the program array arr_items, to calculate the total price of the order and store it in the variable order_total.
  • Line 14 displays the value of order_total on the form.