HP 3000 Manuals

ORDERS Database Model Program (Continued) [ TurboIMAGE/XL Database Management System Reference Manual ] MPE/iX 5.5 Documentation


TurboIMAGE/XL Database Management System Reference Manual

ORDERS Database Model Program (Continued) 

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

Closing the Database 

     (USER SELECTS 12 TO CLOSE THE DATABASE)

     ROUTINE:  Close_The_Database

     *    OBJECTIVE:  This routine closes the ORDERS database by calling
     *                the DBCLOSE intrinsic.
     *
     *    ACCESS:     Mode 1 - Shared Modify Access
     *
     *    CALLED BY:  Main Line
     *
     *    CALLS:      DBCLOSE in mode 1 (close)

     BEGIN ROUTINE

          CALL DBCLOSE (DBname, Not_Used_Parm, Mode1_Close, Status)

               ERROR CHECKING

     END ROUTINE

C 

This section shows, in C, portions of the model program presented at the
beginning of this chapter.  The examples perform specific tasks to
illustrate the use of TurboIMAGE/XL intrinsics.  The C example does not
illustrate everything in the COBOL example.  Some blocks of code may be
appropriate only if expanded to a full program.

Data items are defined at the beginning of the sample program.
TurboIMAGE/XL intrinsics must be declared for C as external procedures.
The procedure name is identified by the word "Intrinsic."

Type declarations declare names for data structure forms that will be
used in allocating variables.  Variable declarations allocate the
variables of the program.  Variables are defined with precise types or
forms.  C string literals are delimited with double quotation marks ("
").  Field and record names are separated with a dot (.)  when referenced
(for example, base_name.baseid).


NOTE Because the Schema Processor, DBSCHEMA, upshifts alphabetic characters, programs must specify data set and data item names in all uppercase characters. Take note of this because C does not require that you use uppercase characters.
For information on TurboIMAGE/XL data item lengths and type designators, refer to chapter 3. Tables 3-2 and 3-3 show the TurboIMAGE/XL type designators, sub-item lengths, and data types typically used to process them in C.
NOTE All parameters must be on halfword boundaries.
Defining Data Types, Variables, and Intrinsics. The following is part of the C example program; it defines type declarations, variable declarations, and TurboIMAGE/XL intrinsics. #pragma list off #include <stdio.h> #include <string.h> #include <stdlib.h> #pragma list on /* Define all TurboIMAGE/XL procedure calls that */ /* will be used in your application program */ #pragma intrinsic DBBEGIN, DBEND, DBOPEN, DBCLOSE, DBGET, DBPUT,DBFIND, DBINFO #pragma intrinsic DBEXPLAIN, DBERROR, DBDELETE, DBUPDATE, DBLOCK,DBUNLOCK /* Define all your TurboIMAGE/XL constants */ #define End_Of_Chain 15 /* For DBGET Mode 5 */ #define End_Of_Data_Set 11 /* For DBGET Mode 2 */ #define No_Chain_Head 17 /* For DBFIND */ #define No_Such_Entry 17 /* For DBGET Mode 7 */ #define Entry_Has_No_Data 17 /* For DBGET Mode 4 */ short DBname[6] Password[4] Sales_D_Set[4]; char *Purch_Date = "PURCH-DATE;", *Equal_Op = " =", *Item_List ="ACCOUNT,STOCK#,PRICE,TAX,TOTAL,PURCH-DATE;"; /* Define all your global variables. */ struct Database_Status_Type { short Condition; short Length; int Record_Number; int Chain_Count; int Back_Pointer; int Forward_Pointer; } Status; struct Sales_Data_Set_Type {int Account_Number; char Stock_Number[8]; int Price; int Tax; int Total; char Purch_Date[6]; }; struct Lock_Descriptor_Type {short Num_Of_Elements; short Length_Of_Descriptor; char Data_Set_Of_Descriptor[16]; char Data_Item_Of_Descriptor[16]; char Relop_For_Data_Item[2]; char Value_For_Data_Item[6]; }; short Mode; Main Body of Program. /* Beginning of the main program */ main() { /* Initialize the database and set information */ strcpy ((char *)DBname," ORDERS; "); strcpy ((char *)Password,"DO-ALL;"); strcpy ((char *)Sales_D_Set,"SALES;"); Open_The_Database(); Get_Sales_For_Date(); exit (0); } Obtaining Error Messages and Explanations. The following paragraph implements the GET-ERROR-AND-EXPLAIN routine of the sample program. This routine calls DBEXPLAIN and DBERROR. DBEXPLAIN interprets the contents of the status parameter and prints a message on $STDLIST. DBERROR returns a message in the ERROR-BUFFER, explaining the condition code returned by TurboIMAGE/XL. At the end the routine, users can choose to abort or continue the execution of this program. /* Beginning of subroutines */ Get_Error_And_Explain() { /* Access : Mode 1 - Shared Modified Access The Orders database was opened in mode 1 Called by: Open_The_Database Get_Sales_For_Date Get_A_Product_Record List_All_Customers Add_A_Product Update_A_Customer Delete_A_Product Rewind_Customer_Set Get_Data_Item_Info Close_The_Database Calls : DBERROR DBEXPLAIN */ short Error_Buffer[80]; short Error_Length; int Answer; DBERROR(&Status,Error_Buffer,&Error_Length); printf("-------------------------------------------\n"); printf("%.*s\n",Error_Length, (char *)Error_Buffer); printf("-------------------------------------------\n"); DBEXPLAIN(&Status); Answer=0; printf("---Enter, <1> to ABORT..., <2> to Continue >\n"); scanf("%d",&Answer); if (Answer != 1) printf(" Continuing .........\n"); else exit(0); }


MPE/iX 5.5 Documentation