Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
PDS*BASE HIERARCHAL DATA BASE SYSTEM VERSION 3.2 FOR PC OR MS-DOS A PRODUCT OF PRO DEV SOFTWARE 545 GROVER ROAD MUSKEGON, MI 49442 Information in this document is subject to change without notice and does not represent a commitment on the part of PRO DEV Software. The disk containing the PDS*BASE software and this document was furnished free via various public domain methods of distribution. The software may be copied only in accordance with the instructions in the "README.DOC" file on the PDS*BASE MASTER DISK. The software and this documentation is copyrighted and can not be passed on in a modified version. Copyright PRO DEV Software 1985 LIMITED WARRANTY PRO DEV Software shall have no liability or responsibility to purchaser or to any other person or entity with respect to any liability, loss or damage caused by this product, including but not limited to any interruption of service, loss of business or anticipatory profits or consequential damages resulting from the use or operation of this product. Only the origional disks supplied by PRO DEV Software will be exchanged within six months from the date of purchase if defective in manufacture, labeling, or packaging, but except for such replacement the sale or subsequent use of this series of programs is without warranty or liability. THE ABOVE IS A LIMITED WARRANTY AND THE ONLY WARRANTY MADE BY PRO DEV SOFTWARE. ANY AND ALL WARRANTIES FOR MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY EXCLUDED. "IBM PC" and "PC-DOS" are registered trademarks of the IBM Corp. and "MS-DOS" is a registered trademark of the Microsoft Corp. SYSTEM REQUIREMENTS PDS*BASE requires at least 128k of RAM, MS or PC-DOS, BASIC, at least one disk drive and a printer. Page i PRO DEV SOFTWARE PDS*BASE DATA BASE SYSTEM FOREWORD The PRO DEV SOFTWARE PDS*BASE DATA BASE SYSTEM is a MASTER/DETAIL type of hierarchal and relational data base. It is also known as a MOTHER/DAUGHTER or MASTER/SLAVE type of data base. This type of data base is usually found on only Main Frame type of computers. Although there are other systems of this hierarchal nature on the market for small computers, most of them operate as machine language programs. Often they need a special language to allow the user to operate them. The PDS*BASE System consists of a series of program that create both a custom data base (with up to 10 BASIC language programs to operate with the custom Thus, the generated programs can be easily modified as generators files) and data base. desired. The PDS*BASE System can be operated by a user not conversant with the BASIC programming language, but, that user will not normally be able to take advantage of many of the advanced features. Thus, the PDS*BASE DATA BASE System is designed more for the person who is reasonably conversant with the BASIC language. A FEW WORDS ABOUT THE COPYRIGHT Most professional programmers are in business to make a profit on their labors. They expect to receive fair compensation for their efforts. It is the true professional that has sent funds to PRO DEV Software per the request in the menu program on the disk. The use of this system can save the average programmer the cost of this system on just the first data base project in man hours alone. Since it is likely that you will still charge your customer the same price for his data base system, even though we saved you all those hours, system with the first project. you will probably "pay" for this If, per chance, you are making extensive use of this system, and are feeling guilty about all of the profit you have made from it, PRO DEV Software stands ready to "forgive" you. We suggest a contribution of at least $39.95 (you will probably find it to be worth more - don't be shy). You will then be registered for future update notices. Our address is 545 Grover Road, Muskegon, Michigan 49442. If your PDS*BASE master disk copy is so many generations old that you don't trust it, or wish the latest version, let us know, and we will send you a new one for only another $10.00. be sure to specify PC/MS-DOS, as we also make an Apple II, IIe version. Page ii PDS*BASE DATA BASE SYSTEM VERSION 3.2 FOR PC OR MS-DOS TABLE OF CONTENTS Foreword .............................................ii 1. 2. Introduction & How To Use This Manual .................1 1.1 The PDS*BASE Data Base Specifications ............2 1.2 Structure of a Hierarchal Data Base ..............4 1.3 Typical Uses For a Hierarchal Data Base ..........8 GETTING A SYSTEM UP IN 1 HOUR 2.1 DBDEF PROGRAM To Define a Data Base ..............9 2.2 DBCREATE PROGRAM To Create the Blank Data Base ..13 2.3 DBOPSUB PROGRAM To Create Operational Subroutines ...........13 2.4 DBMANAGE PROGRAM To Create Management Program ...15 2.5 DBREPORT PROGRAM To Create Report Programs ......16 2.6 DBSORT PROGRAM To Create a Sort Program .........19 2.7 DBUTIL01 PROGRAM To Create a Maintenance Program.20 3.0 Example Inventory Control Data Base ..................21 3.1 Creating the Example Data Base ..................23 3.2 Sample Data Base Description List ...............24 3.3 Creating the Blank Data Base ....................25 3.4 Creating the Management Program .................26 3.5 Creating the Report Program .....................26 3.6 Creating the Sort Program .......................27 Page iii PDS*BASE DATA BASE SYSTEM VERSION 3.2 FOR PC OR MS-DOS TABLE OF CONTENTS (continued) 4.0 Description of the Operational Subroutines ...........28 4.1 Opening the Data Base Files .....................28 4.2 Closing the Data Base Files .....................29 4.3 Calculating the Random Access Number ............30 4.4 Reading a Record ................................31 4.5 Writing or Updating a Record ....................32 4.6 Creating a Master Record ........................33 4.7 Creating a Detail Record ........................34 4.8 Deleting a Master Record ........................35 4.9 Deleting a Detail Record ........................36 4.10 Transfer Input Data to Output Buffer ...........36 4.11 Locate Blank Position for Master Record .........36 5.0 Description of the Main Programs .....................38 5.1 Description of the Management Program ...........38 5.2 Description of the Report Program ...............41 5.3 Description of the Sort Program .................44 6.0 Program Hints and Modifications ......................47 6.1 Modifying the Definition File ...................47 6.2 Modifying the Operational Subroutines ...........50 6.3 Modifying the Management Program ................52 6.4 Modifying the Report Program ....................53 Page iv PDS*BASE DATA BASE SYSTEM VERSION 3.2 FOR PC OR MS-DOS TABLE OF CONTENTS (continued) 7.0 Doing Your Own Thing .................................54 7.1 Calculate A Master Record Number ................55 7.2 Direct Read A Selected Record ...................56 7.3 Update A Record Using The Y$ Buffer .............58 7.4 Upadte A Record Using The ZI$ Buffer ............58 7.5 Create A New Master Record ......................59 7.6 Create A New Detail Record ......................60 7.7 Delete A Selected Master Record .................61 7.8 Delete A Selected Detail Record .................62 APPENDIX A (Manage Program Listing) .......................A APPENDIX B (Report Program Listing) .......................B APPENDIX C (Sort Program Listing ) ........................C APPENDIX D (Step-By-Step Flow Chart) ......................D Page v Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 1.0 INTRODUCTION & HOW TO USE THIS MANUAL You have obtained one of the most unique data base systems on the market today for small computers. It is written in BASIC. (GASP!!) It also didn't cost you $499, $409, $229 or $209. If you wish to jump right into creating your first data base, skim the introduction and follow the instructions in Section 2. If you are hesitant to "Go It" on your own, skim the introduction, briefly read Section 2 and carefully follow the Step-By-Step instructions for creating and using the Example Inventory Data Base described in Section 3. After that, go back to Section 2 and try your own "custom" data base. When you have gained confidence with creating your own data base, Sections 4 and 5 will show you just how it works. We hide nothing! Section 6 will show you how to add just several lines to your programs to greatly increase your power to "get the job done". Section 7 will show you how to merge the PDS*BASE with your own custom style of programming. Most data base systems have the operational subroutines (the routines that operate upon the data base to add, delete, update and read information) hidden in protected machine language coding. After all - a data base is a magical concept to be understood only by graduates of the Peek & Poke School of Advanced Programming. Further, most systems suggest that the use of the BASIC programming language is slumming. If you are a beginning programmer for small computers, what language do you use? If you are a professional programmer for small computers, what language do you use for many of your programs? Both answers are probably BASIC. It's a good language that is used for thousands of programs on the market today, and is easily transferrable from one small computer to another with very few modifications. Most other data base systems on the market can't be operated upon from within a BASIC program; it is necessary to invent a "HIGH LEVEL" language. We agree on the "HIGH" as it does take a HIGH level of patience to learn (Oh no not another) language. First we had to learn machine language. Then we learned COBAL, RPG, FORTRAN, BASIC, PASCAL, LOGO, C, etc., etc. Now we need to learn another language. Well, this data base designer has had ENOUGH!!!! PAGE 1 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 Then, since you certainly can't require all of those complex commands to be entered every time you want to post another invoice in your data base, it is necessary to set up "DO" files of commands. These "DO" files are often as long as if you had written the program in BASIC in the first place. What happened to the good old days when all you had to do was enter RUN "INVPOST" (or just INVPOST if the program is compiled) and the computer would take over and run the program that handled invoice posting to your data base? "Ah!" you say... Those good old days before canned data base systems caused you to burn quarts of midnight oil to get just the first program up and running. "Ye of little faith" we reply... We need the best of both worlds. We need a highly sophisticated data base system that runs in BASIC; communicates with the data base with easy to call subroutines; uses straightforward BASIC main programs that can be understood and modified to meet the boss's "what-if" questions, and that YOU CAN PROBABLY GET UP AND RUNNING IN LESS THAN 1 (ONE!) HOUR. This is all done by several program generators that produce your finished programs. The concept of program generators is not new, but we think that you will like the power and convenience of the PRO DEV SOFTWARE PDS*BASE system. 1.1 The PDS*BASE SPECIFICATIONS 1.1.1 FILE QUANTITIES The PDS*BASE data base allows up to 10 files to be open at one time (this assumes that your computer will allow that many files open at one time and that you have a proper CONFIG.SYS file). 1.1.2 RECORDS PER FILE Each of up to 10 files is limited to 32,768 records, or 327,680 records for a 10 file data base. These are the PDS*BASE program limits. It is a good idea to use as the number of records a prime number. Program PRIMES.BAS will give you the next higher prime number. However, the actual limiting factor is the amount of disk capacity on your system or BASIC memory available for report sorts. An IBM PC, allows you to have 362,496 characters of storage on one double sided 5 1/4 inch disk. It is possible to have a file span any number of disk drives. The DBDEF program (used to define your data base) gives you a running account of the disk capacity used for each file, and the total sectors used by all files. PAGE 2 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 1.1.3 FIELD LENGTH = 255 Characters 1.1.4 NUMBER OF FIELDS PER RECORD There is no particular limit to the number of fields, except for the aproximately 1000 character record limit described below. 1.1.5 RECORD LENGTH On the PC or MS-DOS computer there is no record length limit, as it will allow a record to occupy more than one 512 character sector. However, statements 330 and 331 in the generated programs limit you to about 1000 characters per record. If you wish more, just expand these field statements. 1.1.6 RANDOM ACCESS - TRUE The PDS*BASE data base system uses a calculated record formula to determine the exact desired record location for master records. The length of the search string can be up to 255 characters long. For optimum randomization the search string length should not exceed 1/20th of the maximum number of records in a file. For example, with a file limit of 300 records, the search string length can be up to 15 characters. Longer search strings will cause slower creation of new records. If you are familiar with various methods of random access, the PDS*BASE system uses the "hashing" method of calculating the record location. This method is FAST at reading records. Hashing will be completely described in section 4.3. However, all good things have a drawback. When creating new records, and when the data base becomes approximately 80% full, one may run into situations where the same address has been calculated for different search field values. Using a prime number for the total number of records for a master file helps hold this problem down. The system will need to search for a blank location to store the new record. As the data base reaches 100% occupancy, this search time will increase. This normally will not be a problem if you apply a 20% safety factor when designing your data base. There will be no problem READING the records, even at 100% occupancy, as pointers will lead to the desired record. PAGE 3 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 1.2 STRUCTURE OF A HIERARCHAL DATA BASE The PRO DEV PDS*BASE type of MASTER/DETAIL hierarchal data base consists of two types of data sets or files. There are Master files that are randomly accessed, and Detail files that are accessed via a specific record in a Master file. Further, the number of records in a file are fixed at the time the data base is defined. You should never get a "DISK FULL" message. Rather, you will get a program warning that will not crash the system. The via records in a Master file can be read immediately, random access, given a valid value for the search field. A Master record must have a unique search field value. You may NOT have more than one record in a file with the same search field value. When creating Master records, the PDS*BASE system will display an error message if a record with the same search field value already exists. The header of a Master contains the values of the "chain head" and "chain end" for up to nine (9) Detail sets. Detail files are NOT random access files. They are like fixed length sequential files. They are accessed by a record number and are direct access files. The desired record number is not calculated upon a search value as is a Master in a Master set. It takes the value found in the associated Master record to find the first record in a chain of one or more Detail records. Each Detail record contains a forward (to the next) record pointer and a backward (to the previous) record pointer in the Detail chain for a particular Master record. Confused? - Let's use a simple example to clarify the relationship of the Detail and Master records. Suppose that we have a simple inventory control system. We will have a Master record for each part in the inventory. The search field will be the "PART NUMBER". Thus, we will have a unique random accessed record for each part in our inventory. The Master record may also contain the "DESCRIPTION", "SUPPLIER", "MAXIMUM", "MINIMUM", etc. The next page shows a pictorial representation of this example data base. PAGE 4 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 FIGURE 1 EXAMPLE OF MASTER/DETAIL HIERARCHAL DATA BASE INVENTORY CONTROL SYSTEM ****** This page is blank, as it is impossible to ****** ****** reproduce the drawings on a disk file. ****** ****** When you send your Registration to PRO DEV ****** ****** This page will be mailed to you. ****** PAGE 5 Version 1.2 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 STRUCTURE OF A HIERARCHAL DATA BASE (continued) The boss wants to keep a record of parts on order, parts received and parts used. He/she also wants to keep track of purchase order numbers, requisitions, etc., for each transaction for each part. If we had to keep a big enough Master record for all of the possible transactions for each part, this record would be very large. Also, some parts would probably have very little activity and all of this reserved space would be wasted. It would not be possible to fit very many of these records on a disk due to the large size of each record. With a Hierarchal data base we will have one Master disk file for the part Masters, and three separate Detail disk files for (1) the parts on order, (2) the parts received and (3) the parts used. Each parts Master in the Master file will have three Detail set chain head pointers and three chain end pointers ahead of the actual data in the record. When a Master record is created, all of the associated Detail file pointers are set to zero (no Detail records yet). When the Purchasing clerk places the first order for part number "XYZ", the PDS*BASE system will ask for the Master part number. This record will be read to find any existing Detail chain pointers. Then, data is requested for the purchase order Detail record. If this is the first purchase order Detail record for part "XYZ" the chain head and chain end values for the purchase order Detail set will be set to the value of this new Detail record. The Master part record will be updated to contain these pointers and the Detail record is created (or written) to the Detail file. If there are one or more existing Detail purchase order records for part "XYZ", the chain head and chain end pointers in the Master record will not be zero. Thus, the chain end in the Master will be updated to indicate the new chain end. The former Detail record that was the chain end will be updated to have it's forward pointer set to the record number for the new Detail record. The backward pointer for the new Detail record will be set to the record number of the former chain end Detail record. The forward pointer for the chain end Detail record becomes zero, and the backward pointer for the first Detail record in a chain will be set to zero. PAGE 6 Version 1.2 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 STRUCTURE OF A HIERARCHAL DATA BASE (continued) Different purchase order Detail records for part "XYZ" will be added over time. Meanwhile, purchase order Details for other parts may also have been added. This will tend to "scatter" the Detail records for a particular part throughout the Detail disk file. The forward and backward pointers will tie the scattered records into a cohesive and continous chain when it is necessary to search the chain associated with a Master in the associated Master set. If you have been following the preceding example, and if you write inventory programs, and if the accountants are blowing "FIFO, FIFO" in your ear, you may have discovered that if you carry unit costs with each parts received Detail record, then Pro Dev Software has just given you a First-In First-Out system at no extra cost. The Detail chains will always be read in a First In, First Out order. The Detail sets need only to be sized for the AVERAGE number of Details for the Master record, plus a safety factor. Thus, the average quantity of purchase orders for all parts may be 20 per year per part for the above example. Some part Masters may have no Detail records and others may have many, as long as YOUR defined capacity for the Detail set is not exceeded. An extreme case would be to have one part Master using all possible records in a Detail set and all of the other part Masters having no Detail records. Not too likely. However, as you can see, a MASTER/DETAIL (sometimes referred to as a MOTHER/DAUGHTER) hierarchal data base is very dynamic as it is being used. The PDS*BASE system keeps track of all of the pointers for you. Normally, they are of interest only in special cases when you wish to test for chain head or end of a Detail set. The record pointers do take record space, and this is the drawback of a MASTER/DETAIL hierarchal data base. However, the elimination of blank space reserved for data that "may" be needed usually far outweighs the space used by the pointers. The random access speed of the PDS*BASE data base is incredible, even when running in uncompiled BASIC. If you are sorting the data base (you don't actually sort the records - just the order of reading records), you may want to compile the BASIC program with a BASIC compiler such as Microsoft's QuickBasic. PAGE 7 Version 1.3 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 TYPICAL USES FOR A HIERARCHAL DATA BASE 1.3.1 Inventory Systems as described in Section 1.2. 1.3.2 Payroll - Master file for employees with Detail files for weekly information. 1.3.3 Work with etc. in Progress System - Master file for jobs Detail files for direct labor, parts used, 1.3.4 Quotation System - Master for Quote Numbers and Detail files for parts and labor units used for the quote. (PRO DEV Software has issued such a system to the Public Domain). 1.3.5 Library Inventory 1.3.6 Job Control System - Each job is a Master and Detail files can be for budget information, actual cost information, critical dates, etc. 1.3.7 Customer Accounts - Master set for customers with Detail sets for items purchased, amounts invoiced, amounts paid by the customers. 1.3.8 You dream it up - you can probably do it with a hierarchal/relational data base. A random accessed Master set does not necessarily need Detail sets. They can stand alone. PAGE 8 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 2.0 GETTING A SYSTEM UP IN ONE HOUR. BEFORE YOU START - MAKE A BACK-UP COPY OF YOUR PDS*BASE MASTER DISK PER THE INSTRUCTIONS IN THE README.DOC FILE (this is an unprotected system). ALSO, HAVE A SUPPLY OF FORMATTED DISKS TO STORE YOUR DEFINITION FILES, GENERATED PROGRAMS AND DATA FILES. YOU SHOULD HAVE A PRINTER CONNECTED TO THE "LPT1" PORT. YOU MAY HAVE TO TRANSFER THE PDS*BASE FILES TO A DISK WITH THE PROPER DOS AND BASIC INTERPETER FOR YOUR HARDWARE. THE ORIGIONAL PDS*BASE DISKS WERE SHIPPED FORMATTED UNDER PC-DOS 2.1 (9 SECTORS/TRACK). This Section will allow you to define your custom data base. You may wish to follow the step by step example in Section 3 if this section is not completely clear to you. 2.1 DBDEF PROGRAM The first thing to be done when creating a data base is to list, on a sheet of paper, all of the desired files and the field names. It may help to sketch the files as shown in Figure 1 on page 5. This way, you can work out the MASTER/DETAIL relationships before running the DBDEF program. You should also run the PRIMES.BAS program to find the next higher prime number for the number of records for master files. You should give each file a name with a maximum of 8 characters. The DBDEF program will add a ".DAT" extender. Next, give each field a name. The field names can be up to 30 characters long; however, keep them short. These field names will be automatically used in the generated programs. Long names will give you funny looking screens. Also, the DBREPORT program (Section 2.5) will automatically use these field names for the column headings. Insert the PDS*BASE back-up copy master in disk drive "A". Run the DBDEF program each time you wish to create a new data base system. The DBDEF program is a question and answer program that allows you to completely define your custom data base. The questions are as follows: 2.1.1 HOW MANY DISK DRIVES? Enter the number of disk drives (both 5 1/4" and hard disk) on the computer that the system will run on. PAGE 9 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 2.1.2 FILE TYPE MENU Option 1 = Define Master File (Sec. 2.1.3) Option 2 = Define Detail File (Sec. 2.1.4) Option 3 = Finished Defining (Sec. 2.1.5) 2.1.3 DEFINING A MASTER FILE (OPTION 1) The Master file (that has Detail files) must be defined before its Detail files. Step 1 - Enter the name of the file (up to 8 characters). Next, enter the number of associated Detail files, if any. Step 2 - You will be asked for the information for each field. THE FIRST FIELD OF A MASTER FILE IS ALWAYS THE SEARCH FIELD (for random access). Enter the following information: Field Name - Keep it short, but descriptive. Limit=30 characters. Imbedded blanks allowed. DO NOT USE ANY COMMAS. Maximum Number Of Characters (or field size) Limit=255 characters (screens look funny beyond 79) Required or Optional Field - The 1st field of a Master file is automatically required. If a field is specified as required, then the program generated by the DBMANAGE program (Sec. 2.4) will insist that data be entered. Field Type - Integer (no alpha, no decimal point); Real (decimal allowed, no alpha); or Character (alpha/numeric). When you have finished defining fields for a master, just depress the Return key when asked for the next field name. Step 3 - You will be asked for the required number of total records for the file. It should be a prime number, if possible (program PRIMES.BAS will calculate it for you). Since this is a Master file that is random accessed by the hashing method, specify about 20% more records than necessary, if possible. PAGE 10 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 2.1.3 DEFINING A MASTER FILE (OPTION 1 - continued) If you have defined a Master file, the DBDEF program will save room on the disk for a sort file. The DBREPORT and DBSORT programs will sort a Master file. Actually, they don't sort the records, they just create a sorted list of the record numbers, sorted by the first field (or combination of any fields with the DBSORT program). The sort key files are used by report programs so the records will be read in a sorted order. The key file will automatically be re-created if Master records are added or deleted. The memory limit of BASIC may only allow several thousand records to be sorted, depending on the size of the search string. At this time, you will be informed how many disk sectors were needed for this file, and how many total have been used so far. 2.1.4 DEFINING A DETAIL FILE (OPTION 2) Step 1 - Enter the name of the Detail file (up to 8 character limit). Step 2 - Enter the name of the associated Master file. This is VERY important as it takes the pointers in a particular Master file record to find the Detail file records. You MUST have previously defined the Master file. Step 3 - You will be asked for the information for each field for the Detail field as follows: Field Name - Keep it short, but descriptive. Limit=30 characters. Imbedded blanks allowed. DO NOT USE ANY COMMAS. Maximum Number of Characters (field size) Limit=255 characters. Required or Optional Field. Even the first field in a Detail set can be optional. Field Type - Integer, Real or Character. Again, when you are done, depress Return when asked for the next field name. PAGE 11 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 2.1.3 DEFINING A DETAIL FILE (OPTION 2 - continued) Step 4 - Specify the desired number of total records. Since hashing is NOT used on a Detail file, the safety factor need not be as high as 20%. You will NOT be asked if you wish to reserve room for a sort file for a Detail set. IT IS NOT POSSIBLE TO SORT A DETAIL SET. Keep in mind, a Detail is accessed via its associated Master records. Thus, if a sort is desired, the Master set will have a sort key file. You will again be advised of the number of sectors required for the Detail file, and how many sectors have been used so far. 2.1.5 DATA BASE DESCRIPTION LIST (Option 3) After each file is defined, you will be taken back to the File Type Menu (paragraph 2.1.2). When you have defined the last Master or Detail file, enter option 3. At this point you will be asked for a data base name. No more than 8 characters can be used. This name will be used for the Definition File name (".DEF" will automatically be appended). After several logic checks and file location calculations, the DBDEF program will print a Data Base Description Listing. This list will give you a record of where each file is located and how many sectors are required. Then, a File and Field List will be printed. This should be retained as it will be needed to help run the DBREPORT program generator. 2.1.6 DEFINITION FILE The Definition File will be written to disk. It is suggested that you use the disk that will contain your generated programs. The Definition File is used as input by ALL of the other programs on the PDS*BASE master disk. It is a compact and complete definition of your data base. If you define several data bases on the same disk BE SURE TO GIVE THEM DIFFERENT NAMES. See Section listing. 6.1 for a sample Definition File PAGE 12 Version 3.2 2.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBCREATE PROGRAM The Data Base Description List indicated how many disks will be required for the system. Prepare that number of formatted disks (without DOS) and have them at hand. You will probably only need one disk. If multiple disks are required, you should consider a hard disk computer to run your data base system. Insert your PDS*BASE Master disk copy in disk drive "A" and run the DBCREATE program. It will ask you to insert your program disk (containing the Definition File - See Sec. 2.1.6) and to enter the name of the Definition File. The DBCREATE program reads the Definition prepares to create a blank data base. File and You will be prompted to insert the formatted disk(s) into the appropriate disk drive(s). The DBCREATE program will then create an empty data base. A message will be given at the start of creating each file. It is necessary that blank records (and their pointers) be created before any of the generated programs can be run. You cannot run a program using a disk that has only been formatted. It is a good idea to make a back-up copy of the blank data base disks. It will save time if a blank data base is desired at a later date. Use COPY *.* or the DISKCOPY program on your computer's DOS master disk to make back-up copies. To protect your valuable records you should make daily back-up copies of your data base disks as data is added, updated or deleted. If there is a power failure during a session, you may loose some records. 2.3 DBOPSUB PROGRAM You are now ready to start creating programs to run your data base. EACH of your programs MUST start with the Operational Subroutines. The DBOPSUB program generator will create program lines 10 through 2000 in all programs. PAGE 13 Version 3.2 2.3 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBOPSUB PROGRAM (continued) The Operational Subroutines open and close the data base files. They add, read, update and delete both Master and Detail records. They automatically create and keep track of all of the record pointers. They calculate the record numbers for random access to master records. The DBOPSUB program does all of the work to create the subroutines that run your data base. The creation of these subroutines could take hundreds of hours to create manually. It is this manual proceedure that causes many programmers to purchase "canned" data base systems. With DBOPSUB you can have a "custom" system prepared in minutes. Step 1 - You will be asked which program you will be creating. This allows the DBOPSUB program to know which operational subroutines will be necessary. BE SURE TO RUN DBOPSUB FOR EACH PROGRAM. Don't merge the subroutines from one program to another. For instance, if you use the DBMANAGE subroutines for the DBREPORT programs, you will be missing the DIMension statement for the ZN$ array. At this point, be sure that your program disk (that contains the Definition File) is inserted in drive "A". If you wish to use drive "B" for the disk with the definition file, preceed the file name with "B:". When prompted, enter the Definition File name. After the Definition File has been read, the DBOPSUB program will ask if you wish to have drive letters included as part of the file names in the generated program. If you wish all files on drive "A" or you are writing the program for a hard disk system, you should answer "N". The DBOPSUB program generator (as well as the other generators) will create an ASCII file on your program disk containing your program. Then the DBMANAGE, DBREPORT and DBSORT program generators append to the ASCII file created by the DBOPSUB program. After the ASCII file has been appended by a "Main Program" generator, you only need to type the command LOAD" followed by the name of your ASCII program file, followed by depressing the RETURN key. The ASCII file created by the program generators will be loaded into memory as a BASIC program. Then SAVE the BASIC program on a disk with an appropriate program name (this saves it in the more compact tokenized version). This proceedure will be described in more detail later. PAGE 14 Version 3.2 2.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBOPSUB PROGRAM (continued) Step 3 - Enter the PROGRAM File name (preceed with "B:" if you wish to use drive "B"). USE A NAME DIFFERENT FROM YOUR DEFINITION FILE NAME. Failure to use a new name will wipe out your Definition File. The program will now be written to the disk. 2.4 DBMANAGE PROGRAM The DBMANAGE program generator writes the "Main Program" to create, update or delete records in your custom data base. HOWEVER, YOU MUST ALREADY HAVE CREATED AN ASCII PROGRAM FILE THAT CONTAINS THE CORRECT OPERATIONAL SUBROUTINES. Thus, you should have previously run the DBOPSUB program generator to create the "Front End" of your "Management" program. The DBMANAGE program generator appends lines starting at 2010 to the Operational Subroutine file. Step 1 - Insert the PDS*BASE Master disk copy in drive "A" and run DBMANAGE. You will be asked for the name of the Definition File. Preceed with "B:" if you wish to use drive B for the definition file disk. Step 2 Replace the PDS*BASE Master disk (if necessary) with your program disk (containing the Definition File). Enter the name of the Definition File and depress the Return key. Step 3 - After the Definition File has been read, you will be prompted for the ASCII program file name (of the file containing the Operational Subroutines). Enter the file name and depress Return. Then your "Main Program" will be added to the end of the program file. Step 4 - When the DBMANAGE program generator is done, just type in the command LOAD" followed by your ASCII program file name and depress the Return key. Your complete program will be loaded from the ASCII file into memory as a BASIC program. Step 5 - SAVE your new program on your program disk. Now, since your program is still in memory - type RUN. The and for Then program will prompt you to insert the data disk(s) to depress any key. The disk drive(s) will turn on a short period of time while the files are opened. you will see the MAIN MENU for your program. PAGE 15 Version 3.2 2.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBMANAGE PROGRAM (continued) Just follow the instructions. Notice that all of the file and field names have appeared in your program. Since the file names are limited to 8 characters and have a ".DAT" extender, you will probably wish to modify the program lines starting at line 2021 to make them more people frendly. You can create (A option), read or update (M option) or delete (D option) any records that you wish. To end the program, just depress RETURN when the MAIN MENU is on the screen. The disk drive(s) again come on for a short time to close the files in your data base. Now enter the command LIST. EUREKA!!!!! YOU HAVE A COMPLETE BASIC PROGRAM AND YOU DIDN'T CODE A SINGLE LINE. After you have loaded records into your data base, you probably will want to see them in a report..... Read on. 2.5 DBREPORT PROGRAM The DBREPORT program generator writes the "Main Program" to prepare reports from your custom PDS*BASE data base. You can prepare different programs to write different reports. It's all in how you option the DBREPORT program generator. Again, produce an Operational Subroutine program file to APPEND the report "Main Program" by first using the DBOPSUB program generator. Step 1 - Insert the PDS*BASE Master disk copy in disk drive A and run DBREPORT. When prompted, insert your program disk (containing the Definition File) and enter the name of the Definition File. Step 2 - After the Definition File has been read, you will be asked if you wish a printed copy of the Data Base Description Listing (in case you mislaid the origional printed by the DBDEF program). Step 3 - The program will indicate that an 80 column report is standard. You can type a different value over the 80 if you wish to allow for more or less columns on the report. If you call for more than 80 columns, you will be asked if compressed printing is to be used. PAGE 16 Version 3.2 2.5 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBREPORT PROGRAM (continued) This report system is very flexible; however, the first field on the report MUST be a field in one of your Master files. When you call for a field in a Master file different from the first field Master file, a previously called for report field must contain the search item for the new Master file. Section 4.5 gives an example of how one field leads to another Master record and its fields. The program generated by the DBREPORT program will use the first field in the Master file containing the first report field as the sort item. If it is desired to sort on a field (or fields) other than the first field in the Master record, the generated program line 2100 must be modified. This is covered in detail in section 6.4.4. Detail record fields must be called for after their associated Master record field. They must be called for before a different Master file field is requested. Each file and field should progress across the report in a logical manner. Step 4 - The file and field names will be displayed. The number of characters allowed for the field will be displayed in inverse video below the field name. If the width of the field name is greater than the width of the allowed data, you will be asked if you wish to enter a shorter field name. This will allow for a more compact report. Depress Return if no change is desired. Step 5 - The calculated tab position will be displayed in inverse video. The curser will be located over the tab number. If you wish to use the tab value calculated by the program, depress the Return key. If you wish to increase the tab value, enter the new value and depress return. The DBREPORT program generator will also allow for multiple lines to display all of the data. The program will notify you when a new line is started. IF YOU WISH TO FORCE A NEW LINE type the word 'NEW' over the calculated tab number. Step 6 - The justification code is entered as follows: 1 3 5 7 = = = = Left Integer W/O Commas Real W/O Commas Monetary ($ W/Commas) 2 = Right 4 = Integer W/Commas 6 = Real W/Commas PAGE 17 Version 3.2 2.5 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBREPORT PROGRAM (continued) Step 7 - The "PRINT USING" format will be shown. You can over-type changes, if desired. Step 8 - For the first field in a Detail file, you can ask for the following: * List all of the Detail Records for each Master * List only the First Detail Record * List only the Last Detail Record * Show only the numeric total for all of the Details Step 9 - You can also depress the ESC key to call for a special column heading that is not one of the fields in your data base. As an example, you could use a special field to show the total of a unit price times the quantity. The math for this field would require that a basic line be added by you to your program at the appropriate location. Section 6.4.1 on Program Hints will show how to do this. Step 10 - To signal that you have finished calling for report fields, depress Return when asked for the next file and field numbers. Step 11 - You column headings. may optionally print out a copy of the Step 12 - You will be asked if you wish to have a built-in sort function. This sort is limited to sorting only the first field on the first Master file on the report and is limited by the amount of BASIC memory. You can use the DBSORT program generator to write a program that allows for complex multi-field sorts. Section 6.4.4 will show how to modify or add lines to your report program to provide for multi-field sorts. Step 13 - You will be asked if a date will be required for your program. Step 14 Next, enter the title that is to appear at the top of each page. Step 15 - Lastly, printed per page. specify the number of lines to be Step 16 - At this point you will be prompted for the ASCII program file name containing the Operational Subroutines for this report program. Your report "Main Program" is then appended to this file. PAGE 18 Version 3.2 2.5 PDS*BASE DATA BASE SYSTEM Copyright 1985 DBREPORT PROGRAM (continued) Step 17 - When the DBREPORT program generator has finished, enter the command LOAD" followed by your ASCII program file name. This will load the ASCII file into memory as a Basic program. Step 18 - SAVE the program in memory on your program disk with an appropriate name. To obtain your report, run the program that was just created. You may create different programs, each writing a different report. 2.6 DBSORT PROGRAM The DBREPORT program generator can write a report program with a simple built-in sort. However, it can sort only on the first field of the report. For more complex sorts, insert the PDS*BASE Master disk copy in drive "A" and run DBSORT. Then insert your program disk (with the Definition File) and enter the Definition File name. After the Definition File has been read, the DBSORT program generator will append your sort program to a previously prepared Operational Subroutine ASCII program file. Then, using the file name, load program. SAVE appropriate name. LOAD" command followed by your ASCII the ASCII file into memory as a Basic this Sort program to disk with an When this program is run it will display the file names and file numbers of all the Master files in your data base. ONLY Master files can be sorted. Remember, the Master records are not actually sorted. A key sort list will be created which will be used later by the report program to read the Master records in the desired order. You must enter the Master file number to be sorted. Only one Master file can be sorted, and it must be the same Master file that contains the first field in your report program. However, the first field in your report program does not need to be the major sort field. A list of the field names and numbers will be displayed. Enter the field numbers (one or more) in the desired order - major to minor. PAGE 19 Version 3.2 2.6 PDS*BASE DATA BASE SYSTEM DBSORT PROGRAM Copyright 1985 The program will scan the data base and sort all of the active records in the specified file. You will then be prompted for a name to save the sort key file. A very large data base with long search strings could exceed the amount of memory available to BASIC. This limit can be increased with Microsoft's QuickBasic compiler. When you run the report programs, you will be asked for the name of the sort key file. When entered, the report program will read this key file and then write the report in the order specified by the key file. If no new Masters are added between reports, only Detail records, the same sort key file can be used. If new Masters are added, a new sort must be made prior to printing the next report. 2.7 DBUTIL01 PROGRAM There will be times when the pointers in the data base will be incorrect. This can be caused by a power interruption while the data base is open. Usually it will not affect the Master records. What generally fails is the pointer to the next vacant Detail record. Thus, a Utility program is necessary to attempt to correct this problem. Step 1 - Run the DBOPSUB program generator to create the Operational Subroutines. Step 2 - Then run the DBUTIL01 program generator to append the "Main Program" to the Operational Subroutine ASCII file. Step 3 - Again, use the LOAD" command, followed by the name of your ASCII file to load the ASCII file into memory as a Basic program. Save this program on your program disk with an appropriate name. Step 4 - Run the program and it will automatically correct the pointers where possible. It will also print an error list where it is not posible to correct the pointers. This will let you know that you may have to re-enter records. The generated program will allow for a raw listing of your files, and to hard modify pointers or data fields. PAGE 20 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 3.0 EXAMPLE INVENTORY CONTROL DATA BASE Throughout this documentation, reference is made to an example Inventory Control data base. Figure 1 on Page 5 is a pictorial representation of this example data base. It consists of 5 files. Two of the files are Master files - the STOCK file and the SUPPLIER file. The remaining three files are all Detail files. They are the ORDER, RECEIVED and USED files, all are Details to the STOCK Master file. To make this example clear, we must review the thought process that the author went through to design this data base. In the following steps, the file and field names will be shown in upper case. After each field name, the desired number of characters, the REQ/OPT (Required or Optional) status and field type (CHARacter, INTeger or REAL) is shown in parentheses. We need to decide the field names, desired number of characters for the field, if the field is required or optional and the field type, before the DBDEF program can be run to define the data base. When it is a required field, any program that "posts" information to the data base should "insist" that data for that field be entered. Step 1 - The main requirement for this system is to keep track of the inventory for a stock of parts. Since the purchasing clerk will be posting information to the data base for different items of stock, the PART NUMBER must be the search item for a Master file. We will name this file STOCK. PART NUMBER (10, REQ, CHAR) Step 2 - The records in the STOCK file should contain only the minimum information. It should not contain any transaction fields. Transaction fields are repeated for each "posting" to the PART NUMBER records and should be in Detail records. The second field will be called DESCRIPTION. DESCRIPTION (15, REQ, CHAR) We wish to keep track of the Supplier Name for each PART NUMBER. However, many PART NUMBERs may have the same Supplier Name. If the name is part of each PART NUMBER record, the same Supplier Name could be repeated many times in the STOCK file. Thus, we will just include the SUPPLIER CODE with the PART NUMBER record. This code will lead us to a Master record in the SUPPLIER file that contains the SUPPLIER NAME. The SUPPLIER File will be described below in Step 4. SUPPLIER CODE (4, OPT, INT) PAGE 21 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 3.0 EXAMPLE INVENTORY CONTROL DATA BASE (continued) The last two fields in the STOCK file records will be MAXIMUM and MINIMUM. These fields will contain the desired maximum and minimum quantity for the stock item. MAXIMUM (4, OPT, INT) MINIMUM (4, OPT, INT) Step 3 - Remembering the instructions the boss gave us (see the top of Page 6), we need to separately keep track of the parts on order, the parts that have been received and placed in stock and the parts used. These are the transactions for the PART NUMBERs and will require a Detail file for each type of transaction. An actual system would probably not have all three of these transactions posted to an inventory data base. However, we wished to have 3 Detail files related to a Master file for demonstration purposes. The Detail files will be named ORDER, RECEIVED and USED. The file names must not exceed 8 characters. All three of the files DATE, QUANTITY and PRICE. DATE (8, REQ, CHAR) QUANTITY (4, REQ, INT) PRICE (10, REQ, REAL) will contain fields for the Step 4 - As mentioned in Step 2, we didn't wish to have the Supplier Name carried with each PART NUMBER record in the STOCK file. This would have wasted disk space. The information on the Suppliers will be kept in a Master file named SUPPLIER. The fields will be as follows: SUPPLIER CODE (2, REQ, INT) SUPPLIER NAME (15, REQ, CHAR) STREET ADDRESS (15, OPT, CHAR) CITY STATE AND ZIP (15, OPT, CHAR) CONTACT NAME (15, OPT, CHAR) TELEPHONE NUMBER (15, OPT, CHAR) Notice that NO COMMA was used in the CITY STATE AND ZIP field name. You can't use commas in the field names. PAGE 22 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 3.0 EXAMPLE INVENTORY CONTROL DATA BASE (continued) When a report is written from the STOCK file and it is desired to show the SUPPLIER NAME on the report, it is possible for a report program to use the SUPPLIER CODE, in the PART NUMBER record, to look up the Suppliers Name in the SUPPLIER Master file. This is described in Section 3.5. Step 5 - The last decision is the maximum number of records required for each file. For this example we elected to have 50 STOCK records, 100 each of the Detail file records and 10 SUPPLIER records. If you were designing your own data base, you would go through a similar process. It is recommended that the file and field names be noted on scratch paper prior to running the DBDEF program. Make a sketch similar to the sketch on page 5. If you have been keeping up with us so far, you should be ready to define this data base using the DBDEF program on the PDS*BASE master disk. 3.1 CREATING THE EXAMPLE DATA BASE The Inventory Control data base was defined using the DBDEF program on your PDS*BASE master disk. You can do the same for yourself by using the Data Base Description Listing shown starting on the next page and continuing to Page 25. The DBDEF program will add ".DEF" to the end of the data base name you enter when running the program. This is so that when you do a DIR of your program disk, you can identify your definition files. When running the other programs on the PDS*BASE master disk, you can either enter your definition file name with or without the ".DEF". Also on the PDS*BASE master disk is the INVENTRY.DEF file that is the Definition File for this example data base. After you have attempted to create your own definition file using the following listing, you can run the DBREPORT program on the PDS*BASE master disk and input the INVENTRY.DEF file, also on the master disk, to check how you did. So, see one file data insert the PDS*BASE master disk (back-up copy) and if you can create the example Definition File. Have formatted disk on which to save your Definition and programs, and a second formatted disk for your base. PAGE 23 Version 3.2 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 SAMPLE DATA BASE DESCRIPTION LIST DATA BASE DESCRIPTION FILE FOR INVENTRY DATA BASE SECTORS**FILE NAME**************FILE **FROM****** TO ***DRIVE* REQ. SECT. REC # REC # ---------------------------------------------------------------19 STOCK.DAT 1 1 50 A 8 ORDER.DAT 1 1 100 A 8 RECEIVED.DAT 1 1 100 A 8 USED.DAT 1 1 100 A 5 SUPPLIER.DAT 1 1 10 A TOTAL DISK DRIVE(S) REQUIRED=1 FILE AND FIELD NAME LISTING FILE NAME****************FIELD NAME********TYPE*****SIZE*REQ/OPT ---------------------------------------------------------------SET # 1 STOCK.DAT SET # 2 ORDER.DAT MASTER 95 (1,1) PART NUMBER CHARACTER 10 R (1,2) DESCRIPTION CHARACTER 15 R (1,3) SUPPLIER CODE INTEGER 2 R (1,4) MAXIMUM INTEGER 4 O (1,5) MINIMUM INTEGER 4 O (MASTER=STOCK.DAT) DETAIL 38 (2,1) DATE CHARACTER 8 R (2,2) QUANTITY INTEGER 4 R (2,3) PRICE REAL 10 R PAGE 24 Version 3.2 PDS*BASE DATA BASE SYSTEM FILE AND FIELD NAME LISTING (Continued) Copyright 1985 FILE NAME****************FIELD NAME********TYPE*****SIZE*REQ/OPT ---------------------------------------------------------------SET # 3 RECEIVED.DAT SET # 4 USED.DAT (MASTER=STOCK.DAT) DETAIL 38 (3,1) DATE CHARACTER 8 R (3,2) QUANTITY INTEGER 4 R (3,3) PRICE REAL 10 R DETAIL 38 (MASTER=STOCK.DAT) (4,1) DATE CHARACTER 8 R (4,2) QUANTITY INTEGER 4 R (4,3) PRICE REAL 10 R SET # 5 SUPPLIER.DAT MASTER (5,1) SUPPLIER CODE INTEGER (5,2) SUPPLIER NAME (5,3) 102 2 R CHARACTER 15 R STREET ADDRESS CHARACTER 15 O (5,4) CITY STATE AND ZIP CHARACTER 15 O (5,5) CONTACT NAME CHARACTER 15 O (5,6) TELEPHONE NUMBER CHARACTER 15 O ^ ^ <--These file and field numbers are calculated by the DBDEF program. ---------------------------------------------------------------3.3 CREATING THE BLANK DATA BASE You should create the blank data base on a separate disk from your Definition File and programs, as you may not have enough room on one disk. Insert the PDS*BASE master copy and run DBCREATE. When prompted, insert your program disk to load the Definition File. Then insert a formatted disk to create the blank data base. PAGE 25 Version 3.2 3.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 CREATING THE MANAGEMENT PROGRAM Now, insert the PDS*BASE master copy and run DBOPSUB. When prompted, insert your program disk. Name the ASCII file TESTMAN.BAS. Then, using the PDS*BASE master copy, run DBMANAGE. Insert the program disk when prompted. When asked for the PROGRAM file name, be sure to use TESTMAN.BAS. When the DBMANAGE generator is finished, type LOAD" followed by TESTMAN and RETURN. This will load the ASCII file into memory as a BASIC program. SAVE this program to your program disk with the name TESTMAN. Run this program and load some test data into the INVENTRY Data Base (notice that Inventory was shortened to 8 characters in our example - Was yours?). Create Master and Detail records. Try deleting them. Use codes like "1", "2", etc., for the Supplier Codes. Be sure that you have established Supplier Code Masters for any Supplier Codes used as field number 3 in establishing STOCK Masters, or a report may look strange. 3.5 CREATING THE REPORT PROGRAM Now, create another PROGRAM file, starting with the DBOPSUB program as above. Name the PROGRAM file TESTREP.BAS. Then, insert the PDS*BASE master copy disk and run DBREPORT. When prompted, insert your program disk. Unless you are sure of what you are doing, enter the following in answer to the program questions: 1,1 1,2 2,1 2,2 5,2 (ASK FOR EACH LINE) (Answer 1,3 to the question) Press RETURN This should produce a report on the following fields: PART NUMBER DESCRIPTION DATE QUANTITY SUPPLIER NAME When the program calls for the PROGRAM file, be sure to use TESTREP.BAS. When the generator is finished, type LOAD" and then TESTREP, followed by RETURN. Again, this will load the ASCII file into memory as a BASIC program. SAVE the program as TESTREP. Now, run TESTREP, and see what happens - GOOD LUCK !! PAGE 26 Version 3.2 3.6 PDS*BASE DATA BASE SYSTEM Copyright 1985 CREATING A SORT PROGRAM Create a PROGRAM file called TESTSORT.BAS, as above, with the DBOPSUB program. Then, append to TESTSORT.BAS by running DBSORT from the PDS*BASE master disk copy. LOAD TESTSORT into memory as a BASIC program and SAVE as TESTSORT. When you run TESTSORT it will let you sort on any field in any of the Master files in the data base. You can not sort Detail file fields. The NOT file the the will program will ask for an external sort key file name. DO USE THE SAME NAME AS ANY OF YOUR DATA BASE FILES, or the will be deleted and replaced by the sort key file. When program has finished the sort, the correct order to read records for a report will be saved to disk. The program then display the following: 1 - STOCK 5 - SUPPLIER ENTER THE FILE NUMBER? Since the report program created in Section 3.4 has a field from the STOCK file as the first field, all sorts for that report program must be with fields in the STOCK file. Thus, enter a "1". The program will display the following: ENTER THE MAJOR TO MINOR SORT FIELD NUMBERS 1 - PART NUMBER 2 - DESCRIPTION 3 - SUPPLIER CODE 4 - MAXIMUM 5 - MINIMUM ENTER FIELD NUMBER? Each time you enter a field number, "ENTER FIELD NUMBER" is displayed again. As an example, enter "2" and then "1". This will cause a sort by DESCRIPTION and then by PART NUMBER. The program will then perform the sort and save the sort key file to disk. Run the report program and enter the sort key file name that you used when you ran the sort program. The program will read the sort key file and then print the desired report. Then, experiment with different report formats. PAGE 27 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 4.0 DESCRIPTION OF THE OPERATIONAL SUBROUTINES For the following, it is suggested that you remove Appendix A from your ring binder. This will make it easier to follow the subroutine explanations. All of the subroutines were written so that it would be possible for a BASIC programmer to write his/her own "Main Programs" and just have to call the subroutines as desired with a simple GOSUB command. All PDS*BASE programs must start with the Operational Subroutines for the program that follows to gain access to the data base files. The Operational subroutines start at line 10 (actually your program title line) and end at line 2000. However, the PDS*BASE Master Disk contains program generators that should take you within 80% to 100% of the final desired result for your "Main Programs". Section 5 will give you instructions on how to modify the generated programs to fit your exact needs. Lines 10 through 90 are mostly housekeeping. They consist of REM lines to explain the use of the variable arrays. Lines 100 to 199 READ in the necessary information about the structure of each file. REM lines 71-89 explain each variable. Lines 210 to 299 READ in the complete description of the field parameters for each file. 4.1 OPENING THE DATA BASE FILES Lines 300-380 OPEN all of the files in the data base. You could add an IF statement at line 312 to GOTO line 370, if you didn't wish to OPEN all of the files for certain application programs. If you have more than 3 files in your data base open at one time, it will be necessary to use the "F" option in the basic command when you are in DOS. If your longest record exceeds 128 bytes, you must also specify the "S" option. For example, for 5 files with the longest 823 characters, use "BASIC/F:6/S:823" (one extra for sort key file). The DBDEF program will print a warning on the definition listing if the number of files or the buffer size will exceed the BASIC default options. You should set up an AUTOEXEC.BAT file on your program disk that will automatically load the BASIC interpeter optioned as required when you boot up your computer with your program disk. PAGE 28 Version 3.2 4.1 PDS*BASE DATA BASE SYSTEM Copyright 1985 OPENING THE DATA BASE FILES (continued) Assuming that you have a menu program on your program disk, the AUTOEXEC.BAT command (for the example on the preceeding page) would be "BASIC MENU/F:6/S:823". Line 320 finds the name of the file to be opened. If you have a file that uses more than 1 drive, line 315 will be changed to a FOR-NEXT to set Z2 = to the file section number. In that case, line 340 will be added to end the FOR-NEXT LOOP. The DBOPSUB program generator will optionally prefix a drive letter and colon to the file name. Line 320 OPENs the file. Lines 325 and 326 field the pointers for the files. Line 335 GETs the housekeeping record tacked on to the end of each Master file to obtain the current number of records assigned. See line 430 where this value is updated when the file is closed. Line 337 GETs the housekeeping record tacked on to the end of each Detail file to obtain the number of records assigned and the pointer to the next vacant Detail record. See line 430 for closing this data. When the blank Detail files were created by the DBCREATE program, each Detail record had its forward pointer set to the number of the next higher record. The "Next Vacant Record" pointer is always kept track of by the PDS*BASE System. More on this later. Line 341 displays currently full. a message if the opened file is Line 344 checks the "Next Vacant Record" in a Detail file to be sure that it is actually vacant. If not, line 360 will display the error message and the program will end. This will happen if Detail records are added and the power fails (or any other system crash occurs) before the PDS*BASE System closes the files. 4.2 CLOSING THE DATA BASE FILES Lines 420 and 430 update the housekeeping record and line 445 will CLOSE all files. A system crash will not update these records for future use of the data base. The DBUTIL01 program will correct the housekeeping record problems. In opening closing and reading the files, the DBOPSUB program generator will automatically make minor changes and additions to the generated programs if one of your files is spread over more than 1 disk drive. PAGE 29 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 4.3 CALCULATING A RANDOM ACCESS RECORD NUMBER This is where the PDS*BASE System differs from many of the "highly advertised" systems on the market today. Many of the other systems use a key file only if you specify that "Random Access" is desired. They then make a quick search of the key file to locate the record number. Others require that you actually sort your entire data base so that a binary search can be performed directly on the records themselves. These systems are good, and fast to set up, if you have single files that don't require much in the way of random access. In fact, if you have a simple single file requirement where you don't need Master/Detail requirements, PRO DEV Software recommends that you purchase one of them (if you can afford it). The other systems will require that you learn a "High Level" language if you want much in the way of complex reports. The "Hashing" method is used to calculate the desired Direct Access Record number. This method was developed in the mid-1950's. It has the advantage that it usually finds the record on the first READ. It is not necessary to make a search through the file looking for a match on the search field. Thus, it is ideal for an "on-line inter-active" system. It allows the rapid "posting" of records on an "as desired" basis. Any inventory, accounting, customer or vendor records, etc., type of system benefits from this approach to data base design. Hashing is also very simple. Take a look at lines 510, 520 and 530. Line 510 sets Z1 to the length (number of characters) of the search string. The variable ZR$ is always set to the value of the search string and ZA is set to the file number before GOSUB 500. Then Z2 is set to the size of the (ZA) file (or the maximum allowed records as defined when you ran DBDEF). Line 522 does all the work to "hash" the string. It scans across the string and converts each character to its ASCII code number (A=65, B=66, etc). The ASCII value minus 32 (to skip blanks) is multiplied by the FOR-NEXT loop indexer. This result is cubed and added to the previous amounts. PAGE 30 Version 3.2 4.3 PDS*BASE DATA BASE SYSTEM Copyright 1985 CALCULATING A RANDOM ACCESS RECORD NUMBER (continued) Multiplying (or dividing) by the FOR-NEXT indexer is somewhat unique to the PDS*BASE System. This assumes that search values will be assigned from some type of log, and that the values will continue to get larger in the last position. This algorithm will cause skips between records that will be needed as the data base becomes filled. If names are the search strings then a fairly random distribution will result anyway. Increased random spread will result if the total records limit for a file equals a prime number. Be sure to run PRIMES.BAS, after you have sized your file, to find the next higher prime number to use for the DBDEF program. Line 530 converts the above result into an integer number between one and the defined size of the file. The great advantage of directly calculating a record address is somewhat offset by the fact that the same address can be calculated for different search strings. When this happens the PDS*BASE System locates a nearby vacant record for the second (or more) record for the same address and places a pointer in the primary (calculated) record, pointing to the secondary record. This will be covered in detail in sections 4.6 and 4.11. 4.4 READING A RECORD The subroutine to read a record starts at line 600. If it is desired to read a particular record number, ZZ is set to 1 prior to calling the subroutine starting at 610. If you are looking for a Master record, based on the value of the search string (the first data field in the record), the subroutine will be called at 600 (ZZ=0). If the file being accessed is spread over 2 or more disk drives (a feature most systems can't handle), there will be lines 615, 620 and 625 (not shown in this simple example) that will calculate the proper file buffer number via Y1 (for that file segment). Line 630 GETs the desired record. Line 650 sets ZL$ equal to the first data field in the file. This is used later to test for a particular Master record. PAGE 31 Version 3.2 4.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 READING A RECORD (continued) Line 660 establishes the ZB for a backward pointer, and ZF for a forward pointer (in the chain for a particular Master). Line 665 establishes the pointer values. The variable ZC indicates the number of current masters that had this same calculated address. ZP points to the previous Master (if this is a secondary Master) and ZN points to the next Master with the same calculated address. Line 665 also establishes the ZH chain head pointers and ZE chain end pointers (1 set for each Detail file). The Y$(X,ZA) array buffer contains the actual data. As you can see, a Master/Detail Hierarchal Data Base does have overhead (pointers) in each record. Line 672 will Return if it is a Detail record. Line 673 will Return a Master if a search string match is not needed. Lines 675 to 685 will search for Secondary Masters (same calculated record address) if the search string match fails on the primary (calculated address) record. If no match is found, an error message is displayed and the variable ZV is set to 1. You may wish to use the value of ZV in your "Main Program". You can also suppress the message by removing the second PRINT statement in line 680. 4.5 WRITE OR UPDATE A RECORD This subroutine starts at either line 700 or 750. The first option (GOSUB 700) writes the record using the Y$(X,ZA) data buffer. The second option (GOSUB 750) writes the record using the ZI$(X,ZA) data buffer. The first option will be explained, as the second operates identically except for line 780 that transfers the data from the ZI$(X,ZA) buffer to the Y$(X,ZA) buffer. The variable ZR must be set to the desired record and ZA must be set to the desired file number prior to calling this subroutine. If this were a multi-disk file (not shown in this example) line 705 would first call the subroutine at line 610 (RETURNing from 625) to obtain Y1 for the file buffer number and actual record number. PAGE 32 Version 3.2 4.5 PDS*BASE DATA BASE SYSTEM Copyright 1985 WRITE OR UPDATE A RECORD (continued) Lines 710 and field buffers. 720 transfer the record pointers to the Line 740 PUTs the record. This subroutine is split into 2 sections as there will be situations where it is desired to hold your actual new data in the ZI$ buffer while secondary Master records are tested to see if they are blank, or to relocate them if they are not blank. More on this in Sections 4.6 and 4.8. 4.6 CREATE A MASTER RECORD This subroutine starts at line 800. ZR is set to the calculated record number from GOSUB 500. ZA is set to the file number. In this example ZA=1 for "PARTS" or ZA=5 for "SUPPLIER". The new data will be contained in the ZI$ buffer. Lines 810 and 820 check to see if the calculated record is presently blank. If it is not blank, we branch to line 880. If it is blank, the new record can be created at the calculated location. Line 335 sets the detail chain head and chain end pointers to zero. The record is created at line 840. Line 850 adds one to the active record counter so that the housekeeping record can be updated when the file is closed at the end of the program. Lines 852 and 854 append active record numbers to the Master Sort key files. Line 880 is branched to (from the above paragraph) if the calculated record was already occupied. First ZC is checked to see if this is a primary Master already at this location. If it is a primary Master, ZC will be greater than zero. ZC is zero if this is a secondary Master. ZC is a count (only at the primary location) of the Masters that have this primary or calculated address. If it is a secondary Master, we branch to 950 to move the secondary Master out of the way. If this was a primary master, the search data item is checked for a duplicate entry in line 890. Then the subroutine at 1800 is called to find a vacant record for the new Master and the new record is created at that location. It will now be necessary to update the Master at the primary location (and possibly in other intermediate secondary locations) so that pointers will lead from the primary calculated location to the location of the new (secondary) Master. PAGE 33 Version 3.2 4.6 PDS*BASE DATA BASE SYSTEM Copyright 1985 CREATE A MASTER RECORD (continued) Line 950 was branched to from the above paragraph if the primary address for the new Master was already occupied by a secondary Master. Line 950 moves that secondary Master to a vacant location and lines 955 and 965 change the ZP and ZN pointers in the previous and possibly next secondary records. Then line 970 sets up the pointers for the new record and branches back up to 825 to create it. Now, all of the above may have sounded complicated well IT IS! However, it happens fast and is usually transparent to the user. It was necessary to move the secondary Master when it happpened to be in the way, because THERE MUST BE A PRIMARY MASTER AT A CALCULATED LOCATION or you will never be able to keep secondary chains from crossing. The secondary Master doesn't care where it is located as it has pointers leading to it. You probably think that the PDS*BASE System will become slow due to searching through secondary Master chains. After all, this is touted as being a "True" random access data base system. Actually, it is rare that you will ever have more than one or two Masters to search to find the desired entry as the algorithm at line 520 tends to spread the records evenly across the file in most applications. You will find that a six record secondary chain can be searched in less than two seconds running in BASIC. If compiled, it runs even faster. 4.7 CREATE A DETAIL RECORD This subroutine starts at line 1000. ZM must = the Master file number and ZS must = the Detail file number. Lines 1025 to 1060 check for "Main Program" errors to be sure that the Detail file number specified is actually a detail to the Master file specified. Line 1100 reads the "Next Vacant Record" location (found in the housekeeping record for this Detail file, or subsequently updated). The forward pointer now becomes the new "Next Vacant Record" for future Detail record additions to this file. PAGE 34 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 4.7 CREATE A DETAIL RECORD (continued) Line 1115 reads the associated Master to get any existing chain head and end pointers. Line 1120 sets both chain head and chain end pointers to the new Detail record number if there were no existing Detail records. Line 1125 sets a new chain end in the associated Master. Lines 1130 and 1140 set the forward pointer in the previous chain end record to the value of the new chain end record address. Line 1140 creates the new Detail record. Line 1145 updates the active record count for the Detail file. This will be written to the housekeeping record at the end of the session when the files are closed. 4.8 DELETE A MASTER RECORD This subroutine starts at line 1200. ZA must = the Master file number, ZR$ must = the value of the search item. Lines 1210 to 1215 check to see records. You can't delete a Detail records, as there would Details without their associated Line 1220 Master. will branch to if there are any Detail Master that still has be no way to access the Master record. 1240 if it is a Secondary Line 1225 checks to see if this Primary Master has any Secondary Masters, and if so, branches to 1280. Line 1230 sets all of the ZI$ data fields to blank, zero's out the pointers and calls the subroutine at 750 to set (update) the record to blank. Then one is subtracted from the number of records assigned. If line 1240 was branched to because it was a Secondary Master to be deleted, the previous and possibly the next Secondary Masters need to be updated (lines 1245 and 1250). The Primary Master is then updated to show one less Secondary Master. Finally, a GOTO 1230 to delete the record. PAGE 35 Version 3.2 4.8 PDS*BASE DATA BASE SYSTEM Copyright 1985 DELETE A MASTER RECORD (continued) Line 1280 was reached because the Master being removed has Secondary Masters. Thus, lines 1280, 1285 and 1290 move the first Secondary Master to the primary location (actually replacing the record to be deleted) and the pointers are updated in further Secondary Masters. Then a branch to 1230 to blanks out the location of the former first Secondary Master. Again, this sounds complicated and it is; but it happens fast. There are no searches. The pointers cause the records to be updated and deleted as fast as the disk drive head can move. 4.9 DELETE A DETAIL RECORD This subroutine starts at line 1300. It is assumed that YS=the record number of the Detail, YM=the record number of its associated Master, ZS=the Detail file number and ZM=the associated Master file number. Line 1310 sets the data fields to blank, sets the forward pointer to the present value of the "Next Vacant Record", calls the subroutine at 750 to blank (actually update) the Detail, resets the "Next Vacant Record" to the deleted Details record number and subtracts one from the "Records Available" counter. The remainder of this subroutine updates pointers in the other Details in the chain and updates the pointers in the associated Master (if necessary). Again, a lot of work. It runs fast due to the pointers. 4.10 TRANSFER INPUT DATA TO THE OUTPUT BUFFER This subroutine starts at line 1500 and is used by some "Main Programs" such as the "Management" programs when a record is being modified. 4.11 LOCATE A BLANK POSITION FOR A MASTER RECORD This subroutine starts at line 1800. It is called by the GOSUB 800 that creates Master records when the primary (calculated) record location is occupied already. PAGE 36 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 4.11 LOCATE A BLANK POSITION FOR A MASTER RECORD (continued) This subroutine checks to see if the data file is full. Then it starts searching DOWNWARD from the primary location for the first available blank record. The algorithm at line 520 has (hopefully) left gaps in the records so that the subroutine will find a vacant record after only several reads. Using a prime number for the total number of records helps to spread the gaps and reduce record clumping. HOWEVER, AS THE FILE REACHES ABOUT 80% FILL, THE NUMBER OF GAPS IS REDUCED SIGNIFICANTLY. THE SEARCH COULD TAKE SOME TIME. OVER 90% FILL, THE SEARCH MAY BECOME EXCESSIVE. Remember this when you are sizing your data files with the DBDEF program: use at least a 20% safety factor. Also, if possible, use a prime number for the total possible records in a master file. This should produce a better random spread and less record clumping. Run program PRIMES.BAS to find the next larger prime number. On large main frame computers this type of data base uses block records to contain bit maps for the record status information. They can do this since a hard disk system is so fast that reading these bit map records doesn't slow down the system. Thus, they can locate a vacant record fast, even with a high fill. Versions 1.0 and 2.0 of the PDS*BASE System used large status flag arrays to indicate a vacant or live record. However, as the size of the files increased, the amount of memory taken by the flag arrays also increased. If you have a small file, the search time to CREATE a record at high fill is not excessive. If the file was large enough for the search time to become excessive, then there was not enough memory to contain the flags. Thus, starting with Version 3.0, the record flags were abandoned as the various trade-offs indicated such. Keep in mind - THERE IS NO DELAY IN READING RECORDS, EVEN AT 100% FILL. PAGE 37 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 5.0 DESCRIPTION OF THE MAIN PROGRAMS 5.1 DESCRIPTION OF THE MANAGEMENT PROGRAM It is suggested that you remove Appendix A from the PDS*BASE ring binder for easy reference. Line 2010 is the header for the Main Menu. Note that the data base name (ZB$) is part of the PRINT statement. If you have shortened the name to 8 characters, but would like a longer, or different, name on the screen, modify ZB$ in line 60. Lines 2021 to 2039 display the names of the files in your data base. The number of lines will vary, depending on the number of files defined for your data base. Again, since you shortened the names to fit into 8 characters (as these are the names of the files), you can modify the PRINT statements to be more descriptive. Lines 2040 to 2080 determine the file program option selected from the menu. number and **** ADD OPTION **** Lines 2100 to 2190 cover records to the data base. the "A" option to ADD new If a Main Menu number was entered for a Detail file, lines 2105 to 2125 will first ask for the search string for the Details associated Master. REMEMBER, A DETAIL CAN ONLY BE ACCESSED VIA ITS MASTER RECORD. If you have not yet created the Master record, then you can't create a Detail for it. Line 2125 actually looks up the associated Master in the Master file to be sure that it does exist. If it doesn't exist, line 680 in the Operational Subroutine to READ a record will display a "Not Found" error message. In that case, ZV will equal 1 and you will be taken back to 2100 to ask for the Master again. Lines 2130 to 2137 ask for the data field information. This is done inside the FOR-NEXT loop that has the number of fields as the limiter (ZA%(ZA,7)). The Subroutine at 5000 is called for each field to obtain the data. This Subroutine will be discussed later. Line 2150 will GOSUB 800 to create a Master record, or line 2160 will GOSUB 1000 to create a Detail record. Lines 2170 to 2190 prompt for either the next Master or the next Detail. PAGE 38 Version 3.2 5.1 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE MANAGEMENT PROGRAM (continued) **** MODIFY (LOOK AT) OR DELETE **** If you are Modifying (or Looking At) or Deleting a Master, you will branch from line 2205 to line 2330. Lines 2205 to 2230 again ask for the associated Master, if you are Modifying or Deleting a Detail record. You need the Master to get to the Detail chain. Line 2245 then sets ZR = to the chain head record for the Details for this Master. If ZR = zero, there are no Details for this Master. Lines 2250 to 2277 look up each Detail for this Master, and display them on the screen, one at a time. If the space bar is depressed, the next Detail will be displayed. If "S" is depressed, you will stop at that Detail. This is how you can search the Masters Detail record chain to modify one or more of the chained records. If you are in the DELETE mode, line 2277 will branch you to line 2400 where you will be asked if you wish to actually delete this Detail. If you are in the MODIFY mode, lines 2280 to 2300 ask which field is to be modified, and then re-display the modified record. When you depress RETURN to select the field to be modified, line 2315 will GOSUB 750 to update the record. If you were modifying or deleting a MASTER record, you branched to line 2330 from line 2205. After you enter the search string for the Master record, line 2335 will GOSUB 500 to calculate the record number, GOSUB 600 to read the record, GOSUB 1500 to transfer the data from the input buffer to the output buffer and GOTO 2295 where the record will be displayed. Again, lines 2297 to 2300 display the record, and lines 2280 to 2295 allow you to modify entries. If you were in the DELETE mode, then, between lines 2400 and 2430 you will be asked if you want to delete the record. If answered "Y", you will GOSUB 1200 to delete a Master, or GOSUB 1300 to delete a Detail. PAGE 39 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 5.1 DESCRIPTION OF THE MANAGEMENT PROGRAM (continued) **** SUBROUTINE 5000 TO INPUT FIELD DATA **** This Subroutine uses an INKEY$ statement at 5070 to input each character. By using this method to collect data, it is possible to test for the "ESC" command. The "ESC" is used to "Abort" from an entry. Using just an INPUT statement won't give the desired control over the input of data. This Subroutine starts at line 5000. The allowed length of the field (Z2) is compared to the length of the name of the variable field (Z3). If their combined length is less than the width of the screen (line 5025), the field name (line 5040) and the inverse window for the input (line 5046) will be displayed on the same line. Otherwise, the window will appear on the line after the field name (line 5044). The FOR-NEXT loop from line 5060 to line 5200 inputs the field data. Each character is input with the YC$=INPUT$ at line 5070. The ESCAPE key is checked at line 5080. If it was pressed, the FOR-NEXT indexer is set to the limit, the field is blanked and a GOTO 5200 forces an abort of the FOR-NEXT loop. Since an INKEY$ does not display the character being entered, the PRINT at line 5120 displays the character. Lines 5090 and 5100 handle the backspace key. Line 5110 detects a FOR-NEXT input loop. RETURN and forces the end of the If the field was specified for "Character" data (Alpha/Numeric), line 5130 branches to 5190 to allow any character to be input. PAGE 40 Version 3.2 5.1 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE MANAGEMENT PROGRAM (continued) Lines 5150 to 5170 ("I" or "R") fields. Line 5190 buffer. places insure the input numeric input for numeric character into the ZI$ Line 5200 ends the input FOR-NEXT loop. Line 5205 scrolls the screen one line if the ESC key was depressed or the data filled the field (RETURN not depressed). Line 5207 detects that RETURN was depressed without data on the first field of a Master. This indicates that the user is done entering new Masters. Lines 5210 to 5215 "Required" field. insure that data was input for a The Subroutine at 5300 handles the backspace key. 5.2 DESCRIPTION OF THE REPORT PROGRAM Appendix B shows the "Main Program" of the Report program for the Example Inventory Data Base, as described in Section 4.5. Assume that the Operational Subroutines for this program are the same as for the "Management" program in Appendix A. This program will not use the Subroutines from line 700 thru line 1860. Line 2010 displays the header for your data base name. The name (ZB$) that is displayed can be changed by modifying line 60. Line 2020 will open the sort key file for the Master file. If the sort key file can be used, it will be loaded and the sort will be skipped. If the file doesn't exist, the time and date stamps or the number of records doesn't match, the program will branch to line 2040 to scan the entire file for sort keys. After the fields are loaded, they will be sorted between lines 2140 and 2290. The sort will also be saved. This sort is the same as used in the SORT program, and will be described in Section 5.3. The actual report writing starts at line 2300. If a date field was specified by the DBREPORT program, the date will be asked for in line 2305. PAGE 41 Version 3.2 5.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE REPORT PROGRAM (continued) The variables follows: DIMensioned in line 2330 are used as YT%(5,9) is described in REM line 2350. YT$(5) is the to printing. buffer that will store the fields prior YH%(5,3) stores the Detail file chain head when a Master field is encountered. This Detail chain may be used in a later field. YE%(5,3) stores the Detail file chain ends. The "5", in the above, is because our example has 5 fields per printed line. This number is established by the DBREPORT program. The FOR-NEXT loop in line 2340 READs in all of the DATA that describes just what this report is all about. This is how the options are passed from the DBREPORT program to this program. Each line of the report is calculated, READ from the data base and printed from within the FOR-NEXT loop between lines 2394 and 2600. Each field is stored in the YT$ array buffer. Line 2400 READs the first field for the report line. Line 2405 looks for a Detail field. Line 2410 handles additional Master fields that are in a record previously READ. Line 2415 is for a Master field that is the first field in a Master that has not already been READ for this report line. YR$(X) will hold the search string value (obtained from a previous field in this report line) that will allow a random access READ for this new Master field. YR$(X) was set previously in line 2490. If YR$(X) is blank in line 2415, the READ for this new Master is skipped. If YR$ holds a value, the new Master record will be obtained by line 2420. Line 2430 checks to see if this Master has any associated Detail files, and if so, stores any chain head and ends for any Detail fields that occur later on the report line. PAGE 42 Version 3.2 5.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE REPORT PROGRAM (continued) If this has been a Master field, a GOTO 2485 at 2435 will cause the "Future Field" flag (YT%(ZJ,3)) to be checked, and store the search value for a new Master search string (located as a field in this record) to be used for a later field on the report line. If this was a Detail field, this is handled between lines 2440 and 2480. This section only handles the first READ for a Detail chain. If the DBREPORT program was optioned to READ all of the Detail records in a chain, the additional records in the chain are READ between lines 2510 and 2545. If a report line is printed for each Detail in a Detail chain, the lines are printed by GOSUB 4000 at lines 2515 and 2545. If only one Detail in a chain is used, the report line is printed by GOSUB 4000 at line 2590. **** SUBROUTINE 4000 TO PRINT A LINE **** The subroutine checks the line counter at line 4015 to see if the GOSUB 4500 should be called to print a page heading. The FOR-NEXT loop between lines 4020 and 4090 check for the correct justification. Lines 4035 to 4045 handle Left justification. Lines 4055 to 4065 handle right justification. Line 4100 prints the first field. The following lines (through 4295) print the remaining fields. The number of lines will vary depending on the number of fields to be printed. Each line starts with a TAB function followed by an LPRINT USING statement to print the field data. Alphanumeric (character) fields print the string variable. Numeric fields print the VALue of the string variable. This all could have been done in a FOR-NEXT loop. However, you can easily modify the order of the line numbers to change the order of printing the fields. PAGE 43 Version 3.2 5.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE REPORT PROGRAM (continued) **** SUBROUTINE 4500 FOR PAGE HEADINGS **** The page heading lines between lines 4500 and 4560 are all set up by the DBREPORT program. Thus, nothing is calculated in this subroutine. 5.3 DESCRIPTION OF THE SORT PROGRAM Sorting in interpeted BASIC programming can be a problem for very large data base master files. The sort program needs room in memory to hold ALL of the search strings along with the BASIC program. Interpeted BASIC only allows a little less than 64,000 bytes of memory. Over several thousand long search strings may exceed the amount of available memory. However, if you compile the BASIC program with Microsoft's QuickBasic compiler, you are allowed additional memory for strings. You can even separately compile a subroutine module to contain little more than just the search strings themselves. If this does not solve the problem, you can write a small main program that writes just the search string and it's record number to a sequencial file and then use a purchased sort routine on that file. If all else fails, use one of the expensive data base systems. The PDS*BASE Data Base can't be all things to all programmers. Appendix C shows the "Main Program" for the Sort Program for the Example Inventory Data Base, as described in Section 4.5. Assume that the Operational Subroutines for this program are the same as for the "Management" Program in Appendix A. This program will not use the Subroutines from line 700 thru line 1860. Line 2010 shows the header for this program. The Data Base name is shown, and can be modified by you to be more descriptive. PAGE 44 Version 3.2 5.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE SORT PROGRAM (continued) Line 2015 DIMensions as follows: the array variables, and is used YA$(X) will hold the sort key strings YA%(X,Y) will hold the sort tags. X = maximum number of records of the largest file in the data base. Y = 1 is to hold the array tag for the sort strings YA$(X). Y = 2 is to hold the tag for the record numbers in the actual data base file being sorted. YF%(Z) will order. Z = most fields. hold the Major - To - Minor sort field the number of fields in the file with the You may wish to modify the value of "X" if you are not going to be sorting the largest master file in your data base. This will save memory. Line 2020 asks for the file name to which to save the sort key record numbers at the end of the program. Line 2030 displays all of the master file names. ONLY MASTER FILES CAN BE SORTED. Line 2035 asks which file is to be sorted. Line 2040 displays all of the fields in the selected file. Lines 2045 and 2050 allow you to input the fields that are to be sorted. Any, or all, of the fields in the selected Master file can be entered. It is NOT necessary to sort on the search (first field) first. The field numbers are entered in the order of Major To - Minor. These field numbers are stored in the YF% array. Line 2050 indicates that the sort strings are being loaded. Line 2060 warns that there may be times when the disk drive stops. This is may be caused by occasional garbage collection due to the way that BASIC dynamically assigns string space. Compiling the program almost entirely eliminates this happening. PAGE 45 Version 3.2 5.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DESCRIPTION OF THE SORT PROGRAM (continued) Lines 2065 to 2120 load the sort strings from the selected data base file. The sort fields are concatenated to the YA$ array. This is the process where garbage can occur, particularly if the number of sort fields is large, and the number of active records in the data base file is large. During the loading process, the YA%(X,1) array is set to "1", "2", "3", etc. Line 2100 skips any vacant records in the data base file. YA%(X,2) will contain the record numbers of just the active records. This process avoids sorting blank records. Then line 2130 sort delay. informs you that there will be a file Lines 2140 to 2220 perform the sort for Z5 records. This is a standard QUIK sort modified to be a Tag sort. The TAG means that in line 2170 we swap tags or pointers rather than the strings themselves. This is faster than swaping strings. The order in which we look at the strings is controlled by the YA%(X,1) array. Initially, during the loading process, this array was set to "1", "2", "3", etc. This array controls which YA$ we look at during a pass. At line 2170, the YA%(X,1) TAG (or array numbers) are "swapped". THUS, STRINGS ARE NOT MOVED. The YA%(X,2) array TAGs are also "swapped". At the end of the sort, the YA%(X,2) array is sorted into the desired order to read the data base Master file for a report. Lines 2250 to 2290 save the sorted record numbers to the desired disk file. Lines 2300 to 2340 save the master file sort key file. If this file is up to date, (the date and time stamps are correct and the number of records is correct) the report program will search only active records the next time it is run. PAGE 46 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 6.0 PROGRAM HINTS AND MODIFICATIONS The PRO DEV Software PDS*BASE Data Base System consists of a series of programs and program generators. This system creates custom data base systems and a series of BASIC programs that operate with the custom data base. It is the fact that the programs are in BASIC which gives the PDS*BASE the flexibility needed to meet complex applications. With this system you can generate and modify a series of programs to operate the custom data base. These programs can be run by non-programmers. Several of the modifications have been referred to in previous sections of this documentation. They, and many others, will be covered in this section. 6.1 MODIFYING THE DEFINITION FILE The Definition File is a simple sequential file. The variables are separated with commas and each record is ended with a carriage return. Thus, almost any Word Processing program or EDLIN.COM (on your DOS disk) can load and modify the Definition file. Following is the Definition File for the Example Inventory Data Base described in Section 4.2. Lines bracketed by < > are narrative added for this manual and are not part of the actual Definition File. 5,1,INVENTRY.DEF < Number of files, Number of disk drives and Definition File Name > < FILE # 1 > STOCK.DAT,1,3,5,50,19,95,1,0 < File Name, File Type (1=Master, 2=Detail), Number of associated files, Number of fields, Maximum records, Disk sectors required, Characters per record, Number of disk drives required, Sectors reserved for sort key file > 1,1,50,1 < This line is repeated for the number of disk drives required to contain this file. The fields are: The drive # (converted to letter later, Starting record number, Ending record number in this section, Section number for this file > PAGE 47 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 < The following three lines are the associated file names for this file > ORDER.DAT RECEIVED.DAT USED.DAT < Following is the data on each field in the file > < Field name, Required or Optional, Field Type (C=Character, I=Integer or R=Real), and the number of characters in the field > PART NUMBER,R,C,10 DESCRIPTION,R,C,15 SUPPLIER CODE,R,I,2 MAXIMUM,O,I,4 MINIMUM,O,I,4 < This is the end of File # 1 > < The following 4 Files have the same format > < FILE # 2 > ORDER.DAT,2,1,3,50,8,38,1,0 1,1,50,1 STOCK.DAT < The associated Master > DATE,R,C,8 QUANTITY,R,I,4 PRICE,R,R,10 < FILE # 3 > RECEIVED.DAT,2,1,3,50,8,38,1,0 1,1,50,1 STOCK.DAT < The associated Master > DATE,R,C,8 QUANTITY,R,I,4 PRICE,R,R,10 < FILE # 4 > USED.DAT,2,1,3,50,8,38,1,0 1,1,50,1 STOCK.DAT < The associated Master > DATE,R,C,8 QUANTITY,R,I,4 PRICE,R,R,10 < FILE # 5 > SUPPLIER.DAT,1,0,6,10,5,102,1,0 1,1,10,1 SUPPLIER CODE,R,I,2 SUPPLIER NAME,R,C,15 STREET ADDRESS,O,C,15 CITY STATE AND ZIP,O,C,15 CONTACT NAME,O,C,15 TELEPHONE NUMBER,O,C,15 End of the Example Definition File. PAGE 48 Version 3.2 6.1 PDS*BASE DATA BASE SYSTEM Copyright 1985 MODIFYING THE DEFINITION FILE (Continued) The previous 1 and 1/2 pages explain the format of the Definition File for the Example Inventory Data Base. 6.1.1 CHANGING DISK DRIVES FOR A FILE The Drive number is the first item on the second record for each file in the data base. A 1 will become drive "A", 2 = "B", etc. You would have to use the Data Base Description File Listing to work out a different arrangement to locate the files on a multi-disk system. The Listing will show the sectors required for each file so that you will not exceed 708 sectors for each double sided disk drive. It is possible to option DBOPSUB so that drive letters are not used for single drive or hard disk drive applications. You may wish to move the files so that you can reserve room on a disk for a special report file, or for a large sort key file. The Definition File must be modified, if desired, before the DBCREATE program or any of the program generators are run. 6.1.2 CHANGING FILE NAMES The file names are the first field in the first line of each set. Be sure to change the field name in all of its locations if it has associated sets. 6.1.3 CHANGING THE NUMBER OF RECORDS IN A FILE This is the 5th item on the Field Description line. CARE SHOULD BE TAKEN, AS YOU MAY EXCEED THE DISK CAPACITY. It is better to run DBDEF again. 6.1.4 CHANGING FIELD NAMES Easy - just do it. 6.1.5 CHANGING REQUIRED/OPTIONAL INDICATOR The Required/Optional flag is the second item on the field description line. IT CAN ONLY BE AN "R" OR AN "O". PAGE 49 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 6.1.6 CHANGING THE FIELD TYPE The third item on the field description line is either a "C" for Character (or Alpha/Numeric), an "I" for Integer (Whole Numbers Only) or an "R" for a Real number (may include Decimal Point) field. Use only one of these three codes. 6.1.7 CHANGING THE FIELD WIDTH The Field Width (or the number of allowed characters in a field) is controlled by the last item on the field description line. TAKE CARE - BE SURE TO ADJUST THE TOTAL RECORD WIDTH ITEM ON THE FILE DESCRIPTION LINE. This is the 8th item on the line that contains the file name for the modified field. Extreme care should be taken in making any of these changes. It is safer to just run DBDEF to re-define the data base. 6.2 MODIFYING THE OPERATIONAL SUBROUTINES Only try changes to the Operational Subroutines after you have had a fair amount of experience with the PDS*BASE Data Base System. 6.2.1 CHANGING THE NAME OF THE DATA BASE AS IT IS USED IN THE "MAIN PROGRAMS" Adjust the value (in quotes) for the variable ZB$ in line 60. PAGE 50 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 6.2.2 NOT OPENING ALL FILES Add an IF statement at line 305. If you don't wish to open files 3 and 4, for instance: 305 IF Z1=3 OR Z1=4 GOTO 370 Add a similar IF statement at 415: 415 IF Z1=3 OR Z1=4 GOTO 440 6.2.3 CHANGING THE MASTER FILE SEARCH FIELD Only do this if you are quite experienced in the PDS*BASE System. The search string test is set up in line 650. The variable ZL$ is set equal to the first data field ( Y$(1,ZA) ). A different field could be used by changing the value of ZTESTFLD (to something other than field 1) in line 610, or you could concatenate several fields for a particular file. Be sure that all of the concatenated fields are defined as Required fields with the DBDEF program. This change would have to be made to ALL of the programs used for this data base. If you are concatenating fields for the search string, the fields MUST be concatenated BEFORE GOSUB 500 MAIN PROGRAM. In the following example, file #1 fields 1 and 2 are concatenated, and these lines would be added in the MANAGEMENT program: 2122 IF ZM=1 THEN PRINT "THEN ENTER "; ZN$(ZM,2,1) : the remainder is the same as 2120 Add the same statement at line 2222. Add a similar statement at line 2332 (using ZA rather than ZM) 2332 IF ZA=1 THEN PRINT "THEN ENTER "; ZN$(ZA,2,1); : the remainder is the same as 2330 Add line 2142: 2142 ZR$=ZR$+ZI$(2,ZA) It is not usually necessary to make changes to the REPORT programs when concatenating the search string for a Master file. PAGE 51 Version 3.2 6.3 PDS*BASE DATA BASE SYSTEM Copyright 1985 MODIFYING THE MANAGEMENT PROGRAM Modifying the search string was covered previously. 6.3.1 ONLY ALLOWING ACCESS TO CERTAIN FILES If you modified the Operational Subroutines to open only certain files, add an IF statement at 2048 to insure that a proper "Main Menu" option was entered. For example, if only files 1 and 3 are used by a program, then: 2048 IF YC <> 1 AND YC <> 3 GOTO 2010 If only one file is used in a program remove the "Main Menu", as such, and set YC equal to the desired file number. Be sure to have a way to get out of the program at the end of the session. ********************************* * * * YOU MUST GOTO 400 AT THE END * * * * OF THE PROGRAM TO CLOSE FILES * * * ********************************* If you modify the Management program and it doesn't close the files at 400, the "Records Assigned" values and the Detail file "Next Vacant Record" pointers will be cobbled up. (Head for Sibera, do not pass GO, do not collect $200). 6.3.2 AUTOMATIC ENTRY OF CERTAIN FIELDS For example, you wish to post stock items received in the Example Inventory data base. Insert line 2015 as follows: 2015 INPUT "ENTER TODAY'S DATE";DT$ : IF DT$ = "" GOTO 400 Since we are posting items received, the program will be dealing with file number 1 (for the STOCK Master) and file number 3 for items RECEIVEd. At line 2130 ZA will be 3 and the DATE field is field number 1. Thus, add line 2132 as follows: 2132 IF ZI = 1 THEN MID$(ZI$(ZI,ZA),1,VAL(LEN(DT$))) = DT$ : GOTO 2137 PAGE 52 Version 3.2 6.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 MODIFYING THE REPORT PROGRAM 6.4.1 ADDING MATH LINES FOR EACH REPORT LINE If you are multiplying the value of one field by the value of another field, there are several places that it can be done. Remember, you may have specified a "Special Field" when you ran the DBREPORT program generator. If all of the fields being multiplied are in the report line, insert the math line between lines 4000 and 4015. Be sure to use the STR$ function to transfer the results into the proper position of the YT$ buffer array. If some of the fields are not in the report line, the following locations may be used: 2432 for Master records 2478 for the "First Read" Detail record 2532 for "Additional" Detail records 6.4.2 CREATING REPORT TOTALS Report Total variables the above lines. can be added to in any of The best place for the Report Total to be printed is by adding a PRINT statement at line 2610. 6.4.3 CHANGING COLUMN TAB VALUES Just change the value of the 5th item in the statements starting at line 2360. The statements are in the order that the report is printed. To cause a line feed, set the item in the DATA statement to a "1". DATA DATA line 10th PAGE 53 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 6.4.4 MODIFYING THE SORT FIELDS You can always use the SORT program to generate multi-field sorts. However, all of the fields in the sort must be in the same Master file as the first field in the report. It may be desired to generate special report programs that have built-in multi-field sorts without the necessity of running the SORT program. You may also wish to have one of the sort fields obtained from a Master file different than the Master file containing the first report field. This is all possible by adding several custom lines in the REPORT program generated by the DBREPORT program generator. The first example will show a multi-field sort for the Example Inventory data base where all of the sort fields are in the STOCK Master file. Change line 2100 to remove the "YA$(Z5)=Y$(1,ZA)". Assuming that we wish to sort on the DESCRIPTION (major) and then the PART NUMBER (minor) fields. These are fields 2 and 1 (in that order). Add line 2105: 2105 YA$(Z5) = Y$(2,ZA) + YA$(1,ZA) In the second example we wish to have the SUPPLIER NAME (file 5, field 2) be the major sort field and the DESCRIPTION (file 1, field 2) be the minor sort field. Again, remove the "YA$(Z5)=Y$(1,ZA)" FROM LINE 2100. Add line 2105: 2105 YA$(Z5)=Y$(2,ZA) : ZR$=Y$(3,ZA) : ZZ=1 : ZA=5 : GOSUB 500 : GOSUB 600 : YA$(Z5)=Y$(2,ZA)+YA$(Z5) : ZA=1 The sort array ( YA(Z5) ) is set equal to the value of the DESCRIPTION. The search string ZR$ is set to the value of the SUPPLIER CODE found in field 3 of the STOCK Master. ZA is set to the file number (5) of the SUPPLIER Masters, GOSUB 500 is called to find the desired SUPPLIER record number and GOSUB 600 is called to read the desired SUPPLIER Master record. YA$(Z5) then has the SUPPLIER NAME concatenated to the front. Last, ZA is set back to 1 for the next pass through the 2050-2120 FOR-NEXT loop when it will be desired to first read the STOCK Master (file 1) again. PAGE 54 Version 3.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 7.0 DOING YOUR OWN THING If you are a good BASIC programmer, you will probably write your own "Main" programs. You will find that they will be more compact and flexible then the programs generated by the PDS*BASE Program Generators. This is because the Program Generators are trying to be "All Things To All People". Before you start, keep in mind the function of the following subroutines: 300 - OPEN THE DATA BASE FILES 400 - CLOSE THE DATA BASE FILES 500 - CALCULATE A MASTER RECORD NUMBER 600 - DIRECT READ A SELECTED RECORD 700 - UPDATE A RECORD USING THE Y$ BUFFER 750 - UPDATE A RECORD USING THE ZI$ BUFFER 800 - CREATE A NEW MASTER RECORD 1000 - CREATE A NEW DETAIL RECORD 1200 - DELETE A SELECTED MASTER RECORD 1300 - DELETE A SELECTED DETAIL RECORD There are rules for passing variables to the subroutines that must be followed. These rules, and program examples, will be covered in the following sections. IT IS SUGGESTED THAT YOU REMOVE PAGES 24 AND 25 FROM THE MANUAL FOR READY REFERENCE IN THE FOLLOWING PROGRAM EXAMPLES. ASSUME THAT THE SUBROUTINES FROM LINE 10 TO 2000 HAVE BEEN CREATED WITH THE DBOPSUB PROGRAM GENERATOR. 7.1 CALCULATE A MASTER RECORD NUMBER ZA must be set to the number of the data set or file number containing the desired record. The Set # can be found on the Data Base Description printed by the DBDEF program. ZR$ must be set to the string variable that contains the desired search string. PAGE 55 Version 3.2 7.1 PDS*BASE DATA BASE SYSTEM Copyright 1985 CALCULATE A MASTER RECORD NUMBER (continued) After the "GOSUB 500", ZR will be RETURNed containing the desired record number to be read. For example, assume that you have the INVENTRY Data Base as described on Pages 24 and 25, and that you have a main program where you have asked for key board input for the PARTNUM$ and you wish to read that master record. Also assume that the master Set containing the Part Number masters is Set #1: 2150 INPUT "ENTER THE PART NUMBER";PARTNUM$ 2160 IF PARTNUM$="" THEN 400 2170 ZA=1 'THE SET NUMBER 2180 ZR$=PARTNUM$ : GOSUB 500 'CALC THE REC NUM. 2190 GOSUB 600:IF ZV=1 THEN 2150 'READ THE RECORD 2200 PRINT "THE DESCRIPTION=";Y$(2,ZA) 7.2 DIRECT READ A SELECTED RECORD The above example showed how to find the desired record based on a search string value. After the GOSUB 500 the value of ZA and ZR were passed to the subroutine at 600 to find the record with the selected search string. If ZV=1, the desired Master was not found. Line 680 prints a "Not Found" error message. To complete this example, assume that the second field in Set #1 contains the description. Thus, line 2200 printed the second field in the selected record. All of the fields in a selected record will always be in the Y$(X,ZA) array. If you desire to read a particular record number, not based on a search string value, set ZA to the desired Set number, ZR to the desired record number and ZZ=1. Then call GOSUB 610. By setting ZZ=1 and calling the subroutine at 610 rather than 600, the subroutine will read the desired record and RETURN without testing the first field in the Y$ buffer for a search string match. PAGE 56 Version 3.2 7.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DIRECT READ A SELECTED RECORD (continued) Normally, this feature of reading by a record number, rather than a search string is used when reading DETAIL records. For example, assume have read the above Master record for the selected PARTNUM$ and that you wish to locate the price for a part received on a particular date. Continuing the previous program example: 2210 INPUT "ENTER THE DESIRED DATE";DT$ 2220 ZR=ZH(2) 'ZH(2) CONTAINS THE DETAIL CHAIN HEAD FOR THE SECOND DETAIL SET (RECEIVED) FOR THE STOCK MASTER 2230 ZZ=1 : ZA=3 'FOR SET #3 2240 GOSUB 610 'READ THE DESIRED DETAIL RECORD 2250 IF DT$=Y$(1,3) THEN 2290 'TEST FOR DATE MATCH 2260 IF ZF>0 THEN ZR=ZF : GOTO 2230 'ZF IS THE FORWARD POINTER TO THE NEXT DETAIL RECORD IN THE CHAIN 2270 REM ** WHEN ZF IS ZERO, THE END OF THE CHAIN HAS BEEN REACHED 2280 BEEP : PRINT "SELECTED DATE NOT FOUND" : GOTO 2150 2290 REM *** THE SELECTED DATE WAS FOUND 2300 PRINT "PART NUMBER ";PARTNUM$; "RECEIVED ON ";DT$;" HAS A PRICE OF ";Y$(3,3) 2310 GOTO 2150 Note that the record number for the chain head was contained in ZH(2) after the GOSUB 600 in line 2190. Line 665 of the subroutine establishes all of the chain head (ZH(X)) and the chain end ((ZE(X)) pointers for the Master record just read (see Appendix A for the subroutine listings). PLEASE NOTE that the chain head pointer for set #3 is contained in ZH(2). This is because it is the SECOND detail set for the STOCK master. ZF (from line 660 of Appendix A) contains the forward pointer to the next record in the detail chain for the selected master. PAGE 57 Version 3.2 7.2 PDS*BASE DATA BASE SYSTEM Copyright 1985 DIRECT READ A SELECTED RECORD (continued) If you had wished to search backward through the Detail chain, substitute ZE(2) for ZH(2) in line 2220 and substitute ZB for ZF in line 2260. This is handy if you are looking for a recently posted record that would likely be at or near the end of the Detail chain. 7.3 UPDATE A RECORD USING THE Y$ BUFFER Care should be taken in using the subroutine at 700. The Y$ buffer was defined in the FIELD statements in lines 325 and 326. REMEMBER the rules for a variable defined as being in a random file buffer. You can't use the variable on the left of an equal sign without using the RSET or LSET functions. If you break this GW BASIC rule the Y$ variable will be assigned a new string space location in memory the random file buffer. and it will no longer be in Normally you will use the subroutine at 750, that uses the ZI$ buffer. 7.4 UPDATE A RECORD USING THE ZI$ BUFFER Assume that you wish to write a "Main Program" to build SUPPLIER records in the INVENTRY Data Base. The following example uses the simple scrolling screen method. You may have your own "View" or "Fixed" screen method. 2010 CLS:PRINT "PROGRAM TO CREATE SUPPLIER MASTERS":PRINT 2020 ZA=5 ' SET #5 FOR THE SUPPLIER MASTERS 2030 FOR J=1 TO 6 2040 PRINT "ENTER THE ";ZN$(ZA,J,2); 2050 INPUT ZI$(J,ZA) 2060 IF J=1 THEN IF ZI$(J,ZA)="" THEN 2110 2070 PRINT 2080 NEXT J 2090 ZR$=ZI$(1,ZA):GOSUB 800 'CREATE THE RECORD PAGE 58 Version 3.2 7.4 PDS*BASE DATA BASE SYSTEM Copyright 1985 UPDATE A RECORD USING THE ZI$ BUFFER (continued) 2100 PRINT:GOTO 2030 'INPUT THE NEXT RECORD 2110 PRINT "ARE YOU FINISHED ? ";:COLOR 0,7:PRINT "Y";:COLOR 7,0:LOCATE ,POS(0)-1,1:A$=INPUT$(1):PRINT A$:IF ASC(A$)=13 THEN A$="Y" 2120 IF A$="Y" THEN 400 2130 GOTO 2030 Line 2020 sets ZA to 5, so that all of the all of the statements that deal with ZA will know that we are dealing with Set #5 for the SUPPLIER Masters. Line 2030 starts the FOR-NEXT fields for the SUPPLIER Master. loop to input the 6 Line 2040 displays the name of the field that is contained in ZN$(ZA,J,1). This variable was established in the READ statement in line 215 (see Appendix A). Line 2050 INPUTs the data into ZI$(J,ZA). Line 2060 tests to see if a supplier code was entered. If RETURN was depressed, without entering key board data, we will branch to 2110 to end the program. LINE 2090 Code) and record. SETS then ZR$ equal to the first field (Supplier GOSUBs 800 to create the new Master Line 2100 loops back to again for the next master. start the process all over That's all there is to it. The PDS*BASE generated programs are more complicated, as they are trying to cover all situations. You can make simpler programs for many applications. 7.5 CREATE A NEW MASTER RECORD As you saw in Section 7.3, we created a Master record. Just remember, that before you GOSUB 800, set ZA to the Set #, set ZR$ to the search field and that all of the data for the record is in the ZI$(X,ZA) buffer. PAGE 59 Version 3.2 7.6 PDS*BASE DATA BASE SYSTEM Copyright 1985 CREATE A NEW DETAIL RECORD First, you must find the Master record for the Detail chain pointers. The following example assumes that we wish to add new parts on order to the ORDER data set: 2150 PRINT "ENTER THE PART NUMBER";PARTNUM$ 2160 IF PARTNUM$="" THEN 400 'ALL DONE 2170 ZA=1:ZR$=PARTNUM$:GOSUB 500:GOSUB 600 'FIND THE MASTER FOR THE PART NUMBER IN FILE #1 2180 IF ZV=1 THEN 2150 'MAKE SURE THE MASTER WAS FOUND 2190 ZM=1:YM=ZR 'SAVES THE MASTER FILE NUMBER AND THE MASTER RECORD NUMBER FOR USE LATER IN THE 1000 SUBROUTINE 2200 ZA=2 'THE SET NUMBER FOR THE ORDER DETAIL RECORDS 2210 PRINT:FOR J=1 TO 3 2220 PRINT "ENTER THE ";ZN$(ZA,J,1); 2230 INPUT ZI$(J,ZA) 2240 IF J=1 THEN IF ZI$(J,ZA)="" THEN 2150 'IF NOTHING INPUT FOR 1ST FIELD, GO FIND THE NEXT MASTER 2260 NEXT J 2270 ZS=ZA 'SET ZS TO THE DETAIL SET NUMBER 2280 GOSUB 1000 'CREATE THE DETAIL RECORD. IT WILL BE APPENDED TO THE END OF THE CHAIN. 2290 GOTO 2210 'INPUT THE NEXT DETAIL RECORD FOR THE SAME MASTER Lines 2190 and 2270 are VERY IMPORTANT as ZM, YR AND ZS MUST be set up before you GOSUB 1000 to create the Detail record. PAGE 60 Version 3.2 7.7 PDS*BASE DATA BASE SYSTEM Copyright 1985 DELETE A SELECTED MASTER RECORD Deleting a Master record is easy to write into a "Main Program", although, the subroutine at 1200 has to do a lot of work. 2150 INPUT "ENTER THE PART NUMBER TO BE DELETED";PARTNUM$ 2160 IF PARTNUM$="" THEN 400 'ALL DONE 2170 ZA=1:ZR$=PARTNUM$:GOSUB 500:GOSUB 600 'FIND THE RECORD NUMBER AND READ THE RECORD 2180 IF ZV=1 THEN 2150 'TEST TO SEE IF MASTER EXISTED. ERROR MESSAGE PRINTED BY LINE 680. 2190 PRINT:PRINT "DESCRIPTION=";Y$(2,ZA) 2200 PRINT "DO YOU WISH TO DELETE ";:COLOR 0,7:PRINT "N";:COLOR 7,0:LOCATE ,POS(0)-1,1:A$=INPUT$(1):PRINT A$:IF ASC(A$)=13 THEN A$="N" 2210 IF A$="Y" THEN GOSUB 1200 'DELETE THE RECORD 2220 GOTO 2150 Line 2200 is a fancy way of asking a "Yes/No" question. The default answer, "N" in this case, is shown in inverse video. The "N" implies that a "N" would abort the delete process. If RETURN is depressed, the implied value of "N" (in this case) is placed in A$. PAGE 61 Version 3.2 1985 7.8 PDS*BASE DATA BASE SYSTEM Copyright DELETE A SELECTED DETAIL RECORD The following example is very similar to the example in Sections 7.1 and 7.2, where we located a selected Detail record. We will just add several lines to actually delete the record. 2150 INPUT "ENTER THE PART NUMBER";PARTNUM$ 2160 IF PARTNUM$="" THEN 400 2170 ZA=1 'THE SET NUMBER 2180 ZR$=PARTNUM$ : GOSUB 500 'CALC THE REC NUM. 2190 GOSUB 600:IF ZV=1 THEN 2150 'READ THE RECORD 2195 ZM=1:YM=ZR '***** ADDED LINE ***** 2200 PRINT "THE DESCRIPTION=";Y$(2,ZA) 2210 INPUT "ENTER THE DESIRED DATE";DT$ 2220 ZR=ZH(2) 'ZH(2) CONTAINS THE DETAIL CHAIN HEAD FOR THE SECOND DETAIL SET (RECEIVED) FOR THE STOCK MASTER 2230 ZZ=1 : ZA=3 'FOR SET #3 2240 GOSUB 610 'READ THE DESIRED DETAIL RECORD 2250 IF DT$=Y$(1,3) THEN 2290 'TEST FOR DATE MATCH 2260 IF ZF>0 THEN ZR=ZF : GOTO 2230 'ZF IS THE FORWARD POINTER TO THE NEXT DETAIL RECORD IN THE CHAIN 2270 REM ** WHEN ZF IS ZERO, THE END OF THE CHAIN HAS BEEN REACHED 2280 BEEP : PRINT "SELECTED DATE NOT FOUND" : GOTO 2150 2290 REM *** THE SELECTED DATE WAS FOUND 2300 PRINT "PART NUMBER ";PARTNUM$; "RECEIVED ON ";DT$;" HAS A PRICE OF ";Y$(3,3) PAGE 62 Version 3.2 7.8 PDS*BASE DATA BASE SYSTEM Copyright 1985 DELETE A SELECTED DETAIL RECORD (continued) 2302 PRINT:PRINT "DO YOU WISH TO DELETE ? ";:COLOR 0,7:PRINT "N";:COLOR 7,0:LOCATE ,POS(0)-1,1 :A$=INPUT$(1) :PRINT A$: IF ASC(A$)=13 THEN A$="N" '*****ADDED LINE***** 2304 IF A$="Y" THEN ZS=ZA:YS=ZR:GOSUB 1300 '***** ADDED LINE ***** 2310 GOTO 2150 Note that we only added three lines to the previous example. Line 2195 stores the values of ZM and YM for later use. Line 2302 asks if the Detail record should be deleted. Line 2304 sets ZS to ZA (the number of the detail set) sets YS to the actual Detail record number in the Detail set and GOSUBs 1300 to delete the record. IT IS VERY IMPORTANT TO SET THE VALUES OF ZM, YM, ZS AND YS BEFORE THE SUBROUTINE AT 1300 IS USED. FAILURE TO SET THESE 4 VARIABLES TO THE CORRECT VALUES WILL GET YOU DISASTER (at least)! If you follow the rules as outlined in this chapter, you should find it easy to "Go It" on your own. GOOD LUCK !!!! PAGE 63 PDS*BASE SYSTEM APPENDIX A Copyright 1985 LISTING OF SAMPLE INVENTORY DATA BASE MANAGE PROGRAM 10 REM *** PROGRAM 'TESTMAN.BAS' *** 20 REM 30 REM *** THIS PROGRAM OPERATES AGAINST A PDS*BASE DATA BASE 35 REM ** ALMOST ALL VARIABLES WILL START WITH THE LETTER Y OR Z TO ALLOW YOU TO USE ANY OTHER VARIABLE NAME. ** 40 KEY OFF 45 ZBLANK$=STRING$(255,32) : ZFOPEN=0 'SETS UP A VARIABLE OF 255 BLANKS AND SETS OPEN SORT FILE FLAG TO ZERO 50 REM *** OPEN THE DATA BASE FILES *** 60 CLS:ZO$=CHR$(44):ZB$="INVENTRY":ZQ= 5 REM COMMA, BASE NAME, NUMBER OF FILES 65 '**** BE SURE TO START BASIC WITH THE COMMAND EXTENDERS AS FOLLOWS: 'BASIC/F:5' AS YOU HAVE MORE THAN 3 FILES 70 DIM ZS$(5,4),ZS%(5,10),ZT%(5,1,4),ZDATE$(5),ZTIME$(5), ZCHGFLAG( 5 ),ZH( 3 ),ZE( 3 ),ZH$( 5 , 3 ),ZE$( 5 , 3 ) 71 REM ZS$(X,Y) Y=1 IS NAME OF SET, Y=2-10 IS NAME OF ASSOCIATED SETS 72 REM ZS%(X,1)=SET TYPE (1=MASTER, 2=DETAIL) 73 REM ZS%(X,2)=SET CAPACITY (NUMBER OF RECORDS) 74 REM ZS%(X,3)=RECORD SIZE OR WIDTH 75 REM ZS%(X,4)=NUMBER OF ASSOCIATED SETS 76 REM ZS%(X,5)=NUMBER OF DRIVES REQUIRED 77 REM ZS%(X,6)=NUMBER OF RECORDS ASSIGNED 78 REM ZS%(X,7)=NUMBER OF VARIABLES IN THE SET 79 REM ZS%(X,8)=POINTER TO NEXT RECORD TO BE CREATED IF A DETAIL FILE 80 REM ZS%(X,9)=1 IF A COMPANION ACTIVE/SORT FILE IS PRESENT 81 REM ZS%(X,10)= UNASSIGNED AT THIS TIME 83 REM FOR MULTI-DISC FILES THE LOCATION OF RECORDS IS LOCATED IN ZT%(X,Y,Z). THE FILE NAME WILL BE THE SAME, WITH THE PROGRAM KEEPING TRACK OF THE CORRECT FILE BUFFER NUMBER FOR THE APPROPRIATE DRIVE. 84 REM ZT%(X,Y,Z) X=SET NUMBER 85 REM Y=FILE SECTION NUMBER (MULTI-DISC FILES) 86 REM Z=1 = STARTING RECORD 87 REM Z=2 = ENDING RECORD 88 REM Z=3 = DRIVE 1=A AND 2=B 89 REM Z=4 = FILE BUFFER NUMBER FOR THIS SECTION 90 DIM ZI$( 6 , 5 ),Y$( 6 , 5 ),ZC$( 5 ),ZP$( 5 ),ZNEXT$( 5 ), ZB$( 5 ),ZF$( 5 ) 'INPUT AND BUFFER ARRAYS 100 FOR Z1=1 TO 5 105 READ ZS%(Z1,1),ZS%(Z1,2),ZS%(Z1,3),ZS%(Z1,4),ZS%(Z1,5), ZS%(Z1,7),ZS%(Z1,9),ZS$(Z1,1) 110 IF ZS%(Z1,4) > 0 THEN FOR Z2=1 TO ZS%(Z1,4) : READ ZS$(Z1,Z2+1):NEXT Z2 120 FOR Z2=1 TO ZS%(Z1,5) : READ ZT%(Z1,Z2,1),ZT%(Z1,Z2,2), ZT%(Z1,Z2,3),ZT%(Z1,Z2,4) : NEXT Z2 125 NEXT Z1 130 DATA 1 , 50 , 80 , 3 , 1 , 5 , 0 131 DATA "STOCK.DAT","ORDER.DAT","RECEIVED.DAT","USED.DAT" PAGE A - 1 PDS*BASE SYSTEM 132 133 134 135 136 137 138 139 140 141 142 143 144 200 205 210 215 220 221 222 223 224 225 300 304 305 310 315 320 322 324 325 326 330 APPENDIX A Copyright 1985 DATA 1 , 50 , 2 , 1 DATA 2 , 100 , 32 , 1 , 1 , 3 , 0 DATA "ORDER.DAT","STOCK.DAT" DATA 1 , 100 , 2 , 2 DATA 2 , 100 , 32 , 1 , 1 , 3 , 0 DATA "RECEIVED.DAT","STOCK.DAT" DATA 1 , 100 , 2 , 3 DATA 2 , 100 , 32 , 1 , 1 , 3 , 0 DATA "USED.DAT","STOCK.DAT" DATA 1 , 100 , 2 , 4 DATA 1 , 10 , 92 , 0 , 1 , 6 , 0 DATA "SUPPLIER.DAT" DATA 1 , 10 , 2 , 5 DIM ZN$( 5 , 6 ,2), ZSIZE%( 5 , 6 ) FOR ZI=1 TO 5 FOR ZJ=1 TO ZS%(ZI,7) READ ZN$(ZI,ZJ,1),ZN$(ZI,ZJ,2),ZSIZE%(ZI,ZJ):NEXT ZJ:NEXT ZI DATA "PART NUMBER","RC",10,"DESCRIPTION","RC",15,"SUPPLIER CODE","RI",2,"MAXIMUM","OI",4,"MINIMUM","OI",4 DATA "DATE","RC",8,"QUANTITY","RI",4,"PRICE","RR",10 DATA "DATE","RC",8,"QUANTITY","RI",4,"PRICE","RR",10 DATA "DATE","RC",8,"QUANTITY","RI",4,"PRICE","RR",10 DATA "SUPPLIER CODE","RI",2,"SUPPLIER NAME","RC",15,"STREET ADDRESS","OC",15,"CITY STATE AND ZIP","OC",15,"CONTACT NAME","OC",15,"TELEPHONE NUMBER","OC",15 REM ALL VARIABLE INFORMATION LOADED PRINT TAB(27)"PDS*BASE DATA BASE SYSTEM":PRINT:PRINT:PRINT TAB(21)"INSERT DATA DISC(S) AND PRESS ANY KEY"; : YQ$=INPU T$(1) : PRINT PRINT:PRINT "IF YOU SEE 'Bad file number in 322', RESTART BASIC AS 'BASIC/F:6/S:92'" Z5=0 FOR Z1=1 TO 5 Z2=1 ZF$=MID$("ABCDE",ZT%(Z1,Z2,3),1)+":"+ZS$(Z1,1) 'add correct drive letter. This is a DBOPSUB option OPEN ZF$ AS ZT%(Z1,Z2,4) LEN=ZS%(Z1,3) : YC1=0 : YC2=0 : YC 3=0 : YC4=0 IF ZS%(Z1,1)=1 THEN FIELD ZT%(Z1,Z2,4), 5 AS ZC$(Z1), 5 AS ZP$(Z1), 5 AS ZNEXT$(Z1) : YC1=15 IF ZS%(Z1,1)=2 THEN FIELD ZT%(Z1,Z2,4), 5 AS ZB$(Z1), 5 AS ZF$(Z1) : YC1=10 IF ZS%(Z1,1)=1 AND ZS%(Z1,4)>0 THEN FOR Z3=1 TO ZS%(Z1,4) : FIELD ZT%(Z1,Z2,4), YC1 AS DUMMY1$, 5 AS ZH$(Z1,Z3), 5 AS ZE$(Z1,Z3) : YC1=YC1+10 : NEXT Z3 FOR Z3=1 TO ZS%(Z1,7) : Y0=ZSIZE%(Z1,Z3) : FIELD ZT%(Z1,Z2, 4), YC1 AS DUMMY1$, YC2 AS DUMMY2$, YC3 AS DUMMY3$, YC4 AS DUMMY4$, YC5 AS DUMMY5$, Y0 AS Y$(Z3,Z1) 331 IF YC1+Y0<256 THEN YC1=YC1+Y0 ELSE IF YC2+Y0<256 THEN YC2=Y C2+Y0 ELSE IF YC3+Y0<256 THEN YC3=YC3+Y0 ELSE IF YC4+Y0<25 6 THEN YC4=YC4+Y0 ELSE YC5=YC5+Y0 332 NEXT Z3 PAGE A - 2 PDS*BASE SYSTEM APPENDIX A Copyright 1985 335 IF ZS%(Z1,1)=1 THEN GET ZT%(Z1,Z2,4),ZS%(Z1,2)+1:ZS%(Z1,6)= VAL(ZC$(Z1)) : ZDATE$(Z1)=ZP$(Z1) : ZTIME$(Z1)=ZNEXT$(Z1 ) 'ZDATE$ & ZTIME $ GIVE DATE AND TIME THIS MASTER FILE WAS LAST CHANGED 337 IF ZS%(Z1,1)=2 THEN GET ZT%(Z1,Z2,4),ZS%(Z1,2)+1:ZS%(Z1,6)= VAL(ZB$(Z1)) : ZS%(Z1,8)=VAL(ZF$(Z1)) 341 IF ZS%(Z1,6)=ZS%(Z1,2) THEN PRINT CHR$(7);"WARNING - THE "; ZS$(Z1,1) : PRINT "DATA FILE IS FULL." : FOR Z2=1 TO 3000 : NEXT Z2 342 IF ZS%(Z1,1)=1 GOTO 370 343 ZR=ZS%(Z1,8) : IF ZR=0 THEN Z5=1 : GOTO 360 344 ZA=Z1 : ZZ=1 : ZR=ZS%(Z1,8) : GOSUB 610 : Z5=0 : FOR Y1=1 TO ZS%(ZA,7) : IF Y$(Y1,Z1) <> LEFT$(ZBLANK$,ZSIZE%(Z1,Y1)) THEN Z5=1 345 NEXT Y1 360 IF Z5>0 THEN PRINT CHR$(7);"WARNING - THE DETAIL FILE POINTERS IN":PRINT ZF$;" ARE IN ERROR. RUN THE UTILITY PROGRAM TO FIX." :PRINT :PRINT TAB(15)"(PRESS ANY KEY TO CONTINUE) ";:ZQ$=INPUT$(1):PRINT 370 NEXT Z1 380 GOTO 2000:REM TO THE MAIN PROGRAM 400 REM ** CLOSE ALL FILES ** 405 Z2=1 410 FOR Z1=1 TO 5 402 IF ZREPTFLAG<>1 THEN 455 'this line only in report programs 420 IF ZS%(Z1,1)=1 THEN RSET ZC$(Z1)=STR$(ZS%(Z1,6)) : ELSE RSET ZB$(Z1)=STR$(ZS%(Z1,6)) : RSET ZF$(Z1)=STR$(ZS%(Z1,8)) 425 IF ZS%(Z1,1)=1 AND ZCHGFLAG(Z1)=1 THEN RSET ZC$(Z1)= STR$(ZS%(Z1,6)):LSET ZP$(Z1)=LEFT$(DATE$,2)+ MID$(DATE$,4,2)+RIGHT$(DATE$,1) : LSET ZNEXT$(Z1)=LEFT$(TIME$,5) ELSE LSET ZP $(Z1)=ZDATE$(Z1) : LSET ZNEXT$(Z1)=ZTIME$(Z1) 430 PUT ZT%(Z1,Z2,4),ZS%(Z1,2)+1 : CLOSE ZT%(Z1,1,4) 440 NEXT Z1 445 CLOSE : IF ZQ=1 THEN PRINT 450 PRINT "ALL DONE" 460 REM END OF PROGRAM 480 END : REM ** ALL DONE ** if you wish to return to DOS, replace END with SYSTEM. If you have a menu program, substitute RUN followed by the menu program name in quotes. PAGE A - 3 PDS*BASE SYSTEM APPENDIX A Copyright 1985 500 REM ** SUBROUTINE TO CALCULATE THE RANDOM ACCESS RECORD NUMBER ** 502 REM 504 REM BEFORE CALLING THIS SUBROUTINE, ZA MUST=THE NUMBER OF THE DATA SET. SET ZR$=THE SEARCH ITEM. IF NECESSARY CONVERT INTEGER OR REAL SEARCH ITEMS TO A STRING FOR ZR$. 505 ZTESTFLD=1 'CHANGE THIS IF YOU ARE USING SEARCH FIELD OTHER THAN THE 1st FIELD. ALSO SEE LINE 610 506 REM 510 Z3=0:Z1=LEN(ZR$):Z2=ZS%(ZA,2) 520 FOR Z4=1 TO Z1:Z44=Z4:IF Z1>12 THEN Z44=1/Z4 'better random spread if length of search string>12 . New with Version 3.1 522 Z0=ASC(MID$(ZR$,Z4,1)):IF Z0<>32 THEN Z0=Z0*Z44: Z3=Z3+(Z0*Z0*Z0) 'This line changed with Version 3.11 525 NEXT 530 ZR=INT(Z3-(Z2*(INT((Z3-1)/Z2)))) : IF ZR<=0 THEN ZR=1 535 IF Z1<ZSIZE%(ZA,ZTESTFLD) THEN ZR$=ZR$+STRING$((ZSIZE%(ZA,T ESTFLD)-Z1),32) 'PADS BLANKS IF NECESSARY TO MAKE SURE THE SEARCH STRING IS THE PROPER LENGTH FOR TESTING IN LINE 675 540 RETURN 550 REM 600 REM ** SUBROUTINE TO DIRECT READ A DATA SET **R=THE DESIRED RECORD NUMBER (FROM SUBROUTINE AT 500). IF A MASTER IS BEING READ ZR$=THE SEARCH ITEM VALUE. Y$(X,ZA) RETURNED WITH THE DATA. 605 ZZ=0 : YZ=0 : Z1=ZR : REM WHEN THIS SUBROUTINE IS CALLED 610 630 635 650 660 665 666 670 671 672 673 FROM 800 OR 1300 SUBROUTINES THEN ZZ WILL=1 AND RETURN WILL BE AT 665. YR=ZR:Y1=1:ZTESTFLD=1:IF ZS%(ZA,5)=1 AND YZ=1 THEN YZ=0 :RETURN 'CHANGE ZTESTFLD IF YOU ARE USING A FIELD OTHER THAN THE 1st FIELD FOR THE SEARCH FIELD. ALSO SEE LINE 505 GET ZT%(ZA,Y1,4),YR ZV=0:REM ZV=0 IF RECORD FOUND AND ZV=1 IF RECORD NOT FOUND ZL$=Y$(ZTESTFLD,ZA) IF ZS%(ZA,1)=2 THEN ZB=VAL(ZB$(ZA)) : ZF=VAL(ZF$(ZA)) IF ZS%(ZA,1)=1 THEN ZC=VAL(ZC$(ZA)) : ZP=VAL(ZP$(ZA)) : ZN=VAL(ZNEXT$(ZA)) IF ZS%(ZA,1)=1 AND ZS%(ZA,4)>0 THEN FOR Y24=1 TO ZS%(ZA,4) :ZH(Y24)=VAL(ZH$(ZA,Y24)):ZE(Y24)=VAL(ZE$(ZA,Y24)):NEXT Y24 REM ** IF A DETAIL DATA SET, ZB=THE BACKWARD POINTER AND ZF =THE FORWARD POINTER. IF A MASTER, ZC=NUMBER OF SECONDARY MASTERS, ZP=PREVIOUS SECONDARY POINTER, ZN=NEXT SECONDARY MASTER REC # POINTER. REM ** WITH A MASTER, ZH(X)=THE CHAIN HEAD OF THE XTH DETAIL SET CHAIN AND ZE(X)=THE CHAIN END OF THE XTH CHAIN. IF ZS%(ZA,1)=2 THEN RETURN 'NEED NO FURTHER INFO FOR A DETAIL SET. IF ZR$=LEFT$(ZBLANK$,ZSIZE%(ZA,ZTESTFLD)) OR ZZ=1 THEN ZZ=0 : RETURN 'IT'S A MASTER BUT, NO TEST FOR SEARCH ITEM IS DESIRED. PAGE A - 4 PDS*BASE SYSTEM APPENDIX A Copyright 1985 674 REM ** TEST FOR SEARCH ITEM ** 675 IF ZL$=ZR$ THEN RETURN 'FOUND IT! IF YOU ARE HAVING TROUBLE FINDING A MATCH, SEE LINE 535. YOUR STRING LENGTHS MUST BE THE SAME. 680 IF ZN=0 THEN PRINT CHR$(7);"NO MASTER FOR ";ZR$;" IN THE DATA BASE." : ZV=1 : RETURN 685 ZR=ZN : GOTO 610 : REM LOOK AT THE NEXT SECONDARY MASTER 695 REM 700 REM ** SUBROUTINE TO UP-DATE OR CREATE A RECORD USING Y$(X,ZA) BUFFER ** 701 REM ** BE SURE THAT 'ZA'=THE NUMBER OF THE DATA SET AND ZR= THE DESIRED RECORD NUMBER 710 IF ZS%(ZA,1)=1 THEN RSET ZC$(ZA)=STR$(ZC) :RSET ZP$(ZA)=STR$(ZP): RSET ZNEXT$(ZA)=STR$(ZN) : IF 720 730 740 750 751 760 770 780 790 800 801 805 810 820 825 830 835 840 850 ZS%(ZA,4)>0 THEN FOR Y24=1 TO ZS%(ZA,4) : RSET ZH$(ZA,Y24)=STR$(ZH(Y24)) : RSET ZE$(ZA,Y24)= STR$(ZE(Y24)) : NEXT Y24 IF ZS%(ZA,1)=2 THEN RSET ZB$(ZA)=STR$(ZB):RSET ZF$(ZA)=STR$(ZF) ' THE DATA MUST BE IN Y$(X,ZA) PUT ZT%(ZA,Y1,4), ZR : RETURN 'WRITE THE RECORD REM ** SUBROUTINE TO UP-DATE OR CREATE A RECORD USING ZI$(X) VARIABLES ** REM ** BE SURE THAT 'ZA'=THE NUMBER OF THE DATA SET AND ZR= THE DESIRED RECORD NUMBER AND THAT ZI$(X,ZA)=THE DATA IF ZS%(ZA,1)=1 THEN RSET ZC$(ZA)=STR$(ZC) : RSET ZP$(ZA)=STR$(ZP):RSET ZNEXT$(ZA)=STR$(ZN):IF ZS%(ZA,4)>0 THEN FOR Y24=1 TO ZS%(ZA,4):RSET ZH$(ZA,Y24)=STR$(ZH(Y24)) :RSET ZE$(ZA,Y24)= STR$(ZE(Y24)):NEXT Y24 IF ZS%(ZA,1)=2 THEN RSET ZB$(ZA)=STR$(ZB): RSET ZF$(ZA)=STR$(ZF) FOR Y24=1 TO ZS%(ZA,7):LSET Y$(Y24,ZA)=ZI$(Y24,ZA):NEXT Y24 PUT ZT%(ZA,Y1,4), ZR : RETURN 'WRITE THE RECORD REM ** SUBROUTINE TO CREATE A NEW MASTER DATA SET ** REM ** BE SURE THAT 'ZA'=THE NUMBER OF THE DATA SET, ZR$=THE SEARCH ITEM, ZI$(X)=THE NEW DATA VARIABLES ** GOSUB 500:ZZ=1:REM ZR NOW=THE CALCULATED RECORD # IN 'ZA' AND WITH ZZ=1 ANY CALLS TO SUBROUTINE AT 610 WILL RETURN FROM 665. GOSUB 610:REM CHECK RECORD TO SEE IF RECORD ALREADY EXISTS AT THIS CALCULATED LOCATION. IF ZL$ <> LEFT$(ZBLANK$,ZSIZE%(ZA,1)) THEN 880 : REM IF ZL$=BLANK THEN NO MASTER EXISTS AT THIS LOCATION ZC=1 : ZP=0 : ZN=0 : REM SET HEADER VARIABLES IF ZS%(ZA,4)=0 GOTO 840 FOR ZI=1 TO ZS%(ZA,4) : ZH(ZI)=0 : ZE(ZI)=0 : NEXT GOSUB 750 : REM CREATE THE RECORD ZS%(ZA,6)=ZS%(ZA,6)+1 : ZCHGFLAG(ZA)=1 'BUMP NUMBER OF RECORDS AND SET THE CHANGE FLAG PAGE A - 5 PDS*BASE SYSTEM APPENDIX A Copyright 1985 852 IF ZS%(ZA,1)=1 AND ZFOPEN<>ZA THEN CLOSE ZQ+1 : ZF$=MID$("ABCDE",ZT%(ZA,1,1),1)+":"+LEFT$(ZS$(ZA,1),(LEN(ZS$( ZA,1)) -4 ))+".SRT" : OPEN ZF$ FOR APPEND AS ZQ+1 : ZFOPEN=ZA 'OPEN THE SORT KEY FILE 854 WRITE #ZQ+1,ZR 'APPEND THE NEWLY CREATED RECORD # TO THE REPORT SORT FILE 860 RETURN 880 REM ** RECORD ALREADY EXISTS AT THE CALCULATED LOCATION ** 885 IF ZL$=ZR$ THEN BEEP : PRINT ZR$;" ALREADY EXISTS IN THE DATA BASE." : ZV=2 : RETURN 890 IF ZC=0 GOTO 950 : REM IF ZC>=1 THEN WE ARE AT THE HEAD OF A MASTER CHAIN 900 GOSUB 1800:IF ZV>0 THEN RETURN ELSE ZZ=1:GOSUB 610:REM Z1 WILL= A VACANT RECORD NUMBER 905 IF ZC>1 GOTO 920 : REM IF ZC=1 THEN THERE ARE NO PRESENT SECONDARY MASTERS 910 ZC=2:ZN=Z1:GOSUB 700:REM UPDATE THE POINTERS ON THE CHAIN HEAD MASTER 915 ZC=0:ZP=ZR:ZN=0:ZR=Z1:GOTO 830:REM SET HEADER VARIABLES, GOTO 830 TO CREATE THE NEW MASTER 920 Z2=ZR:ZR=ZN:REM WE GOT HERE FROM 905 WHEN THERE ARE ALREADY SECONDARY MASTERS 925 ZZ=1:GOSUB 610:IF ZL$=ZR$ THEN PRINT CHR$(7);ZR$;" ALREADY EXISTS IN THE DATA BASE." :ZV=2:RETURN 930 IF ZN=0 GOTO 940 935 ZR=ZN:GOTO 925:REM READ THE NEXT SECONDARY MASTER 940 ZN=Z1:Z3=ZR : GOSUB 700:ZR=Z2 : ZZ=1 : GOSUB 610 : ZC=ZC+1 : GOSUB 700 : REM SET THE POINTERS ON THE FORMER LAST RECORD IN THE CHAIN AND ON THE HEAD MASTER RECORD. 945 ZR=Z1:ZN=0:ZP=Z3:ZC=0:GOTO 830: REM CREATE THE NEW MASTER AT 830 950 GOSUB 1800 : IF ZV>0 THEN RETURN ELSE ZZ=1 : GOSUB 610 : Z2=ZR:ZR=Z1:GOSUB 700 : REM READ SECONDARY MASTER AT CALCULATED POSITION, FIND A NEW VACANT RECORD AND XFER THE SECONDARY MASTER TO IT. 955 Z1=ZR : ZR=ZP : Z3=ZN : ZZ=1 : GOSUB 610 : ZN=Z1 : GOSUB 700 : REM READ AND RESET POINTERS OF THE PREVIOUS RECORD FOR THE SECONDARY WE JUST MOVED 960 IF Z3=0 GOTO 970 965 ZR=Z3 : ZZ=1 : GOSUB 610 : ZP=Z1 : GOSUB 700 : REM RESET THE POINTERS ON THE NEXT RECORD IN THE CHAIN OF THE SECONDARY THAT WE JUST MOVED 970 ZR=Z2:ZC=0:ZP=0:ZN=0:GOTO 825 : REM SET ZR BACK TO THE CALCULATED VALUE THEN GOTO 825 TO CREATE THE NEW MASTER CHAIN HEAD 975 REM PAGE A - 6 PDS*BASE SYSTEM APPENDIX A Copyright 1985 1000 REM ** SUBROUTINE TO CREATE A DETAIL DATA SET ** 1001 REM ** ZR$ MUST= THE SEARCH ITEM OF THE DETAIL'S MASTER SO THE CHAIN HEAD AND END OF THE DETAIL CHAIN CAN BE UPDATED 1002 REM ** IT IS ASSUMED THAT THE CHAIN HEAD MASTER HAS ALREADY BEEN READ AS ZR. ZM=MASTER SET NUM, ZS=DETAIL SET NUM. SAVE ZR AS YM ** 1010 YM=ZR : ZA=ZS 1020 Z6=0 1025 FOR ZI=2 TO 4 1030 IF ZS$(ZM,ZI)=ZS$(ZS,1) THEN Z6=ZI-1 : ZI= 4 1035 NEXT:IF Z6=0 THEN PRINT CHR$(7);ZS$(ZS,1);" DOES NOT MATCH "ZS$(ZM,1) : PRINT "PROGRAMMING ERROR" : GOTO 400 : REM Z6=WHICH DETAIL SET FOR THE MASTER 1040 Z7=ZH(Z6):Z8=ZE(Z6):REM SAVE THE EXISTING CHAIN HEAD AND END POINTERS FROM THE MASTER 1050 IF ZS%(ZS,1)<>2 THEN PRINT CHR$(7);"PROGRAMMING ERROR-"; ZS$(ZS,1);" ISN'T A DETAIL SET." : GOTO 400 1060 Z1=ZS%(ZS,8) : IF Z1=0 THEN PRINT CHR$(7);"THIS DATA SET IS FULL" : PRINT : PRINT " (PRESS ANY KEY TO CONTINUE)"; : YQ$=INPUT$(1) : PRINT : RETURN 1100 Z2=ZR : ZR=Z1 : ZZ=1 : GOSUB 610 : ZS%(ZS,8)=ZF : ZR=Z2 : REM READ THE NEW SLAVE TO GET THE POINTER TO THE NEXT VACANT DETAIL FOR FUTURE REFERENCE IN ZS%(ZS,8) 1110 IF ZF>ZS%(ZS,2) THEN ZS%(ZA,8)=0 1115 ZA=ZM : ZR=YM : ZZ=1 : GOSUB 610 : IF Z7<>0 GOTO 1125 1120 ZH(Z6)=Z1:ZE(Z6)=Z1:GOSUB 700:ZB=0:ZF=0:ZR=Z1:GOTO 1140 1125 Z2=ZE(Z6):ZE(Z6)=Z1:ZA=ZM:ZR=YM:GOSUB 700:ZR=Z2:REM SET NEW CHAIN END IN MASTER 1130 ZA=ZS:ZZ=1:GOSUB 610 1135 ZF=Z1:GOSUB 700:ZB=Z2:REM SET FORWARD POINTER FOR PREVIOUS CHAIN END DATA SET 1140 ZA=ZS:ZF=0:ZR=Z1:GOSUB 750:REM WRITE NEW DETAIL RECORD 1145 ZS%(ZA,6)=ZS%(ZA,6)+1:REM ADD 1 TO THE ACTIVE RECORDS COUNT 1150 ZR=YM : RETURN 1160 REM PAGE A - 7 PDS*BASE SYSTEM APPENDIX A Copyright 1985 1200 REM ** DELETE A MASTER RECORD ** 1201 REM ** ZA MUST=# OF THE SET, ZR$ MUST=VALUE OF SEARCH ITEM. IT IS ASSUMED THAT THE RECORD HAS BEEN READ 1205 Y4=ZR : IF ZC=0 THEN GOSUB 500 : Y5=ZR 1210 IF ZS%(ZA,4)=0 GOTO 1220 1213 FOR ZI=1 TO ZS%(ZA,4):IF ZH(ZI)<>0 OR ZE(ZI)<>0 THEN PRINT CHR$(7);"CAN'T DELETE THIS MASTER RECORD AS IT" : PRINT "STILL HAS DETAIL DATA." : ZV=1 : RETURN 1215 NEXT 1220 IF ZC=0 GOTO 1240 : REM ZC=0 IF IT IS A SECONDARY MASTER 1225 IF ZC>1 GOTO 1280:REM IF ZC>1 THEN THERE ARE SECONDARY MASTERS TO DEAL WITH 1230 FOR Y11=1 TO ZS%(ZA,7):ZI$(Y11,ZA)= LEFT$(ZBLANK$,ZSIZE%(ZA,Y11)):NEXT Y11:ZC=0:ZP=0:ZN=0 :GOSUB 750:ZS%(ZA,6)=ZS%(Z A,6)-1:ZCHGFLAG(ZA)=1 'SET FIELDS BLANK, UPDATE RECORD, SUBTRACT 1 FROM NUMBER OF RECORDS ASSIGNED, SET CHANGE FLAG 1235 RETURN 1240 Y2=ZP : Y3=ZN : ZR=Y2 : ZZ=1 : GOSUB 610 : ZN=Y3 : IF Y2=Y5 THEN ZC=ZC-1 1245 GOSUB 700 : REM RESET THE POINTERS ON THE PREVIOUS RECORD 1250 IF Y3<>0 THEN ZR=Y3 : ZZ=1 : GOSUB 610 : ZP=Y2 : GOSUB 700 : REM RESET POINTERS IN NEXT RECORD 1255 IF Y2<>Y5 THEN ZR=Y5 : ZZ=1 : GOSUB 610 : ZC=ZC-1 : GOSUB 700 : REM RESET THE NUMBER OF MASTERS IN THE CHAIN HEAD 1260 ZR=Y4 : GOTO 1230 1280 Y2=ZR : ZR=ZN : Y9=ZN : ZX=ZC : ZZ=1 : GOSUB 610 : Y3=ZN : REM WE ARE REMOVING THE CHAIN HEAD THAT HAS SECONDARY MASTERS. THUS, WE MOVE THE 1ST SECONDARY TO THE CHAIN HEAD RECORD NUMBER 1285 ZC=ZX-1 : ZP=0 : ZR=Y2 : GOSUB 700 : REM THIS MOVED THE 1ST SECONDARY MASTER TO THE CHAIN HEAD 1290 IF Y3<>0 THEN ZR=Y3 : ZZ=1 : GOSUB 610 : ZP=Y2 : GOSUB 700 : REM RESET POINTER ON NEXT RECORD 1295 ZR=Y9 : GOTO 1230 1300 REM ** DELETE A DETAIL RECORD ** 1301 REM ** ASSUMES THAT YS=THE RECORD NUMBER OF THE DETAIL RECORD THAT HAS PREVIOUSLY BEEN READ (IN ZS), AND THAT YM=THE RECORD NUMBER OF THE ASSOCIATED MASTER RECORD (IN ZM). 1305 ZA=ZS : Z1=YS 1310 FOR Y11=1 TO ZS%(ZA,7) : ZI$(Y11,ZA)= LEFT$(ZBLANK$,ZSIZE%(ZA,Y11)):NEXT Y11:Z2=ZF:ZF=ZS%(ZA,8): Z3=ZB:ZB=0:GOSUB 750:ZS%(ZA,8)=YS:ZS%(ZA,6)=ZS%(ZA,6)-1 1311 REM SET THE RECORD TO BLANKS, SAVE THE RECORD # IN ZS%(ZA,8) & SET FORWARD POINTER TO NEXT VACANT RECORD 1315 IF Z3=0 GOTO 1340 1325 ZR=Z3 : ZZ=1 : GOSUB 610 : REM READ THE PREVIOUS RECORD IN THE CHAIN PAGE A - 8 PDS*BASE SYSTEM APPENDIX A Copyright 1985 1330 ZF=Z2 : GOSUB 700 : REM UP-DATE THE FORWARD POINTER IN THE PREVIOUS RECORD IN THE DETAIL CHAIN 1340 IF Z2=0 GOTO 1360 1345 ZR=Z2 : ZZ=1 : GOSUB 610 : REM READ THE NEXT RECORD IN THE DETAIL CHAIN 1350 ZB=Z3 : GOSUB 700 : REM UP-DATE THE BACKWARD POINTER IN THE NEXT RECORD IN THE CHAIN 1360 REM UP-DATE THE ASSOCIATED MASTER IF NECESSARY 1365 IF Z2<>0 AND Z3<>0 THEN RETURN : REM THE DELETED DETAIL WAS IN THE MIDDLE OF A DETAIL CHAIN 1370 ZA=ZM : ZR=YM : ZZ=1 : GOSUB 610 : REM READ THE ASSOCIATED MASTER 1375 Z6=0 : FOR ZI=2 TO ZS%(ZA,4)+1 : IF ZS$(ZM,ZI)=ZS$(ZS,1) THEN Z6=ZI-1 : ZI=ZS%(ZA,4)+1 1380 NEXT : IF Z3=0 THEN ZH(Z6)=Z2 1385 IF Z2=0 THEN ZE(Z6)=Z3 1390 GOSUB 700 : RETURN : REM UP-DATE THE CHAIN HEAD AND CHAIN ENDS IF THE ASSOCIATED MASTER 1395 REM 1500 REM ** SUBROUTINE TO CREATE ZI$(X) FROM Y$(X) ** 1510 REM ** ZA MUST=THE NUMBER OF THE DATA SET 1520 FOR Z1=1 TO ZS%(ZA,7) : ZI$(Z1,ZA)=Y$(Z1,ZA) : NEXT Z1 1530 RETURN 1540 REM 1800 REM ** SUBROUTINE TO LOCATE A VACANT MASTER RECORD ** 1810 Z1=ZR : Z2=ZR : ZV=0 : IF ZS%(ZA,6)=ZS%(ZA,2) THEN PRINT " DATA SET ";ZS$(ZA,1);" IS FULL.";CHR$(7) : ZV=1 : RETURN 1820 Z1=Z1-1:IF Z1=0 THEN Z1=ZS%(ZA,2) 'REM SEARCH DOWNWARD FOR A VACANT RECORD 1830 ZZ=1:ZR=Z1:GOSUB 610:IF ZL$ <> LEFT$(ZBLANK$,ZSIZE%(ZA,1)) THEN 1820 'READ THE LOWER RECORD AND CHECK FOR BLANK SEARCH FIELD 1840 ZR=Z2 : REM FOUND A BLANK RECORD 1850 RETURN 1860 REM 1981 REM ** THE MAIN PROGRAM FOLLOWS ** 1982 REM ** THE FOLLOWING SUBROUTINES CAN BE CALLED ** 1983 REM 500 - TO CALCULATE A RECORD NUMBER 1984 REM 600 - TO DIRECT READ A RECORD 1985 REM 700 - TO UPDATE A RECORD USING Y$(X) BUFFER 1986 REM 750 - TO UPDATE A RECORD USING ZI$(X) BUFFER 1987 REM 800 - TO CREATE A NEW MASTER 1988 REM 1000 - TO CREATE A NEW DETAIL DATA SET 1989 REM 1200 - TO DELETE A MASTER RECORD 1990 REM 1300 - TO DELETE A DETAIL RECORD 1991 REM 1500 - TO CREATE ZI$(X) FROM Y$(X) BUFFER 1995 REM 1800 - TO LOCATE A VACANT RECORD PAGE A - 9 PDS*BASE SYSTEM APPENDIX A Copyright 1985 2000 REM *******MAIN PROGRAM****** 2010 CLS : PRINT TAB(7)"PDS*BASE FILE WORK MENU FOR":PRINT :Z2=LEN(ZB$)+9:PRINT TAB(INT((40-Z2)/2))ZB$;" DATA BASE":PRINT:LOCATE ,,1 'turn on the cursor 2015 REM *** THE FOLLOWING TITLES ARE FROM THE FILE NAMES. YOU MAY WISH TO CHANGE THEM TO MORE PEOPLE FRENDLY MENU TITLES AND REMOVE THIS REM LINE. *** 2021 PRINT 2022 PRINT " 1 - STOCK.DAT" 2023 PRINT 2024 PRINT " 2 - ORDER.DAT" 2025 PRINT 2026 PRINT " 3 - RECEIVED.DAT" 2027 PRINT 2028 2029 2030 2035 2040 2042 2045 2047 2050 2052 2055 2060 2065 2070 2080 2100 2105 2110 2115 2120 2125 2130 2135 2136 2137 2138 2140 2150 2160 PRINT " 4 - USED.DAT" PRINT PRINT " 5 - SUPPLIER.DAT" ZPOSX=CSRLIN:ZPOSY=POS(0):LOCATE ZPOSX+6,1,1:PRINT "DEPRESS RETURN WHEN FINISHED";:LOCATE ZPOSX,ZPOSY,1 PRINT: COLOR 0,7 :PRINT "ENTER CODE + A, M, D ":PRINT "A=ADD, M=MODIFY, D=DELETE": COLOR 7,0 :PRINT "ENTER "; INPUT YC$ YC=VAL(YC$) : IF YC=0 GOTO 400 IF YC>ZQ GOTO 2010 ZA=YC:ZI=LEN(YC$):IF YC<10 AND ZI<2 GOTO 2070 IF YC>9 AND ZI < 3 GOTO 2070 IF MID$(YC$,ZI,1)="A" THEN YB=1 IF MID$(YC$,ZI,1)="M" THEN YB=2 IF MID$(YC$,ZI,1)="D" THEN YB=3 IF YB < 1 OR YB > 3 THEN PRINT CHR$(7):GOTO 2010 CLS : ON YB GOTO 2100,2200,2200 REM ADD NEW DATA SETS IF ZS%(ZA,1)=1 GOTO 2130 ZS=ZA:Y11=0:FOR ZI=1 TO ZQ:IF ZS$(ZA,2)=ZS$(ZI,1) THEN Y11=ZI:ZM=ZI:ZI=ZQ NEXT:IF Y11=0 THEN PRINT CHR$(7);"NO MASTER SET FOUND FOR '";ZS$(ZA,1);".":FOR ZI=1 TO 5000:NEXT:GOTO 2010 PRINT "FIRST ENTER ";ZN$(ZM,1,1);:INPUT YC$:IF YC$="" GOTO 2010 ELSE ZR$=LEFT$(ZBLANK$,ZSIZE%(ZM,1)) : MID$(ZR$,1,LEN(YC$))=YC$ ZA=ZM:GOSUB 500:GOSUB 600:YM=ZR:ZA=ZS:IF ZV>0 THEN ZA=YC: GOTO 2100 FOR ZI=1 TO ZS%(ZA,7) PRINT:GOSUB 5000:IF ZI=1 AND ZS%(ZA,1)=1 AND ZI$(ZI,ZA)= LEFT$(ZBLANK$,ZSIZE%(ZA,1)) THEN ZI=ZS%(ZA,7) IF ASC(YC$)=27 THEN ZI=ZS%(ZA,7) NEXT:IF ZS%(ZA,1)=1 AND ZI$(1,ZA)= LEFT$(ZBLANK$,ZSIZE%(ZA,1)) THEN 2010 IF ASC(YC$)=27 GOTO 2010 ZD$=ZI$(1,ZA):IF ZS%(ZA,1)=1 THEN ZR$=ZI$(1,ZA) IF ZS%(ZA,1)=1 THEN GOSUB 800:ZA=YC IF ZS%(ZA,1)=2 THEN GOSUB 1000:ZA=YC PAGE A - 10 PDS*BASE SYSTEM APPENDIX A Copyright 1985 2170 IF ZS%(ZA,1)=1 THEN PRINT : PRINT CHR$(7);"CREATE NEXT "; ZN$(ZA,1,1) : PRINT : GOTO 2100 2180 IF ZS%(ZA,1)=2 THEN PRINT : PRINT CHR$(7);"ADD ANOTHER "; 2185 2190 2200 2205 2210 2215 2220 2225 2230 2235 2240 2245 2250 2255 2260 2265 2267 2268 2270 2275 2277 2280 2285 2287 2290 2292 2295 2297 2300 2302 2304 2305 2310 ZN$(ZA,1,1);" TO MASTER ";ZR$;" (Y/N)?"; :YQ$=INPUT$(1):PRINT YQ$ IF ZS%(ZA,1)=2 AND YQ$="Y" GOTO 2130 PRINT "THEN ";:ZA=ZM:GOTO 2120 REM **MODIFY DATA SET** Y5=0:IF ZS%(ZA,1)=1 GOTO 2330 ZS=ZA:Y11=0:FOR ZI=1 TO ZQ:IF ZS$(ZA,2)=ZS$(ZI,1) THEN Y11=ZI:ZM=Y11:ZI=ZQ NEXT:IF Y11=0 THEN PRINT CHR$(7);"NO MASTER SET FOUND FOR '";ZS$(ZA,1);".":FOR ZI=1 TO 5000:NEXT:GOTO 2010 PRINT "FIRST ENTER EXISTING ";ZN$(ZM,1,1);" (\=SAME)"; :INPUT YC$:IF YC$="" GOTO 2010 ELSE IF YC$<>"\" THEN ZR$= LEFT$(ZBLANK$,ZSIZE%(ZM,1)) : MID$ (ZR$,1,LEN(YC$))=YC$ ZA=ZM:GOSUB 500:GOSUB 600:YM=ZR:IF ZV>0 THEN ZA=YC :GOTO 2200 ZA=ZS:Y2=0:FOR ZI=2 TO 4 IF ZS$(ZM,ZI)=ZS$(ZS,1) THEN Y2=ZI-1:ZI= 4 NEXT ZR=ZH(Y2):Y3=0:IF ZR=0 THEN PRINT CHR$(7);"NO DETAIL DATA FOR THIS MASTER":GOTO 2200:REM WE NOW HAVE THE CHAIN HEAD IN THE SLAVE SET ZA=ZS:GOSUB 600:GOSUB 1500:Y3=Y3+1 CLS:PRINT "PRESS SPACE=NEXT - S=STOP":PRINT :PRINT"RECORD ";Y3 PRINT:FOR ZI=1 TO ZS%(ZA,7) PRINT ZI;" - ";ZN$(ZA,ZI,1);" = ";ZI$(ZI,ZA) :IF ZS%(ZA,7)<10 THEN PRINT IF ZS%(ZA,7)>20 AND ZI=20 THEN PRINT : PRINT "(PRESS ANY KEY TO CONTINUE); : ZQ$=INPUT$(1) :PRINT NEXT IF ZF=0 THEN PRINT:PRINT CHR$(7);"END OF CHAIN":GOTO 2277 YQ$=INPUT$(1) :PRINT YQ$:IF YQ$<>"S" THEN ZR=ZF:GOTO 2250 IF YB=3 GOTO 2400 PRINT:PRINT "ENTER NUMBER OF ITEM TO CHANGE ";:INPUT Y4$ : Y4=VAL(Y4$):IF Y4=0 THEN GOTO 2310 IF Y4>ZS%(ZA,7) THEN PRINT CHR$(7):GOTO 2280 IF ZS%(ZA,1)=1 AND Y4=1 THEN PRINT CHR$(7);"CAN'T MODIFY THE SEARCH VALUE.":PRINT:GOTO 2280 PRINT:ZI=Y4:GOSUB 5000:IF ASC(YC$)=27 GOTO 2010 Y5=Y5+1: CLS IF ZV>0 GOTO 2200 PRINT:FOR ZI=1 TO ZS%(ZA,7) PRINT ZI;" - ";ZN$(ZA,ZI,1);" = ";ZI$(ZI,ZA) :IF ZS%(ZA,7)<9 THEN PRINT IF ZS%(ZA,7)>20 AND ZI=20 THEN PRINT : PRINT "(PRESS ANY KEY TO CONTINUE); : ZQ$=INPUT$(1) : PRINT NEXT : IF YB=2 GOTO 2280 IF YB=3 GOTO 2400 IF Y5=0 GOTO 2200 PAGE A - 11 PDS*BASE SYSTEM APPENDIX A Copyright 1985 2315 GOSUB 750:GOTO 2200 2330 PRINT "ENTER EXISTING ";ZN$(ZA,1,1);:INPUT YC$:IF YC$=""GOTO 2010 ELSE ZR$=LEFT$(ZBLANK$,ZSIZE%(ZA,1)) : MID$(ZR$,1, LEN(YC$))=YC$ 2335 GOSUB 500:GOSUB 600:GOSUB 1500:GOTO 2295 2400 PRINT:PRINT "DO YOU WISH TO DELETE THE ABOVE (Y/N) ";: YQ$=INPUT$(1):PRINT YQ$:IF YQ$<>"Y" GOTO 2200 2410 IF ZS%(ZA,1)=1 THEN GOSUB 1200:GOTO 2200 2420 IF ZS%(ZA,1)=2 THEN YS=ZR:GOSUB 1300 2430 ZA=YC:GOTO 2200 5000 REM ** SUBROUTINE TO INPUT DATA ** 5010 Z2=ZSIZE%(ZA,ZI) 5020 Z3=LEN(ZN$(ZA,ZI,1))+10 5025 IF (Z2+Z3)>79 THEN Z3=1 5030 ZI$(ZI,ZA)=LEFT$(ZBLANK$,Z2) 5040 PRINT "ENTER ";ZN$(ZA,ZI,1);" ? ";:LOCATE ,,1 5044 IF Z3=1 THEN PRINT 5046 COLOR 0,7:FOR Y11=1 TO Z2:PRINT CHR$(32);:NEXT:COLOR 7,0 : LOCATE ,Z3,1 5060 FOR ZJ=1 TO Z2 5070 YC$=INKEY$:IF YC$="" THEN 5070 5080 IF ASC(YC$)=27 THEN ZJ=Z2:ZI$(ZI,ZA)=LEFT$(ZBLANK$,Z2) : GOTO 5200 5090 IF ASC(YC$)=8 THEN GOSUB 5300 5100 IF ASC(YC$)=8 GOTO 5070 5110 IF ASC(YC$)=13 THEN ZJ=Z2:GOTO 5200 5120 COLOR 0,7 : PRINT YC$; : COLOR 7,0 5130 IF MID$(ZN$(ZA,ZI,2),2,1)="C" GOTO 5190 5140 IF VAL(YC$)>0 OR YC$="0" GOTO 5190 5150 IF YC$="-" OR YC$="+" GOTO 5190 5160 IF YC$="." AND MID$(ZN$(ZA,ZI,2),2,1)="R" GOTO 5190 5170 PRINT:PRINT CHR$(7);"MUST BE A NUMBER - TRY AGAIN" :PRINT:GOTO 5030 5190 MID$(ZI$(ZI,ZA),ZJ,1)=YC$ 5200 NEXT ZJ 5205 PRINT 5207 IF ZI=1 THEN IF ASC(YC$)=13 AND ZI$(ZI,ZA)= LEFT$(ZBLANK$,Z2) AND ZS%(ZA,1)=1 THEN RETURN 'FINISHED ADDING MASTERS 5210 IF MID$(ZN$(ZA,ZI,2),1,1)<>"R" OR ASC(YC$)=27 THEN RETURN 5212 IF ZI$(ZI,ZA)<>LEFT$(ZBLANK$,Z2) THEN RETURN 5215 PRINT:PRINT CHR$(7);"ENTRY FOR THIS ITEM REQUIRED.":PRINT "PRESS 'ESC'TO CANCEL THE ENTIRE ENTRY.":PRINT:GOTO 5030 5300 REM **SUBROUTINE FOR BACKSPACE** 5320 IF ZJ=1 THEN RETURN 5330 LOCATE ,POS(0)-1,1: COLOR 0,7 : PRINT " "; : COLOR 7,0 : LOCATE ,POS(0)-1,1:MID$(ZI$(ZI,ZA),ZJ-1,1)="" :ZJ=ZJ-1:RETURN PAGE A - 12 PDS*BASE SYSTEM APPENDIX B Copyright 1985 LISTING OF SAMPLE INVENTORY DATA BASE REPORT PROGRAM 2010 CLS:PRINT " PDS*BASE DATA BASE REPORT PROGRAM FOR" : PRINT : PRINT TAB( 4 );"STOCK REPORT FOR TEST DATA BASE" : PRINT : PRINT 2015 DIM YA$( 51 ),YA%( 51 ,2),ZS9( 10 ,1) 2017 YB$=STRING$(255,32) 'USED TO GENERATE BLANKS 2018 ZPASS=1 : ZF$="B:TESTREP.SRT" : ZA= 1 2020 ON ERROR GOTO 2027 2022 PRINT:PRINT "READING SORT KEYS FROM FILE ";ZF$:OPEN ZF$ FOR INPUT AS ZQ+1:INPUT #ZQ+1, ZTDATE$,ZTTIME$:INPUT #ZQ +1, Z5 2024 IF ZPASS=1 THEN IF Z5<>ZS%( 1 ,6) THEN BEEP : PRINT "THE NUMBER OF RECORDS IN THE KEY FILE DOESN'T = NUMBER OF RECORDS IN DATA BASE":PRINT:CLOSE #ZQ+1:GOTO 2029 2025 IF ZPASS=1 THEN IF ZDATE$(ZA)<>ZTDATE$ OR ZTIME$(ZA)<>ZTTIME$ THEN BEEP:PRINT "DATE & TIME FOR THE KEY FILE DOESN'T= DATE & TIME IN THE DATA BASE":PRINT :CLOSE #ZQ+1:GOTO 2029 2026 ON ERROR GOTO 0:GOTO 2030 2027 RESUME 2028 2028 IF ZPASS=2 THEN 2029 ELSE ZF$=MID$("ABCDE",ZT%(ZA,1,1),1)+ ":"+LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT" : ZPASS=2 : GOTO 2022 2029 ON ERROR GOTO 0 : GOTO 2040 2030 ZZ5=0 'READ THE SORT KEY FILE 2032 IF EOF(ZQ+1) THEN 2034 ELSE ZZ5=ZZ5+1 :INPUT #ZQ+1, YA%(ZZ5,2):GOTO 2032 2034 CLOSE #ZQ+1:IF ZZ5=ZS%(ZA,6) THEN IF ZPASS=1 THEN 2300 'THE NUMBER OF RECORDS IN THE SORT KEY FILE MAY BE LARGER IF A MASTER WAS DELETED AND RE-CREATED IN THE SAME DATED SESSION 2040 PRINT : PRINT "THE DATA BASE MUST BE RE-SORTED." : PRINT : PRINT "THE SORT KEYS ARE BEING LOADED FROM THE '"; ZS$( 1 ,1);"' FILE." : Z5=0 : ZA= 1 2045 ZJJ=ZS%(ZA,2):IF ZPASS=2 AND ZZ5=ZS%(ZA,6) THEN ZJJ=ZZ5 2050 FOR ZJ=1 TO ZJJ 2055 IF ZZ5=ZS%(ZA,6) AND ZPASS=2 THEN ZR=YA%(ZJ,2) ELSE ZR=ZJ 2060 ZZ=1 : GOSUB 610 2100 IF ZL$<>LEFT$(YB$, 10 ) THEN Z5=Z5+1 : YA$(Z5)=Y$(1,ZA) : YA%(Z5,1)=Z5 : YA%(Z5,2)=ZR 2120 NEXT ZJ 2125 ZS%( 1 ,6)=Z5 : REM CORRECT RECORDS ASSIGNED 2130 PRINT : PRINT CHR$(7);"THERE WILL BE A FILE SORT DELAY." : PRINT : PRINT 2140 ZZT$=TIME$ : ZT1=(VAL(LEFT$(ZZT$,2))*3600) + (VAL(MID$(ZZT$,4,2))*60) + (VAL(RIGHT$(ZZT$,2))) 2150 ZI1=1 : ZJ1=Z5 : ZP=0 2160 ZI=ZI1:ZJ=ZJ1 2170 IF YA$(YA%(ZI,1))>YA$(YA%(ZJ,1)) THEN SWAP YA%(ZI,1),YA%(ZJ,1):SWAP YA%(ZI,2),YA%(ZJ,2) : ZZS%=ABS(ZZS%-1) 2180 ZI=ZI+ZZS%:ZJ=ZJ-(1-ZZS%):IF ZI<ZJ THEN 2170 2190 IF ZI+1<ZJ1 THEN ZP=ZP+1:ZS9(ZP,0)=ZI+1:ZS9(ZP,1)=ZJ1 2200 ZJ1=ZI-1:IF ZI1<ZJ1 THEN 2160 PAGE B - 1 PDS*BASE SYSTEM APPENDIX B Copyright 1985 2210 IF ZJ>0 THEN LOCATE ,1,1:PRINT YA$(YA%(ZJ,1)); 2220 IF ZP THEN ZI1=ZS9(ZP,0):ZJ1=ZS9(ZP,1):ZP=ZP-1:GOTO 2160 2230 ZZT$=TIME$ : ZT2=(VAL(LEFT$(ZZT$,2))*3600) + (VAL(MID$(ZZT$,4,2))*60) + (VAL(RIGHT$(ZZT$,2))):PRINT:PRINT 2240 BEEP:ZT3=ZT2-ZT1:IF ZT3 < 120 THEN PRINT "ELAPSED TIME=";ZT3;" SECONDS" ELSE PRINT "ELAPSED TIME ="; INT(ZT3/60);" MINUTES "; INT( ( (ZT3/60)-INT(ZT3/60) )*60); " SECONDS" 2245 ZPASS=1 : ZF$="B:TESTREP.SRT" 2250 OPEN ZF$ FOR OUTPUT AS ZQ+1 2260 WRITE #ZQ+1,ZDATE$(ZA);ZTIME$(ZA) : PRINT #ZQ+1,Z5 : FOR ZI=1 TO Z5 : PRINT #ZQ+1,YA%(ZI,2) : NEXT ZI 2270 CLOSE #ZQ+1 2275 IF ZPASS=2 THEN 2300 ELSE ZF$=MID$("ABCDE",ZT%(ZA,1,1),1) +":"+LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT":ZPASS=2 :GOTO 2250 2300 REM WRITE THE REPORT 2305 PRINT:PRINT "ENTER THE DATE ? ";:LINE INPUT;ZD$:IF ZD$="" THEN ZD$=DATE$ : PRINT ZD$ : PRINT ELSE PRINT : PRINT 2310 PRINT : PRINT "TURN ON THE PRINTER - STRIKE ANY KEY WHEN READY":QA$=INPUT$(1) : PRINT QA$ 2320 YP=0 : ZL= 63 'PAGE AND LINE COUNTERS 2330 DIM YT%( 5 ,10),YT$( 5 ),YR$( 5 ),ZFORM$( 5 ),YH%( 5 , 3 ), YE%( 5 , 3 ) 2340 FOR ZI=1 TO 5:FOR ZJ=1 TO 10:READ YT%(ZI,ZJ):NEXT ZJ : READ ZFORM$(ZI) : YT$(ZI)=LEFT$(YB$,YT%(ZI,4)) : NEXT ZI 2350 REM YT%(X,Y) X=FIELD ON REPORT, Y=1 IS FILE NUMBER, 2=FIELD IN THAT FILE, 3=FUTURE FLD FLAG, 4=# OF CHAR, 5=TAB VALUE 2355 REM 6=JUSTIFICATION CODE, 7=FILE TO LEAD TO THIS FLD, 8=FIELD TO LEAD TO THIS FIELD, 9=DETAIL FLD ACTION CODE, 10=1 IF END OF LINE 2357 REM FOR THE JUSTIFICATION CODES - 1=LEFT, 2=RIGHT, 3=INTEGER W/O COMMAS, 4=INTEGER W/COMMAS, 5=REAL/2 DECIMAL/NO COM MAS, 6=REAL/2 DECIMAL/WITH COMMAS, 7=MONITARY ($ WITH COMM AS & 2 DECIMAL) 2358 REM ZFORM$ WILL CONTAIN THE FORMAT STRING TO BE USED IN THE PRINT USING STATEMENTS 2360 DATA 1, 1, 1, 11, 1, 1, 0, 0, 0, 0,"\ \" 2361 DATA 1, 2, 0, 15, 13, 1, 0, 0, 0, 0,"\ \" 2362 DATA 2, 1, 0, 8, 29, 1, 1, 1, 0, 0,"\ \" 2363 DATA 2, 2, 0, 8, 38, 4, 0, 0, 0, 0," ###,###" 2364 DATA 5, 2, 0, 15, 47, 1, 1, 3, 0, 1,"\ \" 2390 YL$="" : ZA=0 2394 FOR ZI=1 TO Z5 : REM LOOP FOR EACH RECORD IN THE SORT FILE 2396 YJ=0 : FOR ZJ=1 TO 5 : LSET YT$(ZJ)=LEFT$(YB$,YT%(ZJ,4)) : NEXT ZJ 'LSET IS USED TO REUSE MEMORY LOCATIONS AND PREVENT GARBAGE COLLECTION 2398 FOR ZJ=1 TO 5 : REM LOOP FOR EACH FIELD IN THE REPORT 2400 IF ZJ=1 THEN ZZ=1 : ZA=YT%(1,1) : ZR=YA%(ZI,2) : GOSUB 610 : LSET YT$(1)=Y$(YT%(1,2),ZA) : GOTO 2430: REM READ THE RECORD FOR THE FIRST FIELD PAGE B - 2 PDS*BASE SYSTEM APPENDIX B Copyright 1985 2405 IF ZS%(YT%(ZJ,1),1)=2 GOTO 2440 2410 IF ZA=YT%(ZJ,1) THEN LSET YT$(ZJ)=Y$(YT%(ZJ,2),ZA):GOTO 2500:REM ADDITIONAL FIELD IN THE SAME MASTER 2415 IF ZA<>YT%(ZJ,1) AND ZS%(YT%(ZJ,1),1)=1 AND YR$(ZJ)= LEFT$(YB$,YT%(ZJ,4)) THEN 2500 'SKIP THE NEW FIELD IF THE FIELD LEADING TO IT WAS BLANK 2420 IF ZA<>YT%(ZJ,1) AND ZS%(YT%(ZJ,1),1)=1 THEN ZA=YT%(ZJ,1) : ZR$=YR$(ZJ) : GOSUB 500 : GOSUB 600 : LSET YT$(ZJ)= Y$(YT %(ZJ,2),ZA) : REM FIELD IN A DIFFERENT MASTER 2430 IF ZS%(ZA,4)>0 THEN FOR ZK=1 TO ZS%(ZA,4):YH%(ZA,ZK)=ZH(ZK) : YE%(ZA,ZK)=ZE(ZK) : NEXT ZK : REM STORE THE CHAIN HEAD AND ENDS FOR THIS MASTER RECORD 2435 GOTO 2485 2440 2445 2450 2460 2470 2472 2477 2480 2485 2490 2495 2500 2510 2515 2520 2530 2535 2540 2545 2550 2560 2590 2600 2615 2620 2640 2650 REM HANDLE THE DETAIL RECORD IF ZA=YT%(ZJ,1) GOTO 2477 YJ=0 : ZR=0 : ZA=YT%(ZJ,1) IF YT%(ZJ,9)<>2 THEN ZR=YH%(YT%(ZJ,7),YT%(ZJ,8)) IF YT%(ZJ,9)=2 THEN ZR=YE%(YT%(ZJ,7),YT%(ZJ,8)) IF ZR>0 THEN ZZ=1:GOSUB 610:REM READ THE 1ST OR LAST DETAIL RECORD IF ZR=0 GOTO 2500 LSET YT$(ZJ)=Y$(YT%(ZJ,2),ZA):IF YT%(ZJ,9)=0 OR YT%(ZJ,9)=4 THEN YJ=ZJ : YF=ZF : REM SET UP TO READ ADDITIONAL DET AILS AT 2510 IF YT%(ZJ,3)=0 GOTO 2500 FOR Z1=1 TO 5:IF ZA=YT%(Z1,7) THEN YR$(Z1)=Y$(YT%(Z1,8),ZA) : REM SET UP FUTURE FIELD SEARCH VALUE NEXT Z1 NEXT ZJ IF YJ=0 OR YF=0 GOTO 2590 IF YT%(YJ,9)=0 THEN GOSUB 4000 : REM PRINT 1ST LINE WHEN A LINE FOR EACH DETAIL (FIELD YJ) IS TO BE PRINTED ZA=YT%(YJ,1) ZR=YF : ZZ=1 : GOSUB 610 : REM READ THE NEXT DETAIL RECORD IF YT%(YJ,9) < > 0 GOTO 2550 FOR Z1=1 TO 5 : IF ZA=YT%(Z1,1) THEN LSET YT$(Z1)= Y$(YT%(Z1,2),ZA) : REM SET UP FIELDS FOR THE DETAIL RECORD NEXT Z1:GOSUB 4000:IF ZF=0 GOTO 2600 REM PRINT THE LINE IF YT%(YJ,9)=4 THEN LSET YT$(YJ)= STR$(VAL(YT$(YJ)) +VAL(Y$(YT%(YJ,2),ZA))) : REM RUN TOTAL ON THIS FIELD IF ZF>0 THEN YF=ZF : GOTO 2530 GOSUB 4000 : REM PRINT LINE NEXT ZI LPRINT CHR$(12) 'FORM FEED REM ALL DONE GOTO 400 REM PAGE B - 3 PDS*BASE SYSTEM APPENDIX B Copyright 1985 4000 REM PRINT LINE SUBROUTINE 4015 IF ZL > 58 THEN GOSUB 4500 : REM PAGE HEAD IF NECESSARY 4020 4030 4035 4040 FOR ZJ=1 TO 5 'CHECK JUSTIFICATION FOR EACH FIELD IF YT%(ZJ,6)>1 THEN 4050 IF LEFT$(YT$(ZJ),1)<>" " THEN 4090 ' ALREADY LEFT JUSTIFIED Z3=1:FOR ZK=1 TO YT%(ZJ,4)-1:IF MID$(YT$(ZJ),ZK,1)<>" " THEN Z3=ZK : ZK=YT%(ZJ,4)-1 4045 NEXT ZK : LSET YT$(ZJ)=MID$(YT$(ZJ),Z3) : GOTO 4090 'MOVES THE STUFF LEFT 4050 IF YT%(ZJ,6)>2 THEN 4090 'RIGHT JUSTIFY FOR CODE 2 4055 IF RIGHT$(YT$(ZJ),1)<>" " THEN 4090 'ALREADY RIGHT JUSTIFIED 4060 Z3=1:FOR ZK=1 TO YT%(ZJ,4):IF MID$(YT$(ZJ),YT%(ZJ,4)-ZK,1)<>" " THEN Z3=ZK : ZK=YT%(ZJ,4) 4065 NEXT ZK:RSET YT$(ZJ)=MID$(YT$(ZJ),1,Z3) 'MOVES STUFF RIGHT 4090 NEXT ZJ 4100 LPRINT TAB(YT%(1,5));:LPRINT USING ZFORM$(1);YT$(1); 4105 LPRINT TAB(YT%(2,5));:LPRINT USING ZFORM$(2);YT$(2); 4110 LPRINT TAB(YT%(3,5));:LPRINT USING ZFORM$(3);YT$(3); 4115 LPRINT TAB(YT%(4,5));:LPRINT USING ZFORM$(4);VAL(YT$(4)); 4120 LPRINT TAB(YT%(5,5));:LPRINT USING ZFORM$(5);YT$(5);: LPRINT : ZL=ZL+1 'END OF LINE 4300 LPRINT:ZL=ZL+1 'PRINT BLANK LINE BEFORE NEXT RECORD REMOVE THIS LINE IF YOU WISH TO SINGLE SPACE 4310 RETURN 4320 REM IF YOU WISH TO CHANGE THE ORDER THAT THE FIELDS ARE PRINTED, JUST CHANGE THE ORDER OF THE ABOVE LINE NUMBERS AND MODIFY THE FOLLOWING COLLUMN HEADING STARTING IN LINE 4535 4500 REM PAGE HEADING SUBROUTINE 4520 IF ZI>1 THEN LPRINT CHR$(12) 'FORM FEED 4525 LPRINT ZD$;SPC(2); 4530 YP=YP+1:LPRINT "STOCK REPORT FOR TEST DATA BASE";TAB(72) "PAGE ";YP : LPRINT 4535 LPRINT "PART NUMBER*DESCRIPTION* DATE* QUANTITY* SUPPLIER NAME" 4550 FOR Z1=1 TO 59:LPRINT CHR$(95);:NEXT Z1:LPRINT:LPRINT 4560 ZL= 6:RETURN PAGE B - 4 PDS*BASE SYSTEM APPENDIX C Copyright 1985 LISTING OF SAMPLE INVENTORY DATA BASE SORT PROGRAM 2000 REM *******MAIN PROGRAM****** 2010 CLS : PRINT TAB(20)" PDS*BASE DATA BASE SORT PROGRAM FOR" : PRINT : PRINT TAB( 36 );"INVENTRY" : PRINT : PRINT 2015 DIM YA$( 50 ),YA%( 50 ,3),YF%( 6 ),ZS9( 10 ,1) 2020 PRINT : PRINT "ENTER THE NAME OF THE PROGRAM THIS SORT WILL BE USED WITH "; : INPUT YF$ : IF YF$="" THEN 400 2025 IF RIGHT$(YF$,4)=".BAS" THEN YF$=LEFT$(YF$,LEN(YF$)-4) +".SRT" ELSE YF$=YF$+".SRT" 'APPEND .SRT TO THE PROGRAM NAME 2030 PRINT:PRINT "CHOOSE ONE OF THE MASTER FILES TO SORT:": PRINT:FOR ZJ=1 TO 5:IF ZS%(ZJ,1)=1 THEN PRINT:PRINT ZJ; " - ";TAB(8)ZS$(ZJ,1) 2035 NEXT ZJ : PRINT : PRINT "ENTER FILE NUMBER "; : INPUT ZA : IF ZS%(ZA,1)<>1 THEN PRINT : PRINT CHR$(7);"BAD CODE - TRY AGAIN" : PRINT : GOTO 2035 2037 ZF$=MID$("ABCDE",ZT%(ZA,1,1),1)+":"+ LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT" 'FIGURE OUT THE SORT KEY FILE NAME FOR THIS MASTER FILE 2040 PRINT : PRINT "ENTER MAJOR TO MINOR SORT FIELD NUMBERS" : PRINT : FOR ZJ=1 TO ZS%(ZA,7) : PRINT :PRINT ZJ;" - "; TAB( 8)ZN$(ZA,ZJ,1) : NEXT ZJ : PRINT 2045 FOR ZJ=1 TO ZS%(ZA,7) : INPUT "ENTER FIELD NUMBER ";ZQ$ :YF%(ZJ)=VAL(ZQ$) : IF YF%(ZJ)=0 THEN ZL=ZJ-1 : ZJ=ZS%(ZA,7) 2050 NEXT ZJ : IF ZL=0 GOTO 400 2055 Z5=0:ZZ5=0:PRINT:PRINT "THE SORT KEYS ARE BEING LOADED FROM THE '";ZS$(ZA,1);"' FILE." 2060 PRINT : PRINT "THERE MAY BE TIMES WHEN THE DISC DRIVE STOPS - NOT TO WORRY" : PRINT 2062 ON ERROR GOTO 2400:OPEN ZF$ FOR INPUT AS #ZQ+1:INPUT #ZQ+1, ZDUMMY$,ZDUMMY$ : INPUT #ZQ+1, ZDUMMY 'OPEN THE SORT KEY FILE TO READ THE ACTIVE RECORD NUMBERS & THROW AWAY THE EXISTING DATE, TIME & # OF ACTIVE RECORDS 2065 IF EOF(ZQ+1) THEN 2070 ELSE ZZ5=ZZ5+1 :INPUT #ZQ+1, YA%(ZZ5,3):GOTO 2065 'READ THE MASTER SORT KEY FILE 2070 CLOSE #ZQ+1:ZFLAG=0:IF ZZ5=ZS%(ZA,6) THEN ZK=ZZ5 ELSE ZK=ZS%(ZA,2):ZFLAG=1 2075 FOR ZJJ=1 TO ZK 'ZK=# RECORDS IN MASTER SORT FILE IF # REC. IN SORT FILE = # ACTIVE REC IN DATA BASE ELSE IT = THE CAPACITY OF THE DATA BASE 2080 IF ZFLAG=0 THEN ZR=YA%(ZJJ,3) ELSE ZR=ZJJ 2090 ZZ=1 : GOSUB 610 2100 IF ZL$<>LEFT$(ZBLANK$,ZSIZE%(ZA,1)) THEN Z5=Z5+1 :FOR ZJ=1 TO ZL:YA$(Z5)=YA$(Z5)+Y$(YF%(ZJ),ZA):NEXT ZJ :YA%(Z 5,1)=Z5:YA%(Z5,2)=ZR 2120 NEXT ZJJ 2125 IF ZFLAG=1 THEN ZS%(ZA,6)=Z5 ' CORRECT RECORDS ASSIGNED 2130 PRINT:BEEP:PRINT "THERE WILL BE A FILE SORT DELAY." :PRINT:PRINT 2140 ZZT$=TIME$ : ZT1=(VAL(LEFT$(ZZT$,2))*3600) + (VAL(MID$(ZZT$,4,2))*60) + (VAL(RIGHT$(ZZT$,2))) PAGE C - 1 PDS*BASE SYSTEM APPENDIX C Copyright 1985 2150 ZI1=1 : ZJ1=Z5 : ZP=0 2160 ZI=ZI1:ZJ=ZJ1 2170 IF YA$(YA%(ZI,1))>YA$(YA%(ZJ,1)) THEN SWAP YA%(ZI,1),YA%(ZJ,1):SWAP YA%(ZI,2),YA%(ZJ,2) :ZZS%=ABS(ZZS%-1) 2180 ZI=ZI+ZZS%:ZJ=ZJ-(1-ZZS%):IF ZI<ZJ THEN 2170 2190 IF ZI+1<ZJ1 THEN ZP=ZP+1:ZS9(ZP,0)=ZI+1:ZS9(ZP,1)=ZJ1 2200 ZJ1=ZI-1:IF ZI1<ZJ1 THEN 2160 2210 IF ZJ>0 THEN LOCATE ,1,1:PRINT YA$(YA%(ZJ,1)); 2220 IF ZP THEN ZI1=ZS9(ZP,0):ZJ1=ZS9(ZP,1):ZP=ZP-1:GOTO 2160 2230 PRINT:PRINT:PRINT:ZZT$=TIME$:ZT2=(VAL(LEFT$(ZZT$,2))*3600) +(VAL(MID$(ZZT$,4,2))*60)+(VAL(RIGHT$(ZZT$,2))) 2240 BEEP:ZT3=ZT2-ZT1:IF ZT3 < 120 THEN PRINT "ELAPSED TIME=";ZT3;" SECONDS" ELSE PRINT "ELAPSED TIME ="; INT(ZT3/60);" MINUTES "; INT(((ZT3/60)-INT(ZT3/60))*60); " SECONDS" 2245 PRINT : PRINT CHR$(7);"THE SORT IS FINISHED!!!!" 2250 PRINT : PRINT "THE REPORT SORT FILE IS BEING SAVED. 2270 OPEN YF$ FOR OUTPUT AS ZQ+1 2275 WRITE #ZQ+1,ZDATE$(ZA);ZTIME$(ZA) 'DATE & TIME THE FILE WITH THE DATE & TIME FROM THE DATA BASE MASTER FILE 2280 PRINT #ZQ+1, Z5:FOR ZI=1 TO Z5:PRINT #ZQ+1, YA%(ZI,2) :NEXT ZI 2290 CLOSE #ZQ+1:PRINT:PRINT "REPORT SORT KEY FILE '";YF$;"' IS CREATED." 2300 PRINT : PRINT "THE MASTER SORT FILE IS BEING SAVED. 2310 OPEN ZF$ FOR OUTPUT AS ZQ+1 2320 WRITE #ZQ+1,ZDATE$(ZA);ZTIME$(ZA) 'DATE & TIME THE FILE WITH THE DATE & TIME FROM THE DATA BASE MASTER FILE 2330 PRINT #ZQ+1, Z5 : FOR ZI=1 TO Z5 : PRINT #ZQ+1, YA%(ZI,2) : NEXT ZI 2340 CLOSE #ZQ+1 : PRINT : PRINT "MASTER SORT KEY FILE '";ZF$;" ' IS CREATED." 2350 GOTO 400 2400 '****** ERROR HANDLING 2410 IF ERR=53 THEN RESUME 2070 'MASTER SORT KEY FILE NOT ON DISC PAGE C - 2 PDS*BASE SYSTEM APPENDIX D Copyright 1985 FLOW CHART FOR CREATING A DATA BASE AND IT'S PROGRAMS :----------------------------------: : : : RUN DBDEF (Menu Option 1) : :-----------------: : To create the : ---->: DEFINITION FILE : : : :-----------------: :----------------------------------: : : : : : :----------------------------------: : : : : : RUN DBCREATE (Menu Option 2) : : : To create blank data : <------------: : base file(s) : : : : : :----------------------------------: : | : : : :----------------------------------: : : : <------------: : RUN DBOPSUB (Menu Option 3) : : : To create the "front : : : end" subroutines for : | a program (run for : | each program written): : : :----------------------------------: : : :----------------------------------: : : : RUN DBMANAGE (Menu Option 4) : : To append the "main : : program" to the oper-: : ational subroutines : : created by DBOPSUB : : : :----------------------------------: : : :----------------------------------: : : : DBOPSUB and DBMANAGE are appended: : to an ASCII file. After it is : : first loaded into memory it can : : SAVEd as a regular BASIC program : : file. : : : :----------------------------------: ------------------: : : : : : : : : : : : : : : <------------: V :-------------: : OPERATIONAL : : SUBROUTINES : :-------------: ---------->: MAIN PROGRAM: :-------------: : : : : : :-------------: : : ---------->:BASIC PROGRAM: : IN MEMORY : : : :-------------: Create the other programs by using the DBREPORT or DBSORT main program generators rather than the DBMANAGE program generator as shown above. PAGE D - 1