Was this helpful?
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.
Create a Record Type
In NewOrder, the array cust_array is based on the record type cust_record. Cust_record has as its attributes the simple data types, c_name (char) and c_number (integer).
To create this record type
1. From the Edit a USER Frame Definition frame, select End to exit to the Edit an Application frame.
2. Select the Globals operation to display the Create or Edit Global Components pop-up menu.
3. Highlight RecordTypes and choose Select.
4. You see the Edit Application Record Type Definitions frame. Select Create to display the Create a Record Definition pop‑up.
5. In the Name field, enter cust_record.
6. In the Short Remark field, optionally enter a brief description, such as Record structure for customer name and number. This stage is shown in the preceding figure.
7. Select OK to create the record type.
8. The Edit a Record Type Definition frame appears. In its fields are the values you entered in the Create a Record Definition pop-up. Cust_record has two attributes, c_name and c_number. To create the attributes of the record, select Create to display the Create a Record Attribute Frame.
a. To create c_name, complete this frame. Enter the data type char(20) and the optional Short Remark, Customer Name.
b. Select OK. You return to the Edit a Record Type Definition frame, where the attribute is displayed in the table field.
c. Repeat the procedure for the attribute c_number, which has a data type smallint and the optional Short Remark Customer number.
9. After creating the attributes, select End to return to the Edit Application Record Type Definitions frame, where the record type you created appears in the table field. Select End.
Create a Global Array
NewOrder uses an array that you create as a global variable through the Globals menu. An array is a collection of records that you can treat as a single unit. In 4GL, arrays must be made up of records, not of simple data types. The array in NewOrders is based on the record type cust_record, created in Create a Record Type.
Cust_array is a global variable. However, you can also use 4GL code to declare an array locally. For information on declaring an array locally, see the 4GL part of this guide.
To create cust_array
1. From the Edit an Application frame, select the Globals operation to display the Create or Edit Global Components pop-up menu.
2. Highlight Variables and choose Select.
3. When the Edit Global Variables frame appears, select Create to display the Create a Global Variable pop-up.
4. In the Name field, enter cust_array.
5. In the Type field, enter cust_record. For an array, you must type this in, as the ListChoices menu of Ingres types does not list user-created record types.
6. When the Nullable field turns into the Array field, enter yes.
7. In the Short Remark field, optionally enter a brief description, such as Array of customer records. Use the LongRemark pop-up to enter a longer comment if you like.
8. When the frame appears as in the following figure, select OK to create the variable.
9. To return to the Edit Global Variables frame, select End.
This frame is where this array is listed in the table field.
Define the NewOrder Form
To build the form for NewOrder, redisplay the Edit a USER Frame Definition frame. The NewOrder form is shown in the following figure.
To define the form
1. Enter the form name orders and select FormEdit. At the VIFRED Creating a Form menu, select Table.
2. At the Creating a Form Based on a Table pop-up, specify the Orders table and the field type simplefields. Select OK.
3. The default form includes the fields Custnum, Custname, Product and Quantity.
Use VIFRED operations to give the fields different titles and reposition them, as shown in the preceding figure. Remove the current_date field, or give it the Invisible attribute. Notice that the Internal Name of each field is the same as the corresponding Customer table column.
4. To add a list of products to be displayed when the user selects ListChoices for the Product field, enter the product list in the Validation Check to Perform field in VIFRED. Use this format:
product in ["bookcase", "chair", "lamp", "sofa",
"stool", "table", "lawn mower"]
5. Save and exit. You return to the Define a USER Definition frame.
6. Choose End to compile the NewOrder frame and return to the Edit an Application frame. The Error Listing frame appears if the source code file contains errors.
After the form is built, you can test the frame.
Last modified date: 04/03/2024