Contents

This tutorial is aimed at first-time users who want to start producing applications with QA Build. It is organised into a number of easy-to-follow exercises that guide you through the creation of a variety of QA Build programs. As you follow these exercises you will learn the principles of programming with QA Build in a task-oriented manner. No previous experience of using QA Build is assumed, but a basic understanding of DP4 database concepts, such as tables, roles, fields, key fields and indexes is necessary to gain the full benefit of the exercises. If you lack this, you are recommended first to read the Database Design section of the DP4 Developers Manual.

  • Introduction to QA Build

  • The QA Build Development Cycle

  • The SALESORD database

  • The Lessons

  • How to Comment on this Help File


What's New in the QAB Tutorials

This page will tell you about recent changes to this manual. The most recent changes are mentioned first.

New in 4.620

  • 17 Oct 2002What's New Page added


Introduction to QA Build

QA Build is an interactive program builder. It is a fourth-generation programming environment for developing and running application programs interactively. QA Build provides marked productivity gains in comparison with third-generation languages, such as COBOL and C.

By answering a series of questions you tell QA Build the specification of the program you want to produce and QA Build produces it for you. It may be a data entry, enquiry, batch update or some other type of program. Most questions require a simple Yes or No answer; for some you select an option from a menu. Default responses are suggested where appropriate and context-sensitive help is always available.

QA Build programs reside within their DP4 application database. QA Build makes extensive use of the DP4 Data Dictionary and so has access to information about your application database, such as the tables it contains, the fields in each table and the relationships between tables. This ensures that QA Build offers only relevant options throughout a program’s development. When you have written a program, you can modify it or take a copy of it to form the basis of another program.

QA Build’s single environment genuinely meets the differing requirements of the various professionals involved in the application development cycle; it can be used to produce specifications in outline, prototype programs and full run-time systems.


The QA Build Development Cycle

There are three stages to producing a QA Build program:

1. Entering details of the program you want to produce into the Program Editor

2. Compiling your program with the Program Compiler

3. Running your program with the Interpreter

You do all these from the QAB Menu in DP4.

The Program Editor (PROGMAKE)

The Program Editor allows you to create and amend QA Build programs. Running this utility involves entering into a question-and-answer session. Because QA Build has all the resources needed to specify complex programs, there are more questions than a first-time user might expect. However, QA Build always suggests a sensible default answer; you can accept the default with confidence. Moreover, context-sensitive help is available to assist you at every stage. You use its sister screen design utility, the Map Editor, to design the screens (maps) that your program will use. Both these applications use the standard Windows interface.

The Program Compiler (PROGCOMP)

Although you must compile your program before you can run it, QA Build does not generate any code in the traditional sense. The Program Compiler converts your program into a set of instructions that can be interpreted by the Interpreter. It makes a number of checks and, if any errors are detected, it displays a suitable error message.

The Program Interpreter (PROGRUN)

The Interpreter runs your program, notifying you of any run-time errors. Note that QA Build programs can only be run using PROGRUN.


The SALESORD Database

The programs you build in the exercises in this tutorial concern the dealings of a fictitious company, Acme Sales Order Plc, which sells a range of products throughout the United Kingdom. An example database called SALESORD is supplied with QA Build. SALESORD stores information on Acme sales employees, customers, orders and supplier’s materials in nine tables, as follows. You use this to develop and run the programs in the exercises.

EMPLOYEE Stores details of Acme employees who manage customer sales regions and customer accounts, including the
employee’s name, gender, company grade and date of birth. The primary key is a unique number that identifies the employee.

REGION Stores details of the UK regions where customers live, including the name of the region and the company employee managing the region. The primary key is a unique code that identifies each region.

CUSTOMER Stores the customer’s name, address and region code, credit arrangements and balance. The primary key is a unique number that identifies the customer.

ORDER Stores the details of the date and time the order was placed, its value and customer payments made against it, delivery date, customer number and code of the Acme employee responsible for the account. The primary key is a unique number that identifies each order. A customer may have several order header records, each of which may have several order lines giving materials and quantities ordered. An order header record may also have several order payment records.

ORDER_LINE Includes one record for each different material in an order. ORDER_LINE contains the order number, a line number that identifies an order line, the material code and quantity ordered, plus the value of the order line. The order number plus line number form the primary key that identifies each record.

ORDER Includes one record for each payment made against an order. PAYMENT records the order number, a payment number that identifies separate payments, the media code (cheque, direct debit, credit card), the amount paid, the card number and payment date and time.

MATERIAL Stores details of each material including its code, description, unit price, quantity in stock and re-order level and the code of the principal and the alternative supplier of the material. The material code is the primary key to the MATERIAL table.

SUPPLIER Stores the company’s name and address. The primary key is a unique number that identifies the company.


The Lessons

The tutorial is organised into the following lessons. Note that you should work through the lessons in sequence, because later lessons assume familiarity with techniques learned in earlier lessons and some lessons use programs or procedures created in previous lessons. The content of the eight lessons is as follows:

Lesson 1: A Heading Display
You create a simple batch program that displays a screen heading. Unfortunately the heading disappears as soon as it is sent to the screen, because the screen clears when the program ends, but in the next lesson we shall overcome this difficulty. The principal purpose of this lesson is to familiarise you with the QA Build development cycle.

Lesson 2: A Pause Procedure
This time you create a simple interactive procedure which displays a button control with a prompt message: Click on OK or Press Return to continue; this routine provides a pause which waits until the user is ready to continue. This is added to the program from Lesson 1 so that the heading remains on the screen (together with the prompt message) until the user presses a key. This lesson introduces the procedure tree, which is fundamental to QA Build’s operation and the use of controls.

Lesson 3: Creating a Table Update Program
Describes a single-procedure program to update the EMPLOYEE table. Your program allows insertion, deletion and modification of records. You are guided through the specification of this program on a keystroke-by-keystroke basis. It introduces Table and Field processing and validation of entered data.

Lesson 4: A Customer Table Update Program
Shows you how to create an update program for the CUSTOMER table. Because the REGION table is a parent of the CUSTOMER table, it introduces QA Build’s related table processing. In addition, we discuss complex screen layouts together with the routines that arbitrate cursor movement, the auto-incrementing facility and multiple-choice maps.

Lesson 5: Customer Number Enquiry Program
You create an enquiry program for the CUSTOMER table. This program displays the CUSTOMER fields when the correct CUSTOMER_NUMBER has been entered and does not allow update of the database. Copying maps from another program’s mapset and use of local fields are among the features discussed.

Lesson 6: A Customer Name Enquiry Program
Describes a CUSTOMER enquiry program similar to the previous one, but giving access by customer name rather than number. The enquiry uses the Scan if no match search method and INDEX_CUST_NAME, which is the secondary index of the CUSTOMER table.

Lesson 7: A Pop-up Menu Program
Shows you how to create a pop-up menu procedure giving options to run the customer number and customer name enquiries, created in Lessons 6 and 7.

Lesson 8: Creating an Order Entry Program
Describes an order entry program using two interactive procedures. The first of these gets details of the order header and updates the ORDER_HEADER table. This is followed by a procedure which uses the Window access mode to display a list of existing ORDER_LINE records from which one may be selected for update. This program requires you to total the order line value into the order value and perform stock validation and adjustment, as order entry proceeds.

In these lessons you will create a number of new programs in the SALESORD database. We suggest that you name them MYPROG1 to MYPROG7. You will find a set of expert solutions already present, named PROG1 to PROG7. If you have difficulty with any of the exercises, load the corresponding expert solution into the Program Editor and examine how it was done.


Key Press Conventions

The Program Editor and the Map Editor

The Program Editor and the Map Editor follow the conventions for Windows 95 and Windows NT programs.

<Enter> accepts the entry in a field or is equivalent to clicking the OK button in a dialog to accept its contents.

<Esc> quits a dialog without saving any changes and is equivalent to clicking on the Cancel button.

<←>, <→>, <> and <↓> keys move the cursor through the options

The Program Compiler and the Interpreter

The Program Compiler and the Interpreter follow the DP4 conventions:

<Tab> accepts the entries in a screen (as does <Enter> on the last field)

<Esc> returns to the stage you were at previously, without saving any changes

<←>, <→>, <> and <↓> keys move the cursor one field at a time

Selecting from Pop-up lists and menus

<Ctrl><P> or <spacebar> pop up a list of available options. The benefit of doing this is that you get help messages telling you what each option does as you move from one option to another

<Page up> and <Page down> display any further items in the list

<Enter> selects an item in the list

Selecting from menus

<Enter> selects the highlighted menu option

mnemonics select the corresponding menu options

<X> or <Esc> exit from the menu


How to Comment on this Help File

Our aim is to provide you with top quality documentation. In order to do that, we need your help. Feedback from you is the best way we have of measuring the quality of our documentation, so comments, criticisms and suggestions on our manuals are greatly appreciated.

If you are familiar with HTML you can use the view source option to get an editable copy of each page. You are welcome to e-mail us with edited versions of pages of this or any other DP4 manual. You can contact us at CustomerCare@itim-ts.com.


Lesson 1: A Heading Display

Traditionally programming courses begin with the creation of a very simple program, often one that just displays a short message, such as Hello World!, on the screen. Our first lesson does the same, except that it displays the name of the fictitious company, Acme Sales Order Plc, with whom all our programs will be concerned, as a screen heading. The tasks you will learn about in this lesson are:

· Starting the Program Editor

· Creating the Heading Program

· Compiling the Heading Program

· Running the Heading Program

You are guided through the specification of this program on a keystroke-by-keystroke basis. In later lessons the instructions will have less detail and you will need to remember what you learned in earlier lessons.


Starting the Program Editor

To Create a QA Build program , you run the program editor. You can achieve this by either running PROGMAKE from your DP4 work group or by selecting Editor from the QAB facilities section of the DP4 system menu.

1. Select the SALESORD database either by typing its name or by double-clicking on its name in the list of databases present.


Creating the Heading Program

  1. Type your initials in the dialog that appears and press <Enter>
  2. Press <Enter> to select Edit program
  3. In the dialog that appears enter MYPROG1 as the program name and press <Enter>
  4. Press <Enter> to create this program

1. Specifying the Program Summary and Type

2. Setting Up The Procedure

3. Designing the Screen

4. Compiling the Heading Program

5. Running the Heading Program


Specifying the Program Summary and Type

Specifying the program summary

Select the Summary option. A dialog appears in which you describe your program and select its type. It is good practice to give each program that you create a meaningful description, because this description appears with the program name when you ask QA Build for a list of programs. This makes it easier for you—and possibly other users—to select the intended program. Type this:

Screen heading display

Specifying the program type

Next specify the program type. All QA Build programs must belong to one of the following types:

Data Entry | updates the database interactively
Enquiry | inspects the records on the database without updating
Batch Update | updates the database with little or no user interaction
Report | prints details of records without updating the database
Library | holds and maintains useful procedures

Although our program does not access the database, select Data Entry as the program type. The reason for this seemingly inappropriate choice is that in the next lesson we shall add an interactive procedure to our program. You may safely accept the defaults for all the other questions in the dialog by clicking on the OK button.


Setting Up The Procedure

All QA Build programs consist of the program description, which you have now created, and the procedure tree. The procedure tree is a hierarchical structure showing the procedures used by programs and the relationships between them. From the procedure tree you can see the order in which the procedures are executed and which procedures call other procedures, that is, execute other procedures as though part of their own specification. In the simplest programs there is only one procedure in the tree.

Procedures are the fundamental building blocks of QA Build programs. They are stored independently of the programs themselves. Consequently, if you have specified a procedure for one program, you may also use it in another one.

Each procedure can have:

· one main map which determines the appearance of the screen; it may also use other subsidiary maps to display messages or menus of items for selection.

· processing for one main table, specifying how the records are accessed and whether records can be added, modified or deleted; it may also retrieve data from other tables but cannot normally update them.

· processing for fields, which could include filling them with an initial value and validating user entry. These fields may represent fields in the database tables or local fields, providing temporary storage for values (they serve the same purpose as variables in conventional programming languages)

It is because each procedure is subject to these limitations that complex programs usually require many procedures.

We are going to set up a new procedure called SCREEN_HEADING

  1. Press <Enter> to select Program flow diagram
  2. Select the Link button.
  3. In the dialog that appears enter the procedure name. SCREEN_HEADING and press <Enter>
  4. Press <Enter> to create this procedure. Press <Enter> to confirm.
  5. Select the procedure edit and add a brief description of the procedure function, such as:

Displays a header at the top of the screen.

6. We come to Procedure Body Editing. Answer some questions about the procedure type. There are only three that matter:

· the Procedure Type. Each procedure must belong to one of the following types:

Interactive | Data-entry procedure
Batch | Procedure without data entry or printing
Menu | A procedure offering the user a choice of actions
Print | A procedure that sends output to a print device
Combined menu/entry | A data entry procedure that ends when the user presses a function key to select another action
Action bar menu | Procedure to set up an action bar with pull-down menus
Save/exit menu | A procedure inviting the user to confirm or abandon changes before the database is updated (when a “private database” is being used
Sub device output | A procedure to select or send print to a different output device, and for multi-output devices
Device select/print | Procedure to select an output device interactively, at run-time
Run another program | Procedure to call another QA Build program, non-QA Build program or use a set of built-in commands
Link to C | Procedure which selects a procedure body written in C
Hot key set up | Procedure to set up hot key actions which can be called when executing subsequent procedures

This procedure is a batch procedure because there is no user input

· the procedure is not a database procedure because it does not use the database

· the procedure does not repeat.

You can accept the default answers for the other questions.

Click on OK to confirm your selection.

  6. Select the Screen/Form design

Designing the Screen

1. In the Screen Design dialog to start with the Main Map field is set to 0. Press <Enter>. The focus now changes to the Map Assignment menu where the Map Number option becomes highlighted and suggests 1 (a number that has not been used in the program’s mapset)

2. Press <Enter>. QA Build asks
Create this map ? Yes
Press <Enter> to create map 1

3. The Map Assignment menu gives various facilities. You can delete or copy an existing map, use no main map or edit a map.

Map Editing

[Check the following - it’s probably changed] Option 7 - Edit map is highlighted. Press <Enter> to select it. The Map Edit screen appears. You are going to use the facilities of the Map Editor to create the screen heading. To do this, you will need to add some text. You can add titles, fields and icons to maps—these and their others contents are called controls in the Map Editor.

Note: DP4 controls have properties such as the font used and the contents of a text field. They can all be changed by the user. Controls can be added to the maps using the tool box shown below.

[pic of tool box goes here]

To display the tool box, select its option on the view menu; to remove it, do the same. The tool box is a floating window. To position it, click its title bar and drag it.

Double clicking on a tool adds the corresponding control to the top-left corner of the current map. Single-clicking an icon makes a cross-hair cursor appear when you move the pointer over any open map. Position the cross-hair where you want the control, then either click to add the control at its default size or drag the mouse to add the control, sizing it yourself.

Adding Text and Titles

To add text to the map you may do either of the following:

· choose static text from the Controls option of the title bar. This creates a standard-sized text box at the top left hand corner of the map

· click on the static text icon in the tool box and move the cursor over a map where it is displayed as a cross. This cross is used to specify the size of the text field, the first click of the mouse specifies one corner of the field and releasing the button specifies the other.

4. Turn off the title bar which is limited in its display possibilities. Create a static text box—if it is the wrong size, you can easily resize it—and move it to the top of the map; to move it simply click on the field and drag using the mouse to the required position. To add text to the field, double click on it—this brings up the text properties dialog from which you can change every aspect of the text box. Feel free to experiment with different fonts and effects, to produce an attractive screen heading. You might, perhaps, create something like the following:

5. When you are satisfied with your map design, save it and exit the Map Editor (both from the File menu).

6. Back in the Program Editor, you must specify the output method. Accept the default, Top of Screen, because that is exactly where we want our screen header to appear.

7. Normally Field Editing would follow, but we have not used any fields, so no field processing is necessary.


Compiling the Heading Program

Your heading program is now complete. To exit from the Program Editor select Exit from the File menu.

To compile your QA Build program, run the Program Compiler. You do this from the DP4 menu by selecting the Compiler option.

1. Specify the database as SALESORD and press <Enter>. The QAB Program Compilation menu appears.

2. Choose the Selected programs option and enter MYPROG1 as the name of the program. Alternatively choose the option: Changed programs.
During compilation, the Program Compiler displays the name of the procedure currently being processed in its screen header. Any warnings or errors are given in pop-up messages. When compilation is complete, summary information is presented concerning the code and data size and the total number of warnings and errors.

3. Exit to the QA Build menu by repeatedly pressing <Esc>.


Running the Heading Program

Having successfully compiled your program, you can run it from the QA Build menu by selecting the Run program option.

1. Specify the database as SALESORD and press <Enter>.

2. Enter MYPROG1 as the name of the program and press <Enter>. Alternatively press <Ctrl + P> for a menu of programs present and double-click on MYPROG1.

It may appear that nothing happens or you may get a brief glimpse of something that immediately disappears, depending on the speed of your computer system. Almost certainly your program has run quite correctly, but when a QA Build program ends, the screen clears. So the program correctly displayed your heading, but because it ended immediately afterwards, the screen cleared before you had a chance to see your creation. In the next lesson we overcome this problem by adding another procedure to the program which forces it to wait for a click on a mouse button or a keypress before ending. Your header will then remain on screen as long as you wish, until you end the program by clicking on the button.


Lesson 2: A Pause Procedure

In this lesson we add a second procedure to the program created in Lesson 1. The new procedure will force the program to wait for a key press before it ends. Consequently you will able be to view the screen header you created in the last lesson for as long as you wish. In this lesson you will learn about:

· adding procedures to existing programs

· the relationship between procedures in programs that use more than one.

Operations that were described in step-by-step detail in the last lesson will not be described again this time. Don’t be afraid to go back to earlier lessons to refresh your memory. This Lesson falls into the following logical steps:

1. Adding a Procedure to an Existing Program

2. Designing the Pause Screen

3. Compiling and Running the Amended Heading Program


Adding a Procedure to an Existing Program

Start the Program Editor and go to MYPROG1’s procedure tree
In the Procedure Tree:
[We need to work out exactly how new procedures will be inserted into the program tree]
The new procedure, called CLICK, allows the user as much time as required to look at the current screen by displaying the message: Click on OK or press Return to continue ... and waiting until the user either clicks on the OK button or presses the <Enter> key.

Add CLICK below SCREEN_HEADER in the procedure tree, as follows:

  2. Press <¯> followed by <Insert>. In the Procedure Link Editing window that pops up, type CLICK for the name of the procedure. Press <Enter> to create and accept the procedure name.
  3. Add a description for the procedure, such as:
    Waits for user to click on OK button

4. Consider the requirements of the procedure:

Option | Choice | Explanation
Procedure Type | Menu/Switch | It prompts the user for a decision (even though there is little element of choice in this procedure) to control the program
Database procedure ? | No | It does not access the database
Repeated Procedure ? | N | It is not a repeated procedure

As before, we omit Table Processing. If you specify that the procedure does not access the database, QA Build will not allow selection of Table Processing, because it is not relevant.


Designing the Pause Screen

Maps are identified by a mapset name and a map number. The mapset name defaults to the program name, but you can specify a different one if you wish. General-purpose procedures such as CLICK are often shared amongst several programs. So, you might wish to change the mapset name to make it specific to your program. You may also opt to change the remarks mapname, which is the mapset for questions, messages and errors. Of course, if the main mapname and remarks mapname are different, your program may contain pairs of maps having the same numbers. This does not matter if the maps belong to different mapsets.

1. Select the Screen/Form design and create and new map

2. Double-click on the map to bring up its properties and ensure that the title bar box is unchecked

3. Create a static text field containing the message:
Click on OK or press Return any key to continue...

4. Add a button to the map. Double-click on it to open its properties dialog. Make it a text button with the caption OK, give it field number 1, make it the default push button, make the associated key press <Enter> (so that clicking the button has the same effect as pressing <Enter>) and accept the other defaults.

5. Double-click on the map itself and in the Map Properties dialog set both the Rows and Columns to 1.

6. Save the map and exit the map editor.

7. In the Screen/Form set-up tab, select the map type as Pop-up Window. This is a temporary window that appears for only as long as it is needed.

Defining the Field Processing

Although the button is technically a field, there is no need to define any field processing.


Compiling and Running the Amended Heading Program

Exit from the Program Editor, recompile and run MYPROG1. This time your screen header should appear together with the map containing the OK button. These should remain on the screen until you indicate your wish to continue by either clicking on the button or pressing the <Enter> key. Then the program ends and the screen clears.


Lesson 3: Creating a Table Update Program

The first two lessons were intended primarily to introduce the main functions of QA Build; the program you created did not access the database. The value of QA Build is in creating your own individually tailored programs that access the DP4 database and present its contents in exactly the format that you require or allow you to amend its contents or both. In this lesson you will write a single-procedure program to update the EMPLOYEE table. Despite its simplicity your program allows you to insert, delete and amend records. In this lesson you will learn about database access, field validation and the modification of existing programs.

The logical steps are as follows:

1. Specifying the EMPLOYEE Program Summary and Type

2. Creating the EMPLOYEE Program Procedure Tree

3. Table Processing for the EMPLOYEE Program

4. Designing the Map for the EMPLOYEE Program

5. Field Processing for the EMPLOYEE Program

6. Compiling and Running the EMPLOYEE Program

7. Using the EMPLOYEE Program

8. Modifying the EMPLOYEE Program

Start the Program Editor, select the SALESORD database and enter MYPROG2 as the name of a new program.


Specifying the EMPLOYEE Program Summary and Type

1. Add the following text as your program summary: Add, change and delete records in the EMPLOYEE table

2. For program type select Data Entry. This option is used for programs that add records to the database interactively

3. Accept the defaults for the remaining fields in the screen by clicking on OK. The screen should look like this:


Creating the EMPLOYEE Program Procedure Tree

Your program has just one procedure, which we shall call EMP_UPDATE.

1. To insert a procedure, press the <Insert> key (pressing <Enter> twice, <L> for Link or <I> for Insert would work as well). [This will probably need changing]. The PROCEDURE LINK EDITING box appears

2. Type the name of the procedure as: EMP_UPDATE

3. Right-click on the new procedure to open the Procedure dialog
With the Procedure tab selected, type this description:
Update records in the EMPLOYEE table
Accept the default of EMP_UPDATE for the name of the procedure body by clicking on OK with the mouse or cursori down to OK and hitting <Enter>

4. QA Build suggests defaults appropriate to a data entry program, including:

Option | Choice | Explanation
Procedure type | Interactive | allows the user to update the EMPLOYEE table interactively
Database procedure ? | Yes | allows the user to update the database
Repeated procedure ? | Yes | means the program repeats until a condition is met such as the user pressing <Esc>

5. Click on OK to accept the defaults suggested.


Table Processing for the EMPLOYEE Program

1. In the Procedure dialog select Table Processing

2. Select Main Table Processing. The Main Table Processing dialog appears. This contains more fields than the ones you’ve seen so far; you will need to think about the task you wish this program to perform. Specify the Table as EMPLOYEE and accept the Identifying role as MAIN.
The manner in which records are read from the database is determined by the Access Mode. Eight different access modes are available, but for the moment we shall consider just three:

Normal | reads a record when its key, in this case EMPLOYEE_NUMBER, has been entered
Already fetched | is used for processing a record which has already been read from the database
Window | displays a list of existing EMPLOYEE records to select from and update

3. Specify Access Mode as Normal, the default. We shall consider other methods of access later.

4. You want to be able to add new records to the EMPLOYEE table and modify and delete existing records. So, accept the defaults for the following questions:

Option | Selection
Update main table ? | Yes
Condition to update | None
Process existing records ? | Yes
Allow new records ? | Yes
New record dialog | 120
Allow record deletion ? | Yes
Record deletion dialog | 121
Deletion confirm required ? | Yes
Condition to delete | None

5. The default answers for New record dialog and Record deletion dialog are numbers which identify message maps. These are special maps, created automatically by QA Build, which appear automatically when a QA Build program needs to send a message to the user. Note that the numbers that appear on your system may be different to those specified here.

6. Leave the Auto-Increment Table? box unticked. Auto-incrementing is a facility whereby a new key is allocated automatically by the database for a new record. QA Build skips the remaining questions to do with auto-incrementing.

7. If, when you enter the EMPLOYEE_NUMBER key, no corresponding EMPLOYEE record exists, you want the facility to scan forwards and backwards through EMPLOYEE records until you find the one you want. You also want to add new EMPLOYEE records to the database and to retype the EMPLOYEE_NUMBER if need be. There are several Search methods to choose from; at least two of these, Scan if no match and Always offer scan, satisfy the above requirements.
Accept the default Search method, which is Always offer scan. It differs from Scan if no match, in that even if the record is found, the option to scan forwards and backwards is available. Other search methods, namely Exact match and Multiple Choice are discussed later.

8. The procedure accesses the EMPLOYEE table using its primary key of EMPLOYEE_NUMBER, that is, using the main index. Accept the default for Search index, which is Main Index.

9. Take the defaults for the following options:

Option | Selection | Description
Search depth | ! | Entering ! allows QA Build to set the number of parts used in a multi-part key to an appropriate value automatically. This isn’t an issue in your procedure, where the EMPLOYEE table is accessed only by EMPLOYEE_NUMBER
Message if no record found | 122 | The automatically generated message 122 is displayed when QA Build fails to find a matching record. You could look at, and change, this message, by pressing <E> to go to the map editor
Message when record found | None | Normally, you don’t want to display a message when a matching record is found
Record scan dialog | 123 | By selecting Always offer scan, you have provided the ability to scan through records. When doing so, this message allows you to accept the current record or select another

10. QA Build skips the questions: map to display choice list, map to display item in list, map to attach choice list to, which are only appropriate to the Multiple choice and Window search methods—we shall use these in later lessons.

11. You can impose a condition that must be met for access to the EMPLOYEE table to be allowed, and a condition that must be met by an EMPLOYEE record for that record to be offered when scanning. We wish to do neither, so specify the following.

Option | Selection
Condition to access | None
Condition on record | None
Apply to record not on db ? | No

12. Record locking can ensure that you have exclusive access to a record at run-time. For your procedure, accept the defaults which don’t invoke record locking:

Option | Selection | Description
Lock existing record ? | No | Answering Yes would prevent other users updating the record until the user who locked the record has secured the changes to the database
Disallow locked record ? | No | Answering Yes would prevent a locked record being read
Locked record retry question | None | Allows you to present a map offering the user various courses of action when the record is found to be locked

That completes the definition of the Main Table Processing screen. Confirm that it is filled out as follows:

[Screenshot to go here]

13. Click on OK to save the Main Table Processing screen.


Designing the Map for the EMPLOYEE Program

When the dialog appears, the focus will be on the caption—type in: Employee Table Update

You will also add a shadowed thin border effect to the map. Just below the caption there are a group of radio buttons that control the border style; click on the appropriate one as shown below:

Button | Choose? | Description
None | No | No border
Thin | Yes | Applies a plain border around the text field
3D | No | Applies a 3D-style look to the text field

There is a Shadow tick box. Click on it to give the text field a shadow. Finally, to centre the text, click on the Centre option in the Justification panel. Now click on the OK icon located at the bottom of the dialog to return to editing mode.

Add the following text fields to the screen; select right justification for each.

Employee Number

Employee Name

Gender

Grade

Date Of Birth

When you have finished them, select them all and use the right-alignment button on the action bar to arrange them neatly.

Adding Icons

The Map Editor allows you to add icons to the screen. Either click on the I icon in the toolbox and then at the appropriate place on the screen or choose Icon from the Controls option on the menu bar.

Do one of the above and place an icon on the screen just to the side of the title. Its position can be changed by clicking and dragging it. To change the icon type, double-click on it. There will be a range of DP4 icons in the dialog that appears—find the DP4 icon and click on it. Now choose OK from the bottom of the dialog box to return to editing mode.

Adding Database Fields

To complete the update entry screen, you must add database fields to the screen. These must be positioned so that they relate to the corresponding labels that you placed earlier. For example, the Employee number field needs to be placed adjacent to the Employee number text label.

The devices for displaying database fields in the map editor are known as edit text controls. To add an edit control to the screen either click on the edit text icon in the toolbox or choose Edit from the Controls section on the menu bar. Place it next to the Employee number label.

Next you must specify the source of the data to fill the control. Double-click on the edit control.

Double-clicking on the control causes the Edit Properties dialog to appear. This dialog can be used to specify the appearance, access rights and contents of edit controls. For the control to display information from a database, you must specify in the Data section of the dialog what it is to display. Click on the Data section. Under the Source heading, tick the Database box which will cause a Field pull-down icon to appear. Clicking on the pull-down icon brings up a menu of all the fields in the database. Find and select the Employee_Number field.

In the same way add ‘Edit’ controls for the remaining labels: Name, Gender, Grade, and Date Of Birth.

It is important that the controls are inserted in this sequence—the order that the controls are added is also normally the sequence in which the user moves between controls when using the program.

Your screen should appear as follows:

The field layout needs to be specified. This is set on the main map properties dialog. Access this either by double clicking on a blank area of the map or by choosing Map Details from the Edit option of the menu bar.

In the Field Layout section of the dialog are the Rows and Columns headings that specify the format of the fields on the map. In this example, the map you have created consists of one column of fields that is five rows down. Accordingly, place 5 in the rows field and 1 in the columns field.

Miscellaneous Features

QA Build provides many features for customising the display features of an Edit text control. Here are some more from the General page that you haven’t used yet:

Option | Description
Field Nr | The Map Editor automatically supplies the next unused field number. Numbering the fields correctly is essential, because this determines how the cursor behaves in the map.
Shared | Enable the Shared option to apply the properties of a previously created edit control or to create a new shared edit control. Disable it, if you want to define the properties of the edit text control uniquely.
Type | With Shared enabled, you can use the Type: list to select the shared edit control whose properties you want to apply. If creating a new shared edit control, specify the name under which it will be known.
Edit single/multi line | Define whether single-line or multi-line text editing is possible
Clear first | Enable this to display the database default value for the field. Disable it to retain the previously entered value for the field
Prompt | Enable this to display a drop-down arrow one space to the right of the edit control, simulating a combo control. Clicking on the arrow or pressing <Ctrl+P> causes any correctly attached multiple choice map to be displayed.
Function Key | Enable this to allow special action to be taken with function keys, such as taking a short cut to the next menu. (In QABuild combined/Menu entry procedures, this property is automatically enabled)

When your design is complete, save the map by choosing Save from the File menu. Alternatively, use the key shortcuts <Alt + F>, <S> and <Enter>. Leave the map editor and return to the Program Editor by choosing Exit from the File option in the menu bar. Exiting can also be achieved by using <Alt + F> and <X>.

In Screen Design accept the default output method, Top of Screen, and the other defaults.


Field Processing for the EMPLOYEE Program

All that is left to do is to specify the field processing that will control the contents of the EMPLOYEE fields you have added to the map. Although we won’t do so, it is also possible to use field processing to change the contents of database and local fields that are not displayed on the map.

1. Select the Field Processing.

2. QA Build can automatically set up the necessary field processing from the fields in the map you have just created. Your map contains five fields, EMPLOYEE_NUMBER, NAME, GENDER, GRADE and DATE_OF_BIRTH. QA Build assumes that they are all input fields. It knows that EMPLOYEE_NUMBER is the record key and that once you have filled in the employee number it can fetch the record and display the appropriate data in the other fields. In this example, its assumptions are correct and you can let QA Build do the work for you by selecting Generate field processing.
Later you will learn how to add further processing for initialising, totalling and validating fields


Compiling and Running the EMPLOYEE Program

Your EMPLOYEE update program is now complete. Exit the Program Editor by selecting Exit from the File menu.

Compile your QA Build program by running the Program Compiler and specifying the database as SALESORD and MYPROG2 as the program. Exit to the DP4 menu by repeatedly pressing <Esc>.

Having successfully compiled your program, you can run it from the QA Build menu by selecting the Run program option.

1. Specify the database as SALESORD and press <Enter>.

2. Enter MYPROG2 as the name of the program and press <Enter>. The EMPLOYEE update screen appears.


Using the EMPLOYEE Program

The EMPLOYEE update screen allows you to scan through, insert, delete and modify EMPLOYEE records. The various messages and menus that appear while searching and updating the Employee table were automatically created for you when you filled in the Main Table Processing.

Accessing the EMPLOYEE records

The cursor is positioned initially on the EMPLOYEE_NUMBER field, which contains the value 0. QA Build expects you to enter the appropriate EMPLOYEE_NUMBER to access an EMPLOYEE record. Type the number, for example 1, of an existing employee followed by <Enter>.

The record having EMPLOYEE_NUMBER 1 is retrieved and the fields of the Employee update screen are filled with the respective values. Also the record scan dialog map appears; it provides these options:

Option | Function
<Enter> | Invokes the Record deletion dialog map (discussed later)
<Esc> | Moves the cursor back to the EMPLOYEE_NUMBER field to select another key
<Down arrow> and <Right arrow> | Scan through the Employee records in ascending EMPLOYEE_NUMBER order
<Up arrow> and <Left arrow> | Scan through the Employee records in descending EMPLOYEE_NUMBER order

Adding EMPLOYEE records

When the cursor is positioned on the EMPLOYEE_NUMBER field, you can insert a new record by typing any number (such as 16) that doesn’t correspond to an existing EMPLOYEE record key, followed by <Enter>. QA Build displays the New record dialog map which provides these options:

Option | Function
Option 1 - Insert | adds a new record with the specified key. The cursor moves to the NAME field so that you can type the employee’s name. Pressing <Tab> or <Down Arrow> moves the cursor to the next field. Pressing <Tab> on the last field, or <Enter>, invokes the submit record menu:
Option 2 - Search | allows the user to search through the existing records.
Option 8 - Rekey | Prompts for another employee number to be inserted.

Amending and deleting EMPLOYEE records

When the cursor is positioned on the EMPLOYEE_NUMBER field, you can amend or delete an existing record by typing its key and pressing <Tab> followed by <Enter>. The record is retrieved and the fields of the EMPLOYEE update screen are filled with values. The Record scan dialog map appears:

Press <Enter> to invoke the Record deletion dialog map:

Use Option 1 - Amend to modify the record.

Use Option 2 - Delete to delete the record, but since you answered Yes in table processing to the question deletion confirm required, you will be asked: Do you really want to do this ? No

Exiting from the Employee Update screen

Press <Esc> from any field in the screen to exit from your program.


Modifying the EMPLOYEE Program

One problem with your program is that there is no validation on the GENDER field. Clearly, only values of M and F should be allowed. GENDER would, ordinarily, be a Boolean field, with allowable values of M and F. It has been defined as a character field to provide a validation exercise. Consequently, with the program in its present form you could enter a meaningless value such as X or 3 in the GENDER field. The purpose of validation is to ensure that only meaningful values are entered. Fields are also validated by QA Build according to their type and their upper and lower limits, defined in MAKEDB.

Validating the GENDER field

1. Run the Program Editor, specifying SALESORD as the database and MYPROG2 as the program to edit. On the Procedure Tree diagram highlight EMP_UPDATE. In the Procedure Dialog select the Field Processing

2. A numbered list of EMPLOYEE fields is displayed. Use the mouse or cursor keys to highlight the GENDER field.

3. Select Edit Field. The processing for the GENDER field appears. The questions on this screen enable you to change the field processing. For example, if you wanted to display the contents of the field without allowing the user to modify it, you would change the answer for Input field ? from Yes to No.

4. To add validation, click on the option Validation condition. From the Formula Editing menu that pops up select Option 1 - Formula/Condition Nr. Press <Enter> to accept 1, the formula number suggested. [Check that this is as described]

5. To specify the validation condition, select Option 7 - Edit formula/condition. Another pop up appears, allowing for a formula of up to four lines, and including various questions. Type the condition:
employee.main.gender._ = "M" or "F"

6. Click on the option Remark on failure. QA Build can output a message if the condition is not met. Select Edit message to accept the proposed message number and to enter the Map Editor.

7. Add a static text control to the screen that is [one unit high and fifteen units long]. Double click on the control to bring up the Text Properties dialog then insert the following text for the caption:
Enter "M" (male) or "F" (female)
To add interest, you could also add a warning icon to the map and a suitable caption in the title bar.

8. Now add a button that can be clicked to clear the message when it has been read. Click on the Button icon or the Button choice under the Controls option in the menu bar. Move the button to the side of the message.

9. Now double-click on the button to adjust its properties. Firstly, change the caption to OK. Tick the Default Push Button box and make the Associated Key Press equal to <Esc>.

10. As you have added an input control, this needs to be specified on the main map properties dialog. Double click on an empty part of the map to bring up this dialog—change the field layout to rows 1, columns 1. Leave the Map Editor and save the map you have created.

11. You are returned to the window where you typed the condition. There are still three questions to address:
Warning only ?, More ? and Continue on failure ?

12. If Warning only ? is Yes, the user may decide to ignore the validation message after entering an invalid value. We want to force the user to enter a valid gender code, so accept the default answer, No.

13. A condition with more than one part can be specified in a single compound condition or its parts can be specified separately by responding Yes to the question More ? One benefit of separating the parts is that each can be given its own validation message. Your condition has one part, so press <Enter> to enter No.

14. Continue on failure ? is automatically answered as No and skipped, because there are no further parts to the condition. If there were, you could answer Yes. This forces QA Build to continue evaluating the condition in order to see whether other parts are also failing.

15. Click on OK to save your changes

16. Exit from the Program Editor

You can now recompile with the Program Compiler and run your program with the Interpreter. Check that any entry for GENDER other than M or F raises your error message, complete with button, and you are forced to re-input.


Lesson 4: A CUSTOMER Table Update Program

This lesson shows you how to create an update program for the CUSTOMER table. Because the REGION table is a parent of the CUSTOMER table, you will learn about QA Build’s Related Table Processing. In addition, we discuss complex screen layouts and the way the cursor moves within them.

· Table Processing for the CUSTOMER Program

· Designing the CUSTOMER screen

· Field Processing for the Customer Program

· Using the CUSTOMER Program

· Amending the Region Table’s Related Table Processing

· Using the Amended CUSTOMER Update Program


Table Processing for the CUSTOMER Program

1. Start the Program Editor, choose the SALESORD database and insert your initials. Enter MYPROG3 as the program name. [Confirm that you do want to add the program to the database]

2. Select option 1 - Summary, [from the PROGRAM EDITING FUNCTIONS menu that appears. Fill out the program summary so it looks like this:]
[pic goes here]

3. In the Procedure Tree insert a procedure named CUST_UPDATE.

4. Right click on it to add to open the Procedure dialog.

5. Click on the Procedure tab and type a suitable description for the procedure body. [, accept the default of CUST_UPDATE for its name and add it to the database]

6. You will see that QA Build assumes quite correctly (from your entries under Program summary) that you want an interactive procedure that updates the database and repeats until <Esc> is pressed

7. Select the Table processing tab and Main table processing
The main table to process is the CUSTOMER table. As before, allow the addition, modification and deletion of records by accepting the defaults offered, but this time specify that you want to use the auto-increment facility and, since CUSTOMER is an auto-incrementing table you should enforce it, that is:

Option | Choice
Auto-increment table ? | Yes
Must use auto-inc for new | Yes
Must Use Auto-inc | error 123

When you add a new CUSTOMER record, QA Build will force you to use its allocated customer number

Your entries in the Main Table Processing screen should match the following:

[screenshot goes here]

8. Save the Main Table Processing screen by clicking on OK. The CUSTOMER table has parents, so select Generate Parent Checks. This ensures all the necessary run-time parent checks, including the generation of dialog messages and default entries for parent-checked fields that are filled out incorrectly.
When parent checking has been carried out, you can access any of the fields on the parent tables and any fields on tables upwardly accessible from the parents. For example, in this program you could use fields on the REGION and EMPLOYEE tables.

9. Select the Screen/Form tab.


Designing the CUSTOMER Screen

Before we can proceed to design the screen for our Customer program, we must consider how the cursor moves in screens where the fields are arranged in more than one column.

How the Cursor Moves in Complex Screens

QA Build assumes that fields are arranged in a grid—that is, fields are arranged in rows and columns—with field numbers allocated from left to right and top to bottom. The number of rows and columns in the map is set from the Map Properties dialog. So, in a screen with four rows and five columns, the fields would be numbered 1 to 20 as follows:

field_1 field_2 field_3 field_4 field_5
field_6 field_7 field_8 field_9 field_10
field_11 field_12 field_13 field_14 field_15
field_16 field_17 field_18 field_19 field_20

When the <¯> key is pressed, the destination field number is calculated by adding the number of columns to the current field number. So, in the above example, if the cursor is positioned on field_4, and you press <¯>, QA Build repositions the cursor on field_9, because 4 + 5 = 9. The reverse applies if the <> key is pressed. For this reason, if you incorrectly number the fields, the cursor movement routines will not work as expected. Similarly, if you incorrectly set the number of rows and columns, some fields may be inaccessible. If you leave the numbers of rows and columns at the default setting of 0, the cursor will be unable to appear in the map and the Field out of range error message will be generated when you attempt to set up the field processing.

Of course, in a practical program it is rarely possible to organise the fields in a perfect grid like the one above; the sizes of fields vary depending on the data type and other layout considerations inevitably impose constraints on the way in which they are arranged. It is still possible, however, to make the cursor move in an orderly manner when the fields are not so regularly arranged. We “pretend” that the ideal grid is still present and we allocate each field the number of the closest field in that hypothetical grid. This means, of course, that some—and perhaps most—field numbers are missing, as in the following example:

field_1 field_2
field_6
field_11 field_12 field_13
field_16 field_17 field_19 field_20

The cursor movement routines still work because, if the calculated destination field number is that of a missing field, the calculation is repeated until an existing field is located. For example, if you are on field_2 and press <¯>, 2 + No. Columns (5) gives 7. Field_7 does not exist. So QA Build repeats the calculation with field_7. 7 + No. Columns (5) gives 12. This field does exist, so field_12 is the next input field.

You are going to design the following data entry screen for the CUSTOMER table:

It has ten fields, including seven from the CUSTOMER table, one from the REGION table and two buttons. These are arranged in four rows and five columns. The ADDRESS field only counts as one row, even though it is three lines deep. The field numbering is the same as that in the example above; field numbers 3–5,7–10,14,15 and 18–20 do not exist and are omitted.

1. Enter the map editor

2. Include the text and add the following edit controls, taking care to specify the field numbers indicated in brackets, CUSTOMER_NUMBER (1), NAME (2), ADDRESS (6), CREDIT_CUSTOMER (11), CREDIT_LIMIT (12), BALANCE (13), REGION_CODE (16) and NAME (17)
Note that the NAME field occurs twice: the first occurrence for the CUSTOMER.NAME and the second for the REGION.NAME. The respective tables are identified when you specify the field processing

3. Add a 3D effect to each edit control by ticking the 3D box under the appearance section. Tick the clear first box for fields 2, 6, 11 and 16. Make field 6 a multi-line field. Tick the prompt option for field 16.

4. Add two buttons with field numbers 19 and 20. For the first button make the caption OK and give it an associated key press of Enter. For the second button, make the caption Cancel and give it an associated key press of Esc. Place them at the bottom of the screen.

5. Double click on the map to bring up the properties. Ensure that: the field layout is set to 4 rows and 5 columns, the border is set to thin and shadowed and the title bar box is ticked.

6. When your design is complete, save the map and leave the Map Editor. In Screen Design select Top of Screen as the output method.


Field Processing for the CUSTOMER Program

When your map is defined, you can allow QA Build to generate the required field processing. This time, however, you must inspect what QA Build has done and change some of the entries.

1. Select the Field Processing tab

2. Select Generate Field Processing, then Field Editing. The NAME field is listed twice. Use the Field Details option to look at the field processing for both occurrences

3. Specify that the NAME field processed in step 2 is from the CUSTOMER table

4. Specify that the NAME field processed in step 8 is from the REGION table
Fields on the parent record cannot be input fields. For the REGION.NAME field, therefore, you must change the answer to the Input Field ? question from Yes to No

5. Exit to the Program Editor.


Using the CUSTOMER Program

Compile and run your program. When you run the program, observe that:

· You may insert new CUSTOMER records, but you must use the CUSTOMER_NUMBER which the program chooses. This number is automatically incremented by 1 each time. In Main Table Processing, if the Must Use Auto-Inc For New? option were set to No instead of Yes, QA Build would allow you to modify the suggested CUSTOMER_NUMBER—for example to select a number that is available because a record has been deleted.

· You may scan through, delete and modify CUSTOMER records as you did with EMPLOYEE records in the last lesson.

· If you type a field entry that does not have a parent, you are offered the nearest match on the parent table as a default. For example, the first four region codes are: ANG, CAM, COR and HUN. If you type C, the program suggests CAM as the nearest match. The name of the region is displayed when the region code has been input.


Amending the Region Table's Related Table Processing

Amending the Region Table’s Related Table Processing

Let’s now look at the processing of parent tables that QA Build has generated.

1. Run the Program Editor.

2. Go to Related Table Processing.
QA Build has generated processing for the REGION table, as you would expect, but it has also recognised that this table has the EMPLOYEE table as a parent. The asterisk (*) before the REGION table indicates that it is processed by the current procedure. The options you can use from this screen are:

Option | Description
Edit | Allows you to change the related table processing for the table highlighted
Delete | Removes parent checking for a related table (the asterisk is removed)
Validate/Auto set up | Generates parent checking for the highlighted table (denoted by an asterisk)
Exit (X) | Takes you back to the Table processing tab

3. Edit the related table processing for the REGION table.

4. The Table name is REGION. A program may use multiple copies of the same table, but each must have a different role. For example, it might use two copies of the SUPPLIER table, one for the principal supplier of a material and one for an alternative supplier. You could then name these roles PRINCIPAL and ALTERNATIVE.

5. Leave Identifying role as MAIN
The available Access mode options are:

Option | Description
Already fetched | Is used for processing a record which has already been read from the database. This is the normal option for enquiries, as you will see later
Check parent on database | Checks that a matching record on the database exists when you enter the key fields of the parent. This is the option currently being used
Join parent from database | Is used for displaying fields from the parent table without entering key fields. This option is more efficient than Check parent where existing records are being displayed. Do not use this option for adding new records
Prohibit parent | Checks that there isn’t a matching record on the database when you enter the key fields

6. Specify Access Mode as Check parent, which should be the default

7. Answer No to Update Table ? Updating the REGION table during the procedure is not a requirement

8. Answer Yes to Verify Table ? to check that this record is not altered by another program during the procedure

9. Answer None to Update Condition. In other situations, you may specify a condition that must be met for QA Build to allow an update to take place

10. Answer No to Allow Initial Join Fail ? Answering Yes would allow processing to continue after failing to join to the REGION table

11. Answer No to Warning Validation Only ? This means that the access mode you chose (Check parent on database) is enforced; in other words, you must enter an existing REGION_CODE

12. QA Build skips the Validation Fail question. If you had answered Yes to the previous question, when a warning validation fails, you can ask users whether they want to ignore the fact that the REGION_CODE doesn’t exist

Specifying Multiple Choice Search Method

At present, Search method is Always offer scan. When you enter the REGION_CODE key, whether the record is found or not, you can scan forwards and backwards one record at a time

A more user-friendly approach is to present a list of REGION_CODEs and highlight the one that most closely matches the REGION_CODE input by the user. The user could make a selection by scrolling up and down the list, and use a scroll bar to see any additional items that were off the screen.

To use this facility:

1. Select Multiple choice as the Search Method

2. The procedure accesses the REGION table, using its primary key of REGION_NUMBER, that is, using the main index. Accept the default for Search Index, which is Main Index

3. Use the <Enter> key to accept the default answers to the following questions:

Search depth | !
Message if no record found | 125
Message when record found | None
Record scan dialog | -

When you select the multiple choice access method, QA Build needs rather more help than usual; in particular you need to provide:

· a map to display the list of choices

· a map to display the items, namely the REGION_CODE and REGION.NAME

Setting up the choice list

To set up the multiple choice list:

1. Select Map to display choice list, create map number 2, then choose to edit it. Design your map to look like the following:

Remember that:

· each field is an edit control apart from the Please select a Region Code text at the top of the screen.

· the field numbers are given under the option Control List found under Edit in the menu bar.

· when adding the first choice field, make the size of the field large enough to accommodate the REGION_CODE and REGION.NAME fields that are to be displayed. Select the control by clicking, then copy and paste it to add the other choice fields

· you should add a field number 100. This enables the scroll bar. You do not want field 100 visible in the finished map, so make it small, do not give it a border and position it where it is not on top of any other control

2. Set up the rows and columns on the MAP PROPERTIES screen to ensure that the cursor keys work intuitively. To arrange that the user can never move the cursor to field 100, don’t include it in your calculation of the number of rows—that is, set up the screen with 2 columns and 6 rows.

3. Save your map and exit from the map editor.

Setting up the item list

To set up the item list to display the REGION_CODE plus REGION.NAME

1. Select Map To Display Item In List, create map number 3, then choose to edit it. By adding the database fields REGION_CODE and NAME, design your map to look like this:

The two fields have no borders; they will use the borders provided by map 2. Save the map and leave the map editor.

2. Specify Map To Attach Choice List To as map 1. This redisplays the main table map after a REGION_CODE has been selected

3. In map 1 you must add an attachment point to indicate the position where map 2 is to be displayed. The top left-hand corner of the attached map will be over the top left-hand corner of the attachment point. You must allocate the attachment point a field number equal to 100 plus the number of the map being attached, so in our current program it is 100 + 2 = 102.
Note: the attachment point itself is only visible in the Map Editor; it is never displayed in the finished program and so you may safely allow it to overlie other controls in the map.

4. Accept the defaults for the remaining questions

Option | Choice
Condition to access | None
Condition on record | None
Apply to record not on db ? | No
Lock existing record ? | No
Disallow locked record ? | No
Locked record retry question | None

Confirm that the Main Table Processing screen is filled out as follows:

[screenshot goes here]

4. Click on OK and then exit the Program Editor


Using the Amended CUSTOMER Update Program

Recompile your program and run it. You will see a screen similar to the following one, if you try to specify a REGION_CODE that doesn’t exist.

You can use the cursor keys to move from one region to another and the scroll bar to see additional pages. <Enter> selects the highlighted region.


Lesson 5: Customer Number Enquiry Program

In this lesson we create an enquiry program for the CUSTOMER table. This program displays the CUSTOMER fields when the appropriate CUSTOMER_NUMBER has been entered, but does not allow update of the database.

Writing an enquiry program consists of little more than designing a map, ensuring that the key fields appear first on it and are input fields, and that the other fields are not input fields. By making this a customer number enquiry, we can make use of the map from the previous lesson’s map. You will learn how to re-use existing maps.

By now you should know your way around the Program Editor. Consequently, the following steps just pick out the questions that require answers other than the defaults proposed.

1. Start the Program Editor and create a new program called MYPROG4

2. When filling out the program summary, specify the Program Type as Enquiry. Selecting this option reduces the number of questions QA Build asks you.

3. For the name of the procedure and the procedure body, type C_NO_ENQUIRY

4. For the procedure overview, all you need do is enter the procedure description; QA Build gives you acceptable answers for the other questions—for example, Update Database is No (the database is opened in read-only mode)

5. For Table Processing, specify:

· the CUSTOMER table as the main table to process

· MAIN as the access index

but choose Exact match as the search method. This means that the program searches for a CUSTOMER record that exactly matches the CUSTOMER_NUMBER entered. If no matching record is found, the following message is displayed:
Can't find Customer record
The Main Table Processing dialog should look like this:
[screenshot goes here]

6. Having specified the CUSTOMER table processing, select Generate Parent Checks, since you also need to access information from parent tables
To see what QA Build has done, look at the related table processing for the REGION table:
[screenshot goes here]
Notice that QA Build has generated a set of processing options suited to an enquiry program:

Option | Choice | Explanation
Access mode | Join parent | Displays the REGION fields automatically, the key field, REGION_CODE, is not entered. This option is more efficient than Check parent where existing records are being displayed
Search method | - | Questions on search method are not applicable
Search index | - |
Search depth | - |
Message if no record found | 122 | Generates the message Can’t find Region record if there is no valid parent, but in this event the enquiry program does not terminate

7. Select Screen/Form design. Designing a screen is quick and easy because the main map in MYPROG4 is suitable.

8. [This will need a good seeing to!] You copy a map using the map assignment menu. For Map 1 select Option 6 - Copy map. In the window that appears, type the name of the mapset that you want to copy from, as PROG2. Press <Tab> to move to the Map Nr field. To bring up the list of the maps in the mapset, press <Ctrl + P> or click on the down arrow. Use the cursor keys to view each map, select the required one, map number 1 and click on OK.

9. The only changes to the map are to edit the title bar contents to reflect the new program’s function and to delete the attachment point which is no longer needed.

10. Accept the defaults for the screen display.

11. All that remains is to complete this procedure’s specification by defining its field processing. From the Field Processing tab select Generate Field Processing. Then edit the field processing QA Build generates to ensure that for all fields except the key field, CUSTOMER_NUMBER, the Input Field ? question is set to No and that the NAME field in step 8 is from the REGION table.

You can now compile and run your program.


Lesson 6: A Customer Name Enquiry Program

In this lesson we create another CUSTOMER enquiry program. In this one, however, access is by customer name rather than by customer number. This makes the finished program more “user friendly” since the user is more likely to know customers by their names than by their numbers. The program uses the Scan if no match search method and INDEX_CUST_NAME, which is the secondary index of the CUSTOMER table.

1. Start the Program Editor and create a new program called MYPROG5

2. When filling out the program summary, specify the Program Type as Enquiry

3. For the name of the procedure and the procedure body, type C_NAME_ENQUIRY

4. For the procedure overview, just enter a suitable description, e.g. Customer name enquiry

5. For table processing, specify:

· the CUSTOMER table as the main table to process

· Scan if no match as the search method

· INDEX_CUST_NAME as the search index

The Main Table Processing should look like this:

[screenshot goes here]

6. Having specified the CUSTOMER table processing, select Generate Parent Checks, since you also need to access information from parent tables

7. For the screen layout, you can copy the MYPROG4 main map (map number 1) as before, changing the title bar text to reflect the new program’s function. There is no need to alter the screen layout, but you must renumber the fields so that CUSTOMER.NAME is field 1. To do this:

8. In the Map Editor select field 2 by double clicking on it.

9. Change the Field Nr to 1, followed by <Enter> or clicking on OK. Confirm your intentions to renumber the field when the Map Editor asks A control with field nr 1 already exists. Renumber fields? Click on Yes. Although this map is, strictly speaking, no longer correctly set up for cursor movement, this does not matter because there is only one input field that the cursor can visit. Save the map and exit from the map editor.

10. Use Generate Field Processing followed by the Field Editing option from the Field Processing tab to ensure that:

· the only input field is CUSTOMER.NAME. This should be field number 1 in the field editing list

· the NAME field at the end of the field editing list is specified as being from the REGION table

Your customer name enquiry program is now complete. Compile and run the program.


Lesson 7: A Pop-up Menu Program

Programs of some complexity usually require the user to select optional actions. Often such selection is by menus or function keys. Menus make the available options clear to the user, while function keys are sometimes provided as shortcut keys for experienced users.

In this lesson we create a pop-up menu procedure giving options to run the customer number and customer name enquiry programs created in lessons 5 and 6.

So far you’ve written programs containing interactive and batch procedures. Another procedure type is menu. With a menu procedure the user selects an option and the procedure tree is constructed so that the branch which is executed depends on that option.

Your program will combine the customer number and customer name enquiries on a menu like this:

The procedure tree is specified as follows:

In the procedure tree, the CUSTOMER_ENQ menu procedure is marked with an M, which indicates that it is a menu procedure. When option 1 is chosen, C_NO_ENQUIRY is executed; when option 2 is chosen, C_NAME_ENQUIRY is executed.

· Creating a Menu

· Adding the Subsidiary Procedures


Creating a Menu

1. Start the Program Editor, create a new program called MYPROG6 and specify the Program type as Data Entry. For the description, enter something like: Menu for running customer number and name enquiries.

2. Add a procedure called CUSTOMER_ENQ to your program. In the procedure overview, enter Menu as the Procedure Type. The procedure is not a database procedure and so it is not necessary to specify any table or field processing

Creating a Map to Display the Pop-up Menu

Most of the effort in creating a menu procedure is in the creation of its map. You are going to create the map for a pop-up menu. This is a standard type of menu used throughout DP4. Its options appear as a list in a pop-up window that overlays what is on the screen.

To create the pop-up menu

1. Go into the Map Editor

2. Create a new map. Add static text controls for the menu title and options.

3. Double-click on each of the options and give them associate field numbers of 1 and 2 respectively.

4. Edit the main map properties. Change the Map Type to pop-up menu, tick the box which says 4.500 position and give the map a thin border with shadow. Change the field layout to one column and two rows.
At runtime, menu options can be selected by using the cursor and pressing <Enter> or by pressing the number for the option in the menus.

5. Exit from the map and save it

6. For Output method, choose Pop up window


Adding the Subsidiary Procedures

To complete the menu-driven enquiry program, you must attach the customer number (C_NO_ENQUIRY) and customer name (C_NAME_ENQ) procedures underneath the menu procedure.

To attach the subsidiary procedures to the menu procedure:

  1. Return to the procedure tree. Press <↓> to extend the procedure tree beneath the menu procedure, and press <Insert>. An M appears on the tree and you are prompted for the option number; 1 is suggested as a default. Accept the default and enter the procedure name as C_NO_ENQUIRY

  2. To complete your program, add the other procedure as option 2. Press the <→>, select Link, accept the default option number 2 and enter C_NAME_ENQ as the procedure name

Finally, compile and run your program.


Lesson 8: Creating an Order Entry Program

This lesson describes how to create an order entry program having two interactive procedures. The first gets details of the order header and updates the ORDER_HEADER table. The second uses the Window access mode to display a list of existing ORDER_LINE records from which the user may select one for update. As order entry proceeds, the program totals the order line value into the order value and performs stock validation and adjustment and also checks that the customer does not exceed his credit limit.

· Creating the ORD_HEADER Procedure

· Creating the ORDER_LINE Procedure


Creating the ORD_HEADER Procedure

1. Specify a new data-entry program called MYPROG7

2. Add an interactive data entry procedure called ORD_HEADER to your program

3. For Main Table Processing, specify:

· ORDER_HEADER as the table to process

· the default Normal as the access mode

· the default Always offer scan as the search method

· the default Main Index as the search index

4. Generate parent checking; access is required to information from the CUSTOMER table. Ensure that the access mode is Check parent and that the search method is Scan if no match

5. Design the main screen like this:

where the fields are:

Number | Fieldname
1 | ORDER_NUMBER
2 | CUSTOMER_NUMBER
3 | NAME
4 | DELIVERY_DATE
5 | ADDRESS
7 | CREDIT_LIMIT
8 | BALANCE
10 | ORDER_DATE
11 | ORDER_TIME
12 | ORDER_VALUE

Double-click on the map to bring up its properties and:

· make it a pop-up window

· tick the title bar box

· make the field layout 5 rows by 3 columns

6. Add an attachment field (field number 102) in the bottom left-hand corner. This is where a map showing order lines will be displayed by the other procedure.

7. The screen colours can be chosen for each control by double clicking on the particular control, choosing the Colour tab in the menu bar and clicking on the colour scheme drop down arrow. A list of schemes is presented which define the attributes for the control, these can be altered using the colour scheme editor which is located under the options selection in the menu bar.

Bring up the editor and select button as the type of control to change. Accept the defaults for a new scheme based on Button Controls (Default). You will notice by changing the type, the attributes for that control are shown below.
Buttons have face, face when active, button text and several more colours. On the right side of the dialog, there is a tabbed menu bar and below this several colours:
To change attribute colours, click on the attribute on the left and then on the chosen colour on the right. Your colour change will be reflected in the sample button shown at the bottom left corner of the dialog.
If you click on the DP4 tab on the right hand side, a list of colours appears; you can scroll through this using the arrow icons.
For example, to change the button face to yellow:

a) click on the face box

b) click on the DP4 tab

c) click on the right arrow until the screen which contains the yellow option appears, click on it and the sample button face will turn yellow.

8. In map properties, make sure that you set up 5 rows of 3 columns for the map. To display the map at the top of screen, which is the requirement, select the appropriate Output method option on the SCREEN DESIGN menu

9. For field processing, specify:

Step number | Input Field? | Table | Field
1 | Yes | ORDER_HEADER | ORDER_NUMBER
2 | Yes | ORDER_HEADER | CUSTOMER_NUMBER
3 | No | CUSTOMER | NAME
4 | Yes | ORDER_HEADER | DELIVERY_DATE
5 | No | CUSTOMER | ADDRESS[1..3]
6 | No | CUSTOMER | CREDIT_LIMIT
7 | No | CUSTOMER | BALANCE
8 | Yes | ORDER_HEADER | ORDER_DATE
9 | Yes | ORDER_HEADER | ORDER_TIME
10 | No | ORDER_HEADER | ORDER_VALUE


Creating the ORDER_LINE Procedure

1. Add an interactive procedure called ORDER_LINE to your program

2. For Main Table Processing, specify:

· ORDER_LINE as the table to process

· Window as the access mode

· Main Index as the access index

Window access mode offers the user a menu of existing records to scroll up and down with the ability to append new records. You may remember that in Lesson 4, you used the multiple choice method to present a window of possible region codes. With window access, the key need not be entered to display the window. The window appears immediately and remains on screen for the duration of the procedure
Confirm that the Main Table Processing screen is filled out in this way:

[screenshot goes here]

3. Having selected the Window access method, you need to provide the map to display the list of choices, as follows:

Add:

· eight local fields (number 1 to 8) to display the order lines

· field number 100 (shown as an attachment field above) to enable a scroll bar for use with orders having more than eight order lines
Note: It is a good idea at this stage to set up only the first of the local fields, to an arbitrary size, and with the field labels only roughly positioned. Save it and quit map 2 and continue with your program set up. Later, when you have finished map 3, return to map 2, open map 3 as well for comparison purposes, and accurate size your local field to match the contents of map 3. When this is done, you can generate local fields 2 to 8 quickly and easily using Cut and Paste. Final positioning of the labels is best carried out when the program is being tested and there is visible data in the fields.

4. Set up the rows and columns on the map properties dialog, but to prevent the user from moving the cursor to field 100; don’t include it in your calculation of the number of rows

5. Define the map to display the items, as follows:

where the fields for the map are database fields as follows:

Field | Name
1 | LINE
2 | MATERIAL_CODE
3 | DESCRIPTION
4 | PRICE
5 | QUANTITY
6 | LINE_VALUE

You should size the fields to accommodate the maximum size of the data type specified.

6. Generate parent checking; access is required to information from the CUSTOMER table. Ensure that the access mode is Join parent, that Update table is set to yes and that the search method is Scan if no match

7. You’ve provided the maps that define the window, but you want to be able to edit the record selected directly in the window. You must, therefore, use the Map to display item in list as the main map. The main SCREEN DESIGN menu is specified with the following options:

Option | Choice | Description
Main map | 3 | Where 5 is the map created previously to display the items
Output method | Attached | Displays the main map within another map
Attach to map | 2 | Displays the main map within the choice list
Field | 0 | Entering 0 when you have selected window access, attaches the main map to the currently selected field in the choice list

Processing the Fields

Field processing for the ORDER_LINE procedure is quite involved. You must set it up so that the following sequence of events is executed:

1. The user enters the ORDER_LINE.LINE and ORDER_LINE.MATERIAL_CODE
QA Build displays the MATERIAL.DESCRIPTION and MATERIAL.PRICE

2. The user enters the ORDER_LINE.QUANTITY. QA Build performs these validations:
ORDER_LINE.QUANTITY must be less than or equal to the MATERIAL.QUANTITY.IN_STOCK
ORDER_LINE.QUANTITY must not be so large as to cause the customer to exceed the CUSTOMER.CREDIT_LIMIT

3. If both conditions are satisfied, QA Build updates the stock level by subtracting ORDER_LINE.QUANTITY from MATERIAL.QUANTITY.IN_STOCK

4. QA Build calculates and displays the ORDER_LINE.LINE_VALUE and totals it into the ORDER_HEADER.ORDER_VALUE

5. QA Build updates the customer’s balance by adding the ORDER_HEADER.ORDER_VALUE to the CUSTOMER.BALANCE

Choose the automatic field generation option, and then ensure that only the ORDER_LINE.LINE, ORDER_LINE.MATERIAL_CODE and ORDER_LINE.QUANTITY are set up as input fields.

Validating the Quantity Ordered

The requirement is that the quantity ordered is validated in two ways. Firstly:

ORDER_LINE.QUANTITY <= MATERIAL.QUANTITY.IN_STOCK

together with a message, if the validation fails, of the type: Insufficient Stock

Secondly, the user must not be able to enter any quantity that would put the customers over the credit limit. The value of the order line is:

MATERIAL.PRICE * ORDER_LINE.QUANTITY

so a possible validation is:

MATERIAL.PRICE * QUANTITY <= CUSTOMER.CREDIT_LIMIT

But this does not take account of the customer’s outstanding balance or other lines contributing to the order. The CUSTOMER.BALANCE field is going to be updated to include the value of order lines as they are entered, but doesn’t include the current order line value. So, the full validation condition is:

(MATERIAL.PRICE * QUANTITY) + CUSTOMER.BALANCE <= CUSTOMER.CREDIT_LIMIT

To enter the two-part validation:

1. Select the field processing for ORDER_LINE.QUANTITY. Move the cursor to Validation condition; the default is None

2. [???] Press <Space> to see the Formula editing menu, select Option 7 - Edit formula/condition

3. Type the first validation condition as:
ORDER_LINE.QUANTITY <= MATERIAL.QUANTITY.IN_STOCK

4. Highlight the option Remark on failure. QA Build can output a message if the condition is not met. Select Edit message to accept the proposed message number and to enter the Map Editor

5. [???] Select Edit in the Map Editor main menu, and type: Insufficient Stock

6. Save the message map and leave the Map Editor.

7. You are returned to the window where you typed the condition. Three questions remain, which should be answered as follows:

Question | Choice | Description
Warning only ? | No | If Warning only ? is Yes the user may decide to ignore the validation message after entering an invalid value
More ? | Yes | There are two validation conditions. The benefit of separating the conditions is that each can be given its own validation message
Continue on failure ? | Yes | This forces QA Build to evaluate the second condition even if the first fails

8. Type the second validation condition as:

(MATERIAL.PRICE * ORDER_LINE.QUANTITY) + CUSTOMER.ORDER_HEADER.BALANCE._ <= CUSTOMER.ORDER_HEADER.CREDIT_LIMIT._

Note that ORDER_HEADER must be inserted as a role, because when the Program Editor automatically generated the parent checking, it selected ORDER_HEADER (the key) as the default identifying role for the CUSTOMER table.

Note that whenever a field is identified in a formula, to avoid ambiguity the following should be specified in full:

table_name.identifying_role.field_name.identifying_role

If, as often, the field has no identifying role, it should be indicated by an underscore character, thus:

table_name.identifying_role.field_name._

In practice the underscore is often omitted, but this is deprecated.

9. Now create a suitable validation failure message, make it a warning only, and answer No to More ? to return to the field processing screen

Updating the Order Value

As order lines are entered, the user wants to see the running total order value displayed on the screen. This requires three actions:

· In the ORD_HEADER, set the ORDER_VALUE to zero but only for new orders

· In the ORDER_LINES procedure, set the LINE_VALUE with the formula:
MATERIAL.PRICE * ORDER_LINE.QUANTITY

· Total the field into the ORDER_VALUE field

To do this:

1. In the field processing for the ORD_HEADER procedure specify that the ORDER_VALUE field is not an input field and set up a new formula to calculate it. Insert 0 for the formula and answer No to the question Calculate always ?; this tells QA Build to use the formula only for new records

2. In the ORDER_LINES procedure, select the Totalling option in field editing for the LINE_VALUE field and set the following options:

Type of totalling | Update | This adds the change in value of the LINE_VALUE field to the field specified in Field name
Total in Type | Database |
Field name | ORDER_VALUE |
Table | ORDER_HEADER |

Select the defaults for the rest by pressing <Enter>.

3. Finally, we must set the ORDER_HEADER table to update in related table processing for the ORDER_LINE procedure. Go into Table Processing for the ORDER_LINE procedure and generate parent checking. Now, select the Related Tables option to see the list of the related tables. Those being processed are identified with an asterisk.

4. Use the cursor keys to move to the ORDER_HEADER entry and select Edit [???]. Ensure that the question Update table ? is answered Yes

The order line value is calculated after the price and quantity are entered. The order value in the order header is updated when the order line is saved.

Updating the Customer’s Order Balance

The CUSTOMER table has a field BALANCE, which is the total value of the outstanding orders for the customer. This field is used in the validation for the order line quantity and it must be updated as order lines are completed, to prevent complications with the validation conditions. This is done by including the field ORDER_VALUE in the ORDER_LINE procedure, as follows:

1. In the field processing list of the ORDER_LINE procedure, insert the ORDER_VALUE field after the LINE_VALUE field. You do not wish to display this field nor make it an input field, so select Mapfield 0. The ORDER_VALUE field does not require a formula as it is totalled into when the LINE_VALUE is processed

2. Select the Totalling option for the ORDER_VALUE field and update the ORDER_VALUE field into the BALANCE field.

Updating the Stock Quantity

The quantity in stock must be updated in the ORDER_LINES procedure. The field in question, QUANTITY.IN_STOCK is held in the parent table MATERIAL, so the program has to ensure that this table is updated along with the ORDER_LINE, ORDER_HEADER and CUSTOMER tables. Two actions need to be performed:

1. The quantity of the order line must be subtracted from the quantity in stock

2. The MATERIAL table must be updated
Subtracting the quantity ordered from the stock is similar to totalling the line value field, except that the quantity must be used to Downdate the stock quantity:
Processing for the related MATERIAL table has already been generated but you must edit it and answer Yes to the question Update table ?.
The program will now adjust the stock quantities on the MATERIAL table.

Running and Testing the Program

You should compile and test your program to see that it is working properly. Test the validation condition that prevents order lines being entered when there is insufficient stock to satisfy the quantity ordered. Also test the second part of the validation condition that prevents order lines being entered that would cause customers to exceed their credit limits.