The Orders Program orders.4gl
Much of the functionality is identical to that in earlier Tutorial examples. The
query/add/delete/update of the orders
table would be the same as the examples in
Chapter 4 and Chapter 6. Only append and query are included in this program, for simplicity. The
add/delete/update of the items
table is similar to that in Chapter 8. The
complete orders
program is outlined, with examples of any new
functionality.
The MAIN program block The MAIN
program block contains the menu for the orders
program.Function setup_actions This function is used by the main menu to enable or disable actions based on the context.Function order_new This function handles the input of an order
record.Function order_insert This function inserts a new record in the orders
database table.Function order_query This function allows the user to enter query criteria for the orders
table. It calls the function order_select
to retrieve the rows from the database table.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_select This function creates the SQL statement for the query and the corresponding cursor to retrieve the rows from the orders
table. It calls the function fetch_order
.Function order_fetch_rel This function calls the function order_fetch
to retrieve the rows in the database; the parameter p_fetch_flag
indicates the direction for the cursor movement. If there are no more records to be retrieved, a message is displayed to the user.Function order_total This function calculates the total price for all of the items contained on a single order.Function order_close This function closes the cursor used to select orders from the database.Function items_fetch 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.Function items_show This function displays the line items for the order in the screen array and returns immediately.Function items_inpupd This function contains the program logic to allow the user to input a new row in the arr_items
array, or to change or delete an existing row.Function items_line_total This function calculates the value of line_total
for any new rows that are inserted into the arr_items
array.Function item_insert This function inserts a new row into the items
database table using the values input in the current array record on the form.Function item_update This function updates a row in the items
database table using the changes made to the current array record in the form.Function item_delete This function deletes a row from the items
database table, based on the values in the current record of the items array.Function get_stock_info This function verifies that the stock number entered for a new row in the arr_items
array exists in the stock
table. It retrieves the description, unit of measure, and the correct price based on whether promotional pricing is in effect for the order.