Define the NewOrder Frame
To start creating the NewOrder frame
1. Choose the operations to define a user-specified frame named neworder. ABF displays the Edit a USER Frame Definition frame.
2. Fill in the fields as you did with Topframe. Take the default values where possible.
3. At this point you can edit the 4GL file for the frame. Choose Edit and enter the source code shown below.
The NewOrder frame places data in two tables, "Orders" and "Marketing." The 4GL code for NewOrder is:
initialize =
declare
cnum = integer;
rcount = smallint;
h_count = smallint;
hret = integer;
begin
end
'Add' =
begin
if custnum = 0 then
callproc beep(); /* Built-in procedure */
message 'You must enter a customer' +
' number before selecting ADD';
sleep 2;
resume;
endif;
insert into orders (product, custname,
custnum, quantity, current_date)
values (:product, :custname, :custnum,
:quantity, 'today');
commit;
insert into marketing (prod, quantity)
values (:product, :quantity);
commit;
/* Check to see if a record exists in */
/* the table Customer having the */
/* customer number in field Custnum */
neworder = select cnum = number
from customer
where number = :custnum;
/* See if a record already exists */
inquire_sql (rcount = rowcount);
if rcount = 0 then
insert into customer (name, number, address)
values (:custname, :custnum,
'Whereabouts unknown');
commit;
endif;
/* Look at each record of the array */
/* cust_array, until an entry is found */
/* for the current customer number */
h_count := 1;
while (h_count <= arr_count) do
if cust_array[h_count].c_number =
:custnum then
endloop;
endif;
h_count := h_count + 1;
endwhile;
/* If no entry is found, add one, */
/* otherwise give a warning message */
if (h_count > arr_count) then
arr_count := arr_count + 1;
cust_array[arr_count].c_name := :custname;
cust_array[arr_count].c_number :=
:custnum;
else
message 'WARNING: You have already' +
' entered an order for ' +
varchar(:custname) +
' during this session'
with style = popup;
endif;
clear field all;
end
'Find' =
begin
if custnum = 0 then
message 'You must enter a customer' +
' number before selecting FIND';
sleep 2;
resume;
endif;
/* Write the customer name that */
/* corresponds to the customer number */
/* in the Custnum field into the */
/* Custname field. */
neworder = select custname = name
from customer
where number = :custnum;
/* See if a row exists for that */
/* customer number */
inquire_sql (rcount = rowcount);
if rcount = 0 then
message 'No such customer number';
sleep 2;
resume;
endif;
clear field product, quantity;
end
'ListChoices' =
begin
/* List choices for field. For the */
/* product field this displays */
/* possible products, taken from the */
/* Validation Check To Perform */
/* attribute for this field. */
hret = callproc help_field();
/* Built-in procedure */
end
'End', key frskey3 =
begin
return;
end
The code declares a menu with four operations: Add, Find, ListChoices, and End. The first two operations contain examples of query statements (insert and select).
ListChoices calls the help_field() built-in procedure. When called for the Product field, this option displays a pop-up list of products from which the user can choose. To specify the product list, use the Validation Check To Perform field in the VIFRED Creating a Form frame while creating the form. See the 4GL part of this guide for more information about built-in procedures.
Arr_count, the global variable you set up while creating Topframe, is used in NewOrder. Arr_count gives the number of rows in the dynamic array cust_array.
NewOrders references the array cust_array, based on the record type cust_record. The customer name and number in the selected row, contained in cust_record, are inserted into cust_array, as element number "arr_count" of the array. You can use an array of this type in many ways in an application. NewOrders uses the array to check for duplicate customer entries and displays a warning message if the user enters a duplicate customer. The next two sections show how to create these two global components.