HP 3000 Manuals

ORDERS Database Model Program [ TurboIMAGE/XL Database Management System Reference Manual ] MPE/iX 5.0 Documentation


TurboIMAGE/XL Database Management System Reference Manual

ORDERS Database Model Program 

Main Body of Program 

     BEGIN MAIN LINE

     *    OBJECTIVE:  The main line contains the logic of this application.
     *                It displays all functions, accepts a selection,
     *                then calls the appropriate routines.  The execution
     *                of this program stops after the database is closed.
     *
     *    ACCESS:     Not applicable.
     *
     *    CALLED BY:  Not applicable.
     *
     *    CALLS:      Open_The_Database
     *                Get_Sales_For_Date
     *                Get_A_Customer_Record
     *                Get_A_Product_Record
     *                List_All_Customers
     *                Add_A_Product
     *                Update_A_Customer
     *                Delete_A_Product
     *                Rewind_Customer_Set
     *                Get_Data_Item_Info
     *                Get_Error_And_Explain
     *                Close_The_Database

          START LOOP

               DISPLAY the list of functions

     (The following illustration depicts one way of displaying the list of
     functions for this program.)

[]
OBTAIN option <-- user input If option = 1 Then CALL Open_The_Database and RETURN If option = 2 Then CALL Get_Sales_For_Date and RETURN If option = 3 Then CALL Get_A_Customer_Record and RETURN If option = 4 Then CALL Get_A_Product_Record and RETURN If option = 5 Then CALL List_All_Customers and RETURN If option = 6 Then CALL Add_A_Product and RETURN If option = 7 Then CALL Update_A_Customer and RETURN If option = 8 Then CALL Delete_A_Product and RETURN If option = 9 Then CALL Rewind_Customer_Set and RETURN If option = 10 Then CALL Get_Data_Item_Info and RETURN If option = 11 Then CALL Get_Error_And_Explain and RETURN If option = 12 Then CALL Close_The_Database and RETURN EXIT LOOP if option = 12 END LOOP END MAIN LINE Opening the Database (USER SELECTS 1 TO OPEN THE DATABASE) ROUTINE: Open_The_Database * OBJECTIVE: This routine opens the ORDERS database in mode 1 * for this application. * * ACCESS: Mode 1 - Shared Modify Access (SMA) with locking required * * CALLED BY: Main Line * * CALLS: DBOPEN in mode 1 (SMA) BEGIN ROUTINE OBTAIN DBname <-- "__ORDERS;" OBTAIN Password <-- "DO-ALL;" CALL DBOPEN (DBname, Password, Mode1_SMA, Status) ERROR CHECKING END ROUTINE Retrieving All the Records on a Chain (with Item Level Locking) (USER SELECTS 2 TO RETRIEVE SALES DATA) ROUTINE: Get_Sales_For_Date * OBJECTIVE: This routine demonstrates chained access, forward chained * read, and data item locking. * * The routine retrieves all sales records generated * on a particular purchase date. The value for date is * provided by the user and is used as the search item. * Due to concurrency issues, a data item lock is acquired * on all sales records identified by the date. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBLOCK in mode 5 (unconditional) * DBFIND in mode 1 (chained access) * DBGET in mode 5 (forward chained read) * DBUNLOCK in mode 1 (unlock) BEGIN ROUTINE Sales_Buffer is made up of: Account Stock# Quantity Price Tax Total Purch-Date Deliv-Date Lock_Descriptor_Sales_Type is made up of: Length_Of_Descriptor Data_Set_Of_Descriptor Data_Item_Of_Descriptor Relative_Operator_For_Data_Item Value_For_Data_Item Lock_Descriptor_Sales_Array_Type is made up of: Number_Of_Elements Lock_Descriptor_Sales_Type (The following illustration shows the layout for a lock descriptor array formats after the actual values have been assigned. Note that the date is stored in YYMMDD format.)
[]
OBTAIN Number_Of_Elements <-- 1 OBTAIN Length_Of_Descriptor <-- 21 OBTAIN Data_Set_Of_Descriptor <-- "SALES;" OBTAIN Data_Item_Of_Descriptor <-- "PURCH-DATE;" OBTAIN Relative_Operator_For_Data_Item <-- "_=" OBTAIN Value_For_Data_Item <-- "881012" OBTAIN List <-- "@;" OBTAIN Search_Item_Name <-- "PURCH-DATE;" OBTAIN Search_Item_Value <-- "881012" CALL DBLOCK (DBname, Lock_Descriptor_Sales_Array_Type, Mode5_Unconditional, Status) ERROR CHECKING CALL DBFIND (DBname, Sales_Detail, Mode1_Chained_Read, Status, Search_Item_Name, Search_Item_Value) ERROR CHECKING START LOOP CALL DBGET (DBname, Sales_Detail, Mode5_Forward, Status, List, Sales_Buffer, Not_Used_Parm) ERROR CHECKING DISPLAY the Sales_Buffer ____________________________________________________________________ Account Stock# Quantity Price Tax Total Purch-Date Deliv-Date EXIT LOOP if end of chain END LOOP CALL DBUNLOCK (DBname, Lock_Desc_Array, Mode1_Unlock, Status) ERROR CHECKING END ROUTINE Retrieving a Data Entry Using a Record Number (USER SELECTS 3 TO RETRIEVE CUSTOMER DATA) ROUTINE: Get_A_Customer_Record * OBJECTIVE: This routine demonstrates directed access by retrieving * a customer record with a known record number. Note * that the record number is first obtained using a DBGET * call, which in this case is a calculated mode 7. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBGET in mode 7 (calculated read) * DBGET in mode 4 (directed read) BEGIN ROUTINE Customer_Buffer is made up of: Account Last-Name First-Name Initial Street-Address City State Zip Credit-Rating OBTAIN List <-- "@;" OBTAIN Key_Item_Value <-- 315578 CALL DBGET (DBname, Customer_Master, Mode7_Calculated, Status, List, Customer_Buffer, Key_Item_Value) ERROR CHECKING OBTAIN Record_Num <-- Status [element 3] CALL DBGET (DBname, Customer_Master, Mode4_Directed, Status, List, Customer_Buffer, Record_Num) ERROR CHECKING DISPLAY the Customer_Buffer ____________________________________________________________________ Account Last-Name First-Name Initial Street-Address City. . . END ROUTINE Retrieving Master Data Using a Key Value (USER SELECTS 4 TO RETRIEVE PRODUCT DATA) ROUTINE:Get_A_Product_Record * OBJECTIVE: This routine demonstrates calculated access by * retrieving a product record from a master data * set based on a user-defined key item value. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBGET in mode 7 (calculated read) BEGIN ROUTINE Product_Buffer is made up of: Stock# Description OBTAIN List <-- "@;" OBTAIN Key_Item_Value <-- "STK30040" CALL DBGET (DBname, Product_Master, Mode7_Calculated, Status, List, Product_Buffer, Key_Item_Value) ERROR CHECKING DISPLAY the Product_Buffer ____________________________________________________________________ Stock# Description END ROUTINE Retrieving Data Serially (with Set Level Locking) (USER SELECTS 5 TO RETRIEVE CUSTOMER DATA) ROUTINE: List_All_Customers * OBJECTIVE: This routine demonstrates serial access by listing * all customer records. For the sake of consistency, * the data set is locked for exclusive access, * then the data is read serially. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBLOCK in mode 3 (unconditional) * DBGET in mode 2 (forward read) * DBUNLOCK in mode 1 (unlock) BEGIN ROUTINE Customer_Buffer is made up of: Account Last-Name First-Name Initial Street-Address City State Zip Credit-Rating CALL DBLOCK (DBname, Customer_Master, Mode3_Unconditional, Status) ERROR CHECKING OBTAIN List <-- "Account, Last-Name, First-Name, Initial;" START LOOP CALL DBGET (DBname, Customer_Master, Mode2_Forward, Status, List, Customer_Buffer, Not_Used_Parm) ERROR CHECKING DISPLAY List ____________________________________________________________________ Account Last-Name First-Name Initial EXIT LOOP if first word of Status buffer <> 0 END LOOP CALL DBUNLOCK (DBname, Customer_Master, Mode1_Unlock, Status) ERROR CHECKING END ROUTINE Adding an Entry (USER SELECTS 6 TO DO A PUT) ROUTINE: Add_A_Product * OBJECTIVE: This routine adds one entry to the Product master data * set. After obtaining user input, the data set is locked * for exclusive access. A transaction starts, and * new values are added by a call to DBPUT. At the end * of the routine, the transaction is ended and locks * are released. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBLOCK in mode 3 (unconditional) * DBBEGIN in mode 1 (transaction begin) * DBPUT in mode 1 (put) * DBEND in mode 1 (transaction end) * DBUNLOCK in mode 1 (unlock) BEGIN ROUTINE Product_Buffer is made up of: Stock# Description OBTAIN Stock# <-- user input OBTAIN Description <-- user input OBTAIN List <-- "@;" CALL DBLOCK (DBname, Product_Master, Mode3_Unconditional, Status) ERROR CHECKING OBTAIN Text <-- "Add entry to Product set Begin__" OBTAIN Textlen <-- 16 CALL DBBEGIN (DBname, Text, Mode1_Xbegin, Status, TextLen) ERROR CHECKING CALL DBPUT (DBname, Product_Master, Mode1_Put, Status, List, Product_Buffer) ERROR CHECKING OBTAIN Text <-- "Add entry to Product set End" OBTAIN Textlen <-- 14 CALL DBEND (DBname, Text, Mode1_Xend, Status, Textlen) ERROR CHECKING CALL DBUNLOCK (DBname, Product_Master, Mode1_Unlock, Status) ERROR CHECKING END ROUTINE Updating an Entry (USER SELECTS 7 TO DO AN UPDATE) ROUTINE: Update_A_Customer * OBJECTIVE: This routine updates a customer record interactively. * Updating is achieved by using the key item value to * locate the proper entry. It then displays the contents * to be updated. * * To perform the actual update, a TurboIMAGE/XL * transaction is started. The entry is retrieved using * a re-read mode, and an item level lock is obtained using * the search value. A contents check of the new values * is done against the old values. If the contents have * changed, the user can choose to abort the process. Otherwise, * the transaction proceeds and the update takes place. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBGET in mode 7 (calculated) * DBLOCK in mode 5 (unconditional) * DBBEGIN in mode 1 (transaction begin) * DBGET in mode 1 (re-read) * DBUPDATE in mode 1 (update) * DBEND in mode 1 (transaction end) * DBUNLOCK in mode 1 (unlock) BEGIN ROUTINE Customer_Buffer, Customer_Buffer_New, and Customer_Buffer_Old are made up of: Account Last-Name First-Name Initial Street-Address City State Zip Credit-Rating Lock_Descriptor_Customer_Type is made up of: Length_Of_Descriptor Data_Set_Of_Descriptor Data_Item_Of_Descriptor Relative_Operator_For_Data_Item Value_For_Data_Item Lock_Descriptor_Customer_Array_Type is made up of: Number_Of_Elements Lock_Descriptor_Customer_Type OBTAIN List <-- "@;" OBTAIN Key_Item_Value <-- user input CALL DBGET (DBname, Customer_Master, Mode7_Calculated, Status, List, Customer_Buffer, Key_Item_Value) ERROR CHECKING Customer_Buffer_Old <-- Customer_Buffer DISPLAY Customer_Buffer OBTAIN Customer_Buffer_New <-- user input OBTAIN Number_Of_Elements <-- 1 OBTAIN Length_Of_Descriptor <-- 22 OBTAIN Data_Set_Of_Descriptor <-- "CUSTOMER;" OBTAIN Data_Item_Of_Descriptor <-- "ACCOUNT;" OBTAIN Relative_Operator_For_Data_Item <-- "_=" OBTAIN Value_For_Data_Item <-- Key_Item_Value CALL DBLOCK (DBname, Lock_Descriptor_Customer_Array_Type, Mode5_Unconditional, Status) ERROR CHECKING OBTAIN Text <-- "Update entry on Customer set Begin__" OBTAIN Textlen <-- 18 CALL DBBEGIN (DBname, Text, Mode1_Xbegin, Status, Textlen) ERROR CHECKING CALL DBGET (DBname, Customer_Master, Mode1_Reread, Status, List, Customer_Buffer, Not_Used_Parm) ERROR CHECKING If Customer_Buffer is the same as Customer_Buffer_Old Then continue Otherwise Let the user know that the entry has been modified by another user, end the transaction, and release the locks. CALL DBUPDATE (DBname, Customer_Master, Mode1_Update, Status, List, Customer_Buffer_New) ERROR CHECKING OBTAIN Text <-- "Update entry on Customer set End" OBTAIN Textlen <-- 16 CALL DBEND (DBname, Text, Mode1_Xend, Status, Textlen) ERROR CHECKING CALL DBUNLOCK (DBname, Customer_Master, Mode1_Unlock, Status) ERROR CHECKING END ROUTINE Deleting an Entry (USER SELECTS 8 TO DELETE AN ENTRY) ROUTINE: Delete_A_Product * OBJECTIVE: This routine deletes an entry from the Product master * data set. The entry is specified by its key item value. * Identifying the entry and deleting it are preceded by * calls to DBLOCK and DBBEGIN to obtain locks and to start * a new transaction. * * When the entry is located, the deletion of the record * at the current record pointer is done by a call to * DBDELETE. * * The completion of a transaction is achieved by a call * to DBEND, and outstanding locks on this data set are * released by a call to DBUNLOCK. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBLOCK in mode 3 (unconditional) * DBBEGIN in mode 1 (transaction begin) * DBGET in mode 7 (calculated read) * DBDELETE in mode 1 (delete) * DBEND in mode 1 (transaction end) * DBUNLOCK in mode 1 (unlock) BEGIN ROUTINE Product_Buffer is made up of: Stock# Description CALL DBLOCK (DBname, Product_Master, Mode3_Unconditional, Status) ERROR CHECKING OBTAIN List <-- "@;" OBTAIN Text <-- "Delete entry from Product set Begin_" OBTAIN Textlen <-- 18 OBTAIN Key_Item_Value <-- "STK30040" CALL DBBEGIN (DBname, Text, Mode1_Xbegin, Status, Textlen) ERROR CHECKING CALL DBGET (DBname, Product_Master, Mode7_Calculated, Status, List, Product_Buffer, Key_Item_Value) ERROR CHECKING CALL DBDELETE (DBname, Product_Master, Mode1_Delete, Status) ERROR CHECKING OBTAIN Text <-- "Delete entry from Product set End___" OBTAIN Textlen <-- 18 CALL DBEND (DBname, Text, Mode1_Xend, Status, Textlen) ERROR CHECKING CALL DBUNLOCK (DBname, Product_Master, Mode1_Unlock, Status) ERROR CHECKING END ROUTINE Rewinding a Data Set (USER SELECTS 9 TO REWIND A DATA SET) ROUTINE: Rewind_Customer_Set * OBJECTIVE: This routine rewinds the customer data set by calling * DBCLOSE in mode 2. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBCLOSE in mode 2 (rewind) BEGIN ROUTINE CALL DBCLOSE (DBname, Customer_Master, Mode2_Rewind, Status) ERROR CHECKING END ROUTINE Obtaining Database Information (USER SELECTS 10 TO OBTAIN INFORMATION ABOUT A DATA ITEM) ROUTINE: Get_Data_Item_Info * OBJECTIVE: This routine obtains information about a data item * by calling DBINFO in mode 102. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBINFO in mode 102 (item access) BEGIN ROUTINE DBINFO_Buffer is made up of: Data_Item_Name Data_Type Sub_Item_Length Sub_Item_Count OBTAIN Data_Item_Name <-- "PURCH-DATE;" CALL DBINFO (DBname, Data_Item_Name, Mode102_Item, Status, DBINFO_Buffer) ERROR CHECKING DISPLAY the DBINFO_Buffer ____________________________________________________________________ Data_Item_Name Data_Type Sub_Item_Length Sub_Item_Count END ROUTINE Obtaining Error Messages and Explanations (USER SELECTS 11 TO OBTAIN ERROR MESSAGES AND ADDITIONAL ERROR-RELATED INFORMATION) ROUTINE:Get_Error_And_Explain * OBJECTIVE: This routine generates an error message, corresponding * to the existing value in the first word of the status * parameter, by calling the DBERROR intrinsic. * Additionally, the routine generates a description * regarding the outstanding error message by calling the * DBEXPLAIN intrinsic. * * ACCESS: Mode 1 - Shared Modify Access * * CALLED BY: Main Line * * CALLS: DBERROR * DBEXPLAIN BEGIN ROUTINE Error_Buffer is made up of: Error_Message CALL DBERROR (Status, Error_Buffer, Error_Length) DISPLAY the Error_Buffer ____________________________________________________________________ Error_Message CALL DBEXPLAIN (Status) END ROUTINE


MPE/iX 5.0 Documentation