  7                              Introduction to Datatrieve   3                                  Application Design   .                                        Outline  /           1.  System Analysis / Decision Phase    )               1.  Initial considerations                    2.  Record Layout   P               3.  Data  Requirements  (save  records,  delete  old records, move5                   old records to history file, etc.)    &               4.  Report Requirements     !           2.  System Foundations    ,               1.  Define Record Description   =               2.  Define File (Datatrieve, EDIT/FSL, RMSDEF)      %           3.  Create Update Routines               4.  Create Reports      P Introduction to Datatrieve                                               Page  2 Application Design    P           The  degree  of success with which any application is implemented withP      Datatrieve (or any other product)  depends  to  a  large  extent  upon  theP      planning  which goes into the implementation.  This session will cover someP      of the steps involved with emphasis on their  relationship  to  Datatrieve.P      Because  every  application  is  different,  and because some decisions mayP      depend upon subjective judgments, or company standards,  or  even  personalP      preference,  it is difficult to give more than general guidelines, and someF      examples showing the relative merits of some different options.    P           Before  anything  is  actually done in Datatrieve, some time should beP      given to planning the application design.  In all cases, the designer  mustP      consider  both  the  information  source  and the final result together, toP      produce the best design.  If there is any fixed rule which  can  be  statedP      for  all  applications,  it  is this:  that the end result should always beP      kept in view during all stages of application development.  It is  all  tooP      easy  to lose track of the original application and the persons for whom it>      was supposed to be designed.  Some common pitfalls are:    P           1.  The  designer  assumed  that  the  user  would  be  familiar  withM               certain data, or procedures, or other background information.     P               Often  the  user knows less than the designer has assumed would beP               known;  this can be such simple things as assuming that  the  userP               will  know  (without  being  reminded)  that  department codes areP               always 4 characters long, or that his department's purchase ordersP               always  begin  with the letter "W" and have a hyphen after the 3rdP               digit, etc.;  but it can also involve such basic functions of  theP               computer  system,  such  as  not  realizing  that when you erase aP               record  it  is  gone  forever  (some  people   might   assume   itL               automatically goes into some sort of backup or recovery area)   P           2.  The  designer  puts  in  extra features because they were "easy to%               add", or "look nice".     P               Sometimes  this  leads  to an application which is too complicatedP               for the intended user to understand.  If the application is  in  aP               new  area  or for users who are new to computing, it may be betterP               to do only the most simple application first, and wait to add  theP               additional  features  after the users have adjusted to the system,P               even if this means more application work.  (Of course, it  usuallyP               doesn't  hurt to do some advance work, such as including fields inP               the record definition which you know will be needed in the future:D               they can be "hidden" with a redefines until needed).    P           3.  The  application  makes  no  provision  for occasions where a data-               item is missing or incorrect.     P               Good  designs  should  make  provisions  for  exception  handling,P               correction of data on entry, validation of data on entry, or  someP               combination  of  the three.  The classic example is not making anyP               provision for a customer who overpays a bill  or  invoice:   other  P Introduction to Datatrieve                                               Page  3 Application Design    P               examples  might  be such things as looking up purchase orders on aP               partial order number when the user has lost or  torn  the  invoiceP               and  does  not  have  a  complete number, or being able to enter aP               telephone number without an area code when someone forgot  to  askP               for  it or write it down, and be able to add it later.  Similarly,P               if the application takes data from one file (or domain)  and  usesP               it to access data in another file (domain), there needs to be someP               way to escape the procedure gracefully if the first file  contains/               a data item which is incorrect.     L           4.  The application has nothing to do with the needs of the user.   P               Sometimes  the  application  was incorrectly described;  sometimesP               the user doesn't know what can be done and so  asks  for  what  heP               thinks  is  what  he wants;  sometimes the person implementing theP               application doesn't understand it (or perceives it to be somethingP               it is not);  and sometimes the designer just goes off on a tangentP               and comes up with the wrong application altogether.  This is  bestP               avoided  by having the designer and the user work together throughP               the application, and not just for a brief meeting to describe  theP               application  at  the  beginning,  and complain about it when it isP               finished.  One of the great advantages of Datatrieve is that it isP               simple  enough  to  learn  that  the  users  can develop their ownP               applications, and this is one of  the  best  ways  to  insure  the7               application fits the needs of the user.       P           Once  the  purpose  of  the  application is clear, the next step is toP      define all of the items of data which will be required by the  application,E      so that the record can be defined.  Some possible sources are:       P           1.  Blank  Forms.   If  an  existing  procedure  using  printed  paperP               forms is to be moved to Datatrieve, the form will have the desired(               data items marked on it.    P           2.  Existing  Reports.   There  may  be  existing  reports produced byP               hand or other means, which are to be produced by Datatrieve.   TheP               data  items  in  the report will indicate the data required in the               application.    P           3.  Other  Documents.   You  may  be  required  to supply documents toP               other  personnel,  accounting  departments,   or   to   governmentP               agencies:   you  can  examine  past  documents  to  determine whatP               information is involved, and base your design on that.  This mightP               include inventory reports, employment records, sales receipts, tax               records, etc.     P           4.  Copy  an  existing  application.   Very often a new application isP               similar to an existing one, and only needs the addition of  a  few  P Introduction to Datatrieve                                               Page  4 Application Design    P               new  data items, or the re-naming of some data items, and this canJ               be much faster than designing an application from scratch.    P           5.  The  data  already  exists.   There  are situations where the dataP               has already been placed in a file (by other  programs  written  inP               FORTRAN,  BASIC,  COBOL, etc., or by transfer from another system)P               and it is now desired to access it with Datatrieve to  obtain  newP               reports,  to  do  on-line inquiry, etc.  In this case, you have toP               create a  record  definition  which  matches  the  layout  of  theP               existing record:  this layout has to be obtained from whomever setP               up the existing data, or is responsible for maintaining  it.   YouP               may  still  have  choices to make on data names, redefines fields,A               and on procedures and report formatting, however.     P           6.  Hard  Work.   It  may  be  that  an entirely new application is toP               be designed, or a hand operation for which  there  is  no  currentP               document  defining the operation is to be moved to Datatrieve.  InP               this case, it may be necessary to follow the procedure (or  followP               a  person  who is going through the procedure) and write down whatP               the steps are, to  determine  the  information  used.   This  mustP               generally  be  done  more than once, to be certain of catching allP               the possible variations, and do not neglect the exception cases.      P           Each data item should be examined to determine if it is really needed,P      that it isn't duplicated elsewhere, and that it is of the proper type  (forP      example, that fields holding names and addresses will be long enough).  NowP      is also the time to determine if there is any other data item which  shouldP      be  added:   sometimes  an existing application may have data items missingP      because no-one has gotten around to having new forms printed, or there  hasP      been  a recent change in procedure, and a good time to add these data items,      is when the application is developed.    P           Once the data items have been determined, a record layout can be made.P      The primary goal here is to group related items together, and label them inH      a meaningful way.  Consider the following two record definitions.          01 FIRST_RECORD.s          10 NAME.w               20 FIRST PIC X(12).              20 MI PIC X.               20 LAST PIC X(14).d          10 HOME_ADDRESS.e!              20 STREET PIC X(20).t              20 CITY PIC X(12).               20 STATE PIC XX.               20 ZIP PIC 9(5).o
          .
          .
          .      ;  P Introduction to Datatrieve                                               Page  5 Application Design              01 SECOND_RECORD.          10 FIRST PIC X(12).          10 ZIP PIC 9(5).a          10 LAST PIC X(14).t          10 CITY PIC X(12).           10 STREET PIC X(20).           10 MI PIC X.y          10 STATE PIC XX. 
          .
          .
          .      ;    P      I  hope  most  people  would  realize  that  the first definition is betterP      organized than the second, with related data items  places  together.   TheP      group  headings (NAME, ADDRESS) are not essential, but do serve to organizeP      the data, and to make it easier to retrieve related  items  together:   forP      example,  on a report one could say PRINT ADDRESS rather than PRINT STREET,P      CITY, STATE, ZIP (though you can still retrieve individual fields when  youP      wish).  They also help to document the use of the data items, which is veryP      useful when the application requires modification, or  new  personnel  must9      familiarize themselves with existing applications.     P           It  is  also  useful  to  consider  the  final report while the recordP      definition is being made:  if one  particular  report  is  used  more  thanP      others,  then it will be helpful to arrange the fields in the record in theP      same order they will appear in the report, so that one can say PRINT recordP      rather  than having to explicitly state all fields to be printed.  If thereP      are multiple groups in a record, one can at least arrange the items  withinP      a  group  in  the  order  they will most often appear, and then specify theP      group names as they are needed.  Even if more than one  report  is  needed,P      there  will usually be groups of fields which are often associated (such asP      the fields which make up an address), and so should  be  grouped  together.P      This  point  can  not be overstated:  whenever any application is designed,P      one should always keep the final result in mind in order to keep the design&      heading in the right direction.    P           The  ordering  of data also needs to be considered.  Some domains willP      have one data entity per record, others will have more than one data entityP      per  record.   Consider two telephone directory records:  the first will be#      ordered in the familiar way.             01 FIRST_TELEPHONE.          10 NAME.d               20 FIRST PIC X(12).              20 MI PIC X.s              20 LAST PIC X(14).a  P Introduction to Datatrieve                                               Page  6 Application Design              10 NUMBER PIC 9(7).          10 LOCATION. #              20 BUILDING PIC X(12).h              20 FLOOR PIC 99.       ;    P      This  record definition has one entry per person, giving their location andP      telephone number, and is very  straight-forward,  but  consider  an  almostP      identical  application  where  several  persons might share a telephone, as      happens in some offices.  e          01 SECOND_TELEPHONE.           10 NUMBER PIC 9(7).          10 LOCATION.e#              20 BUILDING PIC X(12).t              20 FLOOR PIC 99.s               20 POINTS PIC X(6).&          10 NUMBER_INSTRUMENTS PIC 99.L          10 EXTENSIONS OCCURS 1 TO 10 TIMES DEPENDING ON NUMBER_INSTRUMENTS.              20 NAME.w$                  30 FIRST PIC X(12).                  30 MI PIC X. #                  30 LAST PIC X(14). "                  30 DESK PIC 9(4).      ;    P      Which  of these two records is applicable depends on the final report:  theP      first one organizes data with the user being the most important  item,  andP      would  be well suited for printing telephone directories, or for an on-lineP      inquiry system, or for people to find someone's telephone number  by  name;P      though  it  could  also be used to find telephones by building, or users byP      telephone  number,  etc.   The  second  definition  definitely  places  theP      telephone  first,  and then lists the users as subordinate items, and wouldP      be of greatest use to the person who has to maintain the telephone  system:P      reporting   this   domain  by  user  would  be  very  difficult.   If  bothP      applications need to be met, than another definition  altogether  might  be      needed.       nP Introduction to Datatrieve                                               Page  7 Application Design          01 USER_REC.           10 NUMBER PIC 9(7).          10 NAME.i               20 FIRST PIC X(12).              20 MI PIC .              20 LAST PIC X(14).e      ;        01 TELEPHONE_REC.          10 NUMBER PIC 9(7).          10 LOCATION.s              20 BUILDING X(20).               20 FLOOR PIC 99.m          10 CONNECTION.               20 MDF PIC X(10).              20 DESK PIC 9(4).      ;    P      These  two  domains would then be accessed separately when one contains theP      relevant information, or they could be joined  together  with  a  VIEW  (orC      JOIN) when information from both is needed at the same time.     P           One  other  factor to consider in the first phase of the design is howP      the information will change with  time.   In  the  case  of  the  telephoneP      directory,  any  updates  will  probably  just  replace  the old data:  forP      example, if a person moves, then the record with that persons name will  beP      modified  to show the new telephone number.  This simple replacement is notP      the only possibility, however.  In the case of a domain which stores  salesP      receipts,  for  example, new data will be added for each sale, but old dataP      may not be deleted.  Since this would eventually result in an immense file,P      there  may  have  to be some provision to remove old data:  this might be aP      separate procedure to simply delete records of more than a certain age,  orP      the old records may be moved to a separate historic file, or there may be aP      procedure where, when payment is received, then the corresponding  sale  isP      removed  from  the  sales  domain and the transaction recorded in a paymentP      received domain, which may in turn be purged of  records  of  more  than  aP      given  age.   Alternatively,  the  records  may all have to be kept for oneP      fiscal year for accounting purposes, in which case the size of the file mayP      have  to  be  predicted,  to  allow  enough  data to be stored.  To preventP      unnecessary work, and to avoid mistakes, it is better to develop proceduresP      which will automatically transfer data, rather than having a person look upP      the record to be moved, move the data items by hand,  and  delete  the  old      record.    P           Once  the  data  items have been determined, and the basic form of theP      record  has  been  chosen,  the  record  can  be  defined.   Normally,  theP      definition  follows directly from the data, but there are some data type to      consider.     aP Introduction to Datatrieve                                               Page  8 Application Design    P           In  the  case of text, the choices are usually just to make the stringP      long enough to hold the necessary data, and whether to use a T edit-string,P      but there are sometimes questions as to how the data should be broken down.G      In the examples given before, all names were defined liked this:  t            10 NAME.s               20 FIRST PIC X(12).              20 MI PIC X.n              20 LAST PIC X(14).m  :      but they could just as easily be defined like this:          10 NAME PIC X(27).  g  P      The  only  difference  is in how the data can be retrieved:  in the case ofP      the former, the names may be sorted in alphabetical order by last name.  InL      the latter case, this can be done if the names are entered in the form         Lederman, Bart Z.    (      but not if the data is in the form         Bart Z.  Lederman    P      and  if,  for  example,  the  data is to be used to prepare mailing labels,P      where the name should be in the normal order of first name first, and  alsoP      to  be  used  for  a  telephone  directory where it has to appear last nameP      first,  then  the  first  definition  which  allows  access  to  the  namesP      separately  is  the  one  to use.  If the name were just used to record theP      name on a sales slip and did not have to be sorted by last name,  then  theP      second definition is adequate, but consider the problem also of normalizingP      data.  If the first definition is used, then the names will be entered in aP      fixed  format:   the  first  names,  middle initials, and last names of all5      records will be in fixed positions, like this:           Burt         A Roseberryp      David          Saad      Diana          Washburn      Harold       T Glaser      Doug           Morellyl      Cynthia        Mealys      Bart         Z Lederman  P      In  the  case  where  the  name is just one field, the data could look likeD      that, but there is nothing to stop it from looking like this:     iP Introduction to Datatrieve                                               Page  9 Application Design          Burt A. Roseberry      Saad, David      Diana          Washburn      Glaser, Harold To      Morelly, Douglas (Doug)      C Mealy      B. Z. Ledermane  P      While  this  is  just  an  example  using  names, where order is not vital,P      consider a parts inventory  application,  were  different  people  will  beP      entering  data.   If you do not want 20 different people to enter the namesP      of the parts inventoried in 20 different ways, you may want to define  someP      fixed  subdivisions, to force the data to be normalized.  You may also wantP      validation tables to insure the same name is always used for a  given  part/      (or the equivalent in your application).  e  P      In  the case of numbers, again the size is usually known, and the choice isP      for a data type.  Display (PIC 9 without a qualifier) is easy to  use,  andP      can  be transferred to other languages, but is not efficient in space used.P      INTEGER or COMP takes up less space, and will always come out to be a wholeP      number,  but  has  the  drawback  that  it will not always work with tablesP      (particularly on PDP-11s).  Consider this application, where  you  want  toP      store  the department as a number (your departments may be numbered, or youP      might want to save storage space, or you may want to be able to  limit  theP      field to certain valid entries only), and then use a table to print out the      department name:           01 : "Personnel",      02 : "Employment",B      03 : "Accounting",       04 : "Engineering",      05 : "Shipping"
          .
          .
          .  P      In  this  case the department number stored in the record should be DISPLAYP      (the default) and not INTEGER, even though the numbers  in  the  table  areP      integers,  as  the  table look up works on characters even if the left sideP      looks like a number.  If the department names  are  put  in  a  domain  andP      linked  with a view, or are a domain table (VAX only), the the number couldP      be INTEGER, but will probably not be an advantage if keys are used properly      (covered later).     P           REAL  or  Floating Point numbers (COMP-1 and COMP-2) look inviting, asP      they can store a very wide range of numbers in  a  compact  space,  and  itP      isn't  always  necessary  to know the exact range when defining the record.P      They are useful for scientific data and some other  applications,  but  allP      floating  point  numbers  (and not just in Datatrieve, or on DEC computers,P      but everywhere) have the disadvantage of something called  rounding  error.P      The  result of this is that you can enter a whole number such as 12, and it nP Introduction to Datatrieve                                              Page  10 Application Design    P      may convert to 11.9999999:  to a scientist or  mathematician  this  may  beP      close  enough, but you will find if you are dealing with sums of money thatP      some accountants don't think $11,999.99 is the same as  $12,000.00  and  ifP      you  are  dealing  with inventory, your boss might like to know how you canP      have 11.9 widgets in stock.  For these applications, you may want to  avoid      REAL numbers.    P           The  other  number  types  (COMP-3,  COMP-5,  and  COMP-6)  are, in myP      opinion,  only  needed  if  you  have  to  interface  to   existing   COBOLP      applications,  where  the  numbers have already been stored in one of theseP      forms.  For new applications, they really have nothing to  recommend  them,P      as INTEGER is more compact and the math is faster, and you still have to goP      to DISPLAY to use tables.  Also,  there  is  an  advantage  if  DISPLAY  orP      INTEGER  is  used and the field can be a key.  Since COBOL can read DISPLAYP      and INTEGER types, there is no problem going back from Datatrieve to  COBOLP      should  it  be  necessary,  and  since  BASIC and FORTRAN often cannot readP      COMP-3, COMP-5 and COMP-6, there is a real handicap if these types are used>      and the data then has to be accessed by other programs.    P           The  data  type  that seems to trip people up most often is DATE.  TheP      trick here is that DATE looks like a character string when  it  prints  outP      something  like  "13-Apr-84",  but  it  is  in  fact stored internally as aO      number.  Many problems with DATE can be avoided in the following manner:  n        rather than doing this:    B      PRINT domain WITH TRANSACTION_DATE = *."date of transaction"         it is better to to this:  s        DECLARE WHEN USAGE DATE.m#      WHEN = *."date of transaction" .      PRINT domain WITH TRANSACTION_DATE = WHEN  P      If  this  is  done,  then  the  user  can  enter  the date when prompted asP      "April 13, 1984"  or  "13/04/84"  or  "13-APR-84",  or  any   other   validP      Datatrieve date format, and Datatrieve will convert it to a number and do aP      correct numeric comparison on the date stored in the domain:  this may  notP      happen  if it is prompted for as part of the RSE.  Datatrieve dates do haveP      two potential drawbacks, however.  The  first  is  that  it  is  an  8-byteP      integer,  and  some other languages like FORTRAN can't handle them directlyP      (though routines which convert dates have been  published  and  are  fairlyP      easy  to  use),  and  the conversion from the numeric date in clunks to theP      displayable date is cumbersome at best.   If  transfer  of  data  to  otherP      languages  or systems is important, than you may have to store your date asP      a character string, or perhaps a three numbers for  month,  day  and  year.P      Also,  (on  the  PDP-11 and PRO-350 at least) an 8-byte integer cannot be aP      key in a file, so the DATE cannot be keyed (more on keys later),  so  againP      the  date  might  be  stored  as  a character string or 3 numbers.  AnotherP      problem, but one which can be overcome, is that it is a bit  cumbersome  toP      look  up a particular month with the Datatrieve data type.  If you want all uP Introduction to Datatrieve                                              Page  11 Application Design    D      of the records for March, you have to do something like this:    #      DECLARE FIRST_DATE USAGE DATE.h"      DECLARE LAST_DATE USAGE DATE.      FIRST_DATE = 01-MAR-84       LAST_DATE = 31-MAR-84E      PRINT domain WITH TRANSACTION_DATE BETWEEN FIRST_DATE, LAST_DATE   P      What this won't solve is the case where the domain may cover several years,P      and you want all March records from any year  (to  compare  one  year  withP      another,  etc.).   In  this case also, you will have to store the date as aP      character string or separate numbers.  On the other  hand,  the  DatatrieveP      date  can do some things well:  as noted before, if prompted for separatelyP      it will accept the date in several different forms, and will also print  itP      out in many different formats simply by changing the edit string (includingP      some nice extras, like the day of the week).  Times may also be  stored  asP      part  of  the  date,  though  retrieving  this  information  is still a bitP      cumbersome.  Another type of transaction the DATE  type  does  well  is  inP      computing  future  dates, such as the case where you want to find the bills      due this week.  u  #      DECLARE FIRST_DATE USAGE DATE.i      FIRST_DATE = "TODAY"t*      DECLARE ONE_DAY USAGE COMP PIC 9(18).      ONE_DAY = 864000000000m"      DECLARE LAST_DATE USAGE DATE.,      LAST_DATE = FIRST_DATE + ( 7 * ONE_DAY)=      PRINT domain WITH DUE_DATE BETWEEN FIRST_DATE, LAST_DATEo  P      A  procedure like this will always pick up today's date, and add seven daysP      to it without user intervention, and will be much easier to use than if theP      date  was  stored as a character string or as separate year, month, and dayP      values as you would have to do a lot of  math  to  check  for  weeks  whichP      overlapped  the  start of a new month, check for leap years, and other suchP      special conditions.  By the way:  if you want to find all of the bills  dueP      last week, do not subtract 7 times ONE_DAY:  make ONE_DAY negative, and add      negative 7 days thus:    .      FIRST_DATE = LAST_DATE + ( -7 * ONE_DAY)   P      Datatrieve  sometimes has trouble subtracting dates, but will add correctlyP      even if one  number  is  negative.   Also  remember  that  with  a  BETWEENP      qualifier,  the  first value must be less than the second value to retrieve      the data properly.  e  P           Once  the data types have been defined, there is still the question ofP      what to call each field.  This is not always as easy as it may  seem.   ForP      the  sake  of  consistency, some organizations might insist on this type of      definition     P Introduction to Datatrieve                                              Page  12 Application Design          01 INVENTORY_REC.          10 INVENTORY_PART.,-              20 INVENTORY_PART_NAME PIC X(20)G$                  QUERY_HEADER "Part"#                  QUERY_NAME "PART". 0              20 INVENTORY_PART_QUANTITY PIC 9(5)#                  EDIT_STRING ZZ,ZZ9t(                  QUERY_HEADER "Quantity"%                  QUERY_NAME "NUMBER".e
          .
          .
          .      ;  P      I  don't  want  anyone  to  think  that this is wrong, as it does certainlyP      organize the  data  well,  but  in  some  applications  it  may  have  someP      drawbacks.   First:   if  this  domain is only used for printed reports theP      long names are no problem, but if it used  interactively,  there  would  beP      problems  as  the  names are too long to type in comfortably, and the queryP      names don't always match the  query  headers.   Second:   the  extra  queryP      headers  and  names take up working space and take longer to search though,P      and require the computer to do more work.  (On the PDP-11 or PRO-350,  theyP      may   even  take  up  enough  extra  pool  to  make  the  application  failP      completely.) My approach in this application would  be  to  call  the  partP      "PART" and the quantity "QUANTITY" or "NUMBER", and let the record name andP      group header identify them as being relevant to inventory.   Just  to  give!      both sides, consider this:           01 INVENTORY_RECORD.a          10 PART PIC X(20).a          10 STOCK.5              20 QUANTITY PIC 9(5) EDIT_STRING ZZ,ZZ9. !              20 LOCATION PIC 999.s          10 BACK_ORDER. 5              20 QUANTITY PIC 9(5) EDIT_STRING ZZ,ZZ9.i              20 SOURCE PIC 99.
          .
          .
          .      ;  P      It  is  possible  to  get  to  both  quantities  by  using  the group namesP      (STOCK.QUANTITY and BACK_ORDER.QUANTITY), but since the  group  name  wouldP      always  have  to be used to get to the back order quantity, why not call it(      BACK_QUANTITY in the first place.    P           A   related   matter   which  will  never  be  settled  to  everyone'sP      satisfaction is how much to abbreviate names.  An abbreviated name is handyP      if  you  are using the data interactively and don't want to type a lot, butP      if it is too short it won't adequately describe the data.  For example, the,      inventory record could be reduced to:    P Introduction to Datatrieve                                              Page  13 Application Design            01 INVENTORY_REC.-          10 IN PIC X(20) QUERY_HEADER "Part".,C          10 IQ PIC 9(5) EDIT_STRING ZZ,ZZ9 QUERY_HEADER "Quantity".f
          .
          .      ;  P      While  someone very familiar with the application, and who knows that IN isP      the inventory number, could type in the field names  quickly,  anyone  elseP      using the data would have a difficult time trying to figure out what any ofP      the fields actually are.  One way to test your field names is to write themP      out  on a piece of paper and then give it to a person who knows the generalP      area of the application but not your design (and doesn't have to know aboutP      computers  or  Datatrieve)  and  ask them to identify what each name standsP      for:  if they cannot do it  reading  directly  from  the  paper,  you  haveP      probably  made  your abbreviations too short.  Remember also that the namesP      serve to document the data items, and if you have to go back and work  withP      the  domain after a six month absence, you may then wish you made the names!      a little more descriptive.  t  P           Once the record is finally defined, then its time to define the domainP      (which simply ties together the names of the record, domain and file),  andP      define  the  file.   The  big  choice in defining the file is the choice ofP      keys, if any.  A KEYED (synonym INDEXED) file is one which, in addition  toP      storing the data, also stores an index which provides a short-cut to accessP      the data.  An index is very much like the index of  a  book:   rather  thanP      having to search each page to find an item of interest, the index tells youP      which page to go to directly to find that item.  Also, like an index  whichP      is  in  alphabetical order to make finding your item easier, the file indexP      is kept in order (alphabetical or numeric) to make searches faster.  UnlikeP      a  book  index, a file index generally has an entry for every record in theP      file, so it is a bit larger in proportion to the data than  a  book  index,P      and it may be configured to index more than one field in the record.  There2      are basically four reasons for using a key:    *           1.  Faster access to the data.    P               If you will be retrieving certain data items, and the criteria forP               retrieval is the contents of a  particular  field,  you  can  makeP               retrieval  faster by making that field a key field:  that way, theP               system can search the index rather than the entire  file  to  findP               the data.  Note that this works only for some types of retrievals,P               notably EQUALS (numeric and alphabetic), and over a  range.   NoteP               particularly  that  CONTAINING  is  NEVER  keyed:   it  is  alwaysP               necessary to read through the entire domain.  For example, in  theP               telephone lists previously described, if you are going to retrieveP               entries with the command NAME = "---"  a  key  will  help,  but  aP               retrieval  by NAME CONTAINING "---" will not be helped with a key.P               Keys are especially important if the domain will be part of a VIEWP               or  a CROSS, but less important in domains which use a single file lP Introduction to Datatrieve                                              Page  14 Application Design    P               and are nearly always accessed as a whole.   Using  the  telephoneP               file  again  as  an  example:   if  it  was primarily to act as anP               on-line inquiry system, having the most accessed field  as  a  keyP               would  greatly  increase  the speed of information retrieval.  If,P               however, it was used mostly to print a telephone directory,  whereP               the  entire  file  (domain)  is  printed  at once, a key might notP               increase the speed of  the  application  any  (but  see  the  next               paragraph).  i  +           2.  Imposing order on the data.  E  P               The  data  in an indexed file is ALWAYS sorted by the primary key,P               and if you access the  data  without  saying  SORTED BY,  it  willP               automatically  come back sorted by the primary key.  Since sortingP               always takes time, if  you  know  the  domain  will  primarily  beP               reported  in  a certain order, you can make that field the primaryP               key, and save a lot of time by not having  to  re-sort  the  data.P               The  more items there are in the file, the more time you will saveP               by not re-sorting them.  In the case of the  telephone  directory:P               having   the   name   as   a   key  would  keep  the  file  sortedP               alphabetically, so it would take less time to generate a telephone*               directory ordered by name.    &           3.  Preventing duplicates.    P               There  is  an  optional  qualifier  on  all  keys which permits orP               prevents duplicates (two or more records with the same key).  ThisP               has  such  uses  as preventing the telephone directory from havingP               two  or  more  people  with  the  same  telephone  number,  or  onP               applications  such  as employment records, you may want to preventP               the accidental entry of two employees with the same identificationP               number.   By  making this number a key (primary or alternate), andP               specifying NO DUP, it will be impossible for  anyone  to  enter  aP               duplicate number, even deliberately:  RMS simply won't permit it.   #           4.  Preventing changes.  H  P               There  is  another attribute to permit or prevent a keyed field toP               be changed (using the MODIFY command).  This can be handy for manyP               applications:    consider  a  domain  which  keeps  track  of  jobP               assignments, where the original due date is stored by the manager,P               and  the  person  assigned  the  job  will  update the record withP               relevant information.  This means the user must have MODIFY accessP               to  the  domain,  but  this  will  give  them modify access to allP               fields, and you may not want them to change the due date.  If  theP               due  date  is made a key (primary or alternate) with the NO CHANGEP               attribute, the user will then be able to modify  other  fields  toP               update  them,  but  not  the  due  date:   no  matter  what accessP               Datatrieve or CDD allows, RMS will not permit it.  Two  things  toP               remember:   first, the primary key can NEVER be changed.  If it isP               wrong, you have to delete the record, and store it all over  again rP Introduction to Datatrieve                                              Page  15 Application Design    P               with the correct key.  This is an inherent factor in the operationP               of RMS, and cannot be altered.  The other thing is that  NO CHANGEP               on  a  key does not mean no delete, so if you don't want your userP               simply to delete the record and put in another, give  them  modifyG               access but not erase access with Datatrieve or the CDD.       P           With these factors in mind, the appropriate fields can be selected forP      keying.  For example, the telephone records shown  earlier  would  probablyP      have  the  telephone  number  as  the  key,  as the data will most often beP      retrieved by saying NUMBER = ----- or some  similar  command.   Keying  theP      name    might    not    help    if    retrievals    are    often   of   theP      NAME CONTAINING "--------" type, but may  keep  the  file  sorted  in  nameP      order,  which  would be helpful if it is most often reported in name order.P      In the last telephone  example,  where  the  data  was  split  between  twoP      domains,  the  number  should  definitely be the key for both files, as theP      field which joins domains together in a VIEW  or  CROSS  should  ALWAYS  be      keyed for fast access.  H  P           Keep  in  mind  that  keying  a  field  means  that more space will beP      occupied by that file (on disk) than if it were not keyed, so  do  not  keyP      everything:   you  should show some discrimination, and key only the fieldsP      which will result in a benefit to your application.  Occasionally, this mayP      mean  bringing  the application up with few fields keyed, and then using itP      for a while to see which fields are most  often  accessed,  and  which  areP      accessed  in  a  way  in  which  keys would be beneficial.  The various RMSP      utilities can be used to move the data from one file  to  another  with  anP      updated  set of keys to provide faster access to the data:  you do not haveP      to make any changes in Datatrieve when a field changes from  not  keyed  toP      keyed,  and vice versa, provided you do not change the actual layout of theP      record:  Datatrieve is "told" by RMS which fields are keyed when the domainP      is  readied.  (If you change the name of the file, you will have to correct      the domain definition.)    P           Unless  this  is  an  application where the data file has already beenP      created elsewhere for you (in which case data and the selection of keys hasP      already been done), you must now create a file into which the data will go.P      The easiest way is to use the Datatrieve  DEFINE FILE  command.   The  fileP      created  by  this  command  may  not  be  the  best possible file for everyP      application, but it will work, and should at least be a  reasonable  designP      if  you  have done a decent job of selecting record organization and choiceP      of keys.  Use of the keywords available in Datatrieve can help,  especiallyP      the  ALLOCATION keyword.  If you can make a reasonable guess at the size ofP      the file, ALLOCATE space for it  when  you  define  it.   This  most  oftenP      happens  when  you  are creating a new domain from an old one, and know theP      size of the old file.  If you have some experience  with  RMS  and  a  goodP      knowledge  of  the  application, you may be able to increase performance byP      defining a different file structure with one of  the  RMS  utilities  (DES,P      DEF,  EDIT/FSL,  etc.),  but even in this case, it is best to define a fileP      with Datatrieve first, as this will get the position and type of all fieldsP      correct,  and  then modify it where a change is indicated.  If you have not  P Introduction to Datatrieve                                              Page  16 Application Design    P      learned much about RMS, use the file Datatrieve  gives  you:   it  will  beP      better  than  the  file a person defines without a fairly good knowledge ofP      file design and the application involved.  The one exception is if you  putP      your  data  into  the file with Datatrieve first:  once the file is filled,P      the various utilities can measure how much space will be  needed  to  storeP      your  data  and  how  the keys are distributed, and can do a fair amount ofP      optimization when creating a new file to hold that data without your havingP      to  know  a lot about file optimization.  One minor point:  when DatatrieveP      creates the file, it does not store the  name  of  the  field  in  the  keyP      descriptor  (at  least on PDP-11 and PRO-350), so you might want to use oneP      of the file utilities just to go in and put the names of the  correspondingP      fields  on  the  keys.  That way, if someone looks at the file later (with,P      for example, DES or DISPLAY/ATTRIBUTES) it will be easier to determine whatP      is in the file, and to match the file with the corresponding application.    P           Now  that  the record, domain and file are defined, it is necessary toP      load in or modify the data.  You can teach everyone  basic  Datatrieve  andP      let  them  use  the STORE or MODIFY commands, but it is often better to useP      pre-defined routines.  First, a general rule to remember is  the  less  theP      user  has to do, the fewer mistakes will be made.  Second, the users may beP      in positions where they don't have time to learn the computer, or  you  mayP      not  want  them to learn to use the computer:  if your sales staff is goingP      to enter sales receipts, you want them to spend as much  time  as  possibleP      selling,  and  as little time as possible doing computer and paper work.  AP      pre-defined procedure will help everyone, and may also help keep  the  dataP      in  a  clean  form  (like  the  jumbled  names  demonstrated earlier).  The$      procedure may be very simple:      P Introduction to Datatrieve                                              Page  17 Application Design    !      DEFINE PROCEDURE STORE_SALESy      READY SALES WRITE"      DECLARE SALE_DATE USAGE DATE.      DECLARE YOUR_CODE PIC 99.      DECLARE ANOTHER PIC X.c:      DECLARE TOTAL_SALE PIC 9(5)V99 EDIT_STRING $$,$$$.Z9.6      DECLARE TEMP_COST PIC 9(3)V99 EDIT_STRING $$$.Z9.      DECLARE TEMP_ITEM PIC XX.      DECLARE CORRECT PIC X.       DECLARE ALWAYS PIC X.      ALWAYS = "Y"       WHILE ALWAYS EQ "Y" BEGIN           YOUR_CODE = 0o5           WHILE YOUR_CODE NOT IN SALESMEN_TABLE BEGINt/                YOUR_CODE = *."your code number"y
           ENDm           SALE_DATE = "TODAY"            TOTAL_SALE = 0           ANOTHER = "Y"a)           WHILE ANOTHER EQ "Y", "y" BEGIN !                TEMP_ITEM = *.ITEMo                TEMP_COST = 0                CORRECT = "N")                WHILE CORRECT NE "Y" BEGIN &                     TEMP_COST = *.COSTL                     IF (TEMP_COST BETWEEN 0.01 AND 99.99) THEN CORRECT = "Y"H                     IF CORRECT NE "Y" THEN PRINT "Please re-enter cost."                END&                STORE SALES USING BEGIN(                     SALESMEN = YOUR_CODE$                     ITEM = TEMP_ITEM$                     COST = TEMP_COST                END2                TOTAL_SALE = TOTAL_SALE + TEMP_COST-                ANOTHER = *."Y for more items" 
           ENDm?           PRINT "Total for this sale was ", SPACE 1, TOTAL_SALE       END      END_PROCEDURE          salesmen_tablei        01 : "J. Smith",t      02 : "B. Brown",       03 : "T. Jones"      END_TABLE  P      I  am  not  claiming this is an ideal procedure:  it is just to demonstrateP      some possible features.  The first WHILE is used to keep this one procedureP      on  the  screen,  and  would be used if the application were started in theP      morning and kept running on a terminal all day.  The purpose  of  YOUR_CODE iP Introduction to Datatrieve                                              Page  18 Application Design    P      is  to  allow  the  user  to enter a number and have it validated against aP      table BEFORE storing it in the record (in this case, there must not  be  anP      entry  for  0  in  the table, or an ELSE at the end, or every entry will beP      valid).  If a VALID_IF clause were put in the record definition,  it  wouldP      abort  the transaction AFTER all of the data is typed in, which would annoyP      the users, and waste time.  Similarly, TEMP_COST is also used to check  forP      valid  data  before  storing  (and  to calculate TOTAL_COST), and TEMP_ITEMP      could also be validated against  a  table  or  domain.   The  SALE_DATE  isP      automatically  set  to TODAY, which saves the user from having to type in aP      field which can be obtained automatically, and which eliminates a  possibleP      source of user error.  The last loop is used to store each individual item,P      and keep track of the total (this implies an OCCURS clause  in  the  recordP      definition   with   ITEM  and  COST  in  the  variable  part).   AdditionalP      enhancements could be for the procedure to calculate sales tax,  or  modifyP      the  inventory  data  base  to reflect the items sold, or the total cash onP      hand in the store, and so on.  There is obviously a  good  deal  more  thatP      this procedure could do:  its purpose is to be an short example of the typeP      of validation processing which can be done to insure that correct  data  isP      entered,  and  to  give  the  user some useful messages when something goes
      wrong.  y  P           Once  the  domain  has  been created and populated, the data is almostP      always desired in one or more reports.  If the goal of the application  wasP      well  defined  at  the  beginning, producing the report should follow quiteP      easily from the record layout.  Just as with the selection of  data  items,7      the report layout may come from several sources:  v             1.  Blank Forms.    P               If  you  are  converting  a paper operation to Datatrieve, you mayP               want your new form to match  the  old  form  (you  might  even  beP               putting  pre-printed  forms into your hard copy printer).  In thisP               case, you can just copy the layout of  the  form  in  your  report               procedure.    !           2.  Existing Reports.  i  P               If  you are developing an application to match an existing report,G               it can serve as the template for your report procedure.  r              3.  Other Documents.    P               In  this  case, the format of the data might be less well defined,P               but  may  still  serve  as  a  template.   For  example,  if  yourP               application  is  based on a document which has the department nameP               in the upper left corner, then the sales for the day by  salesman,P               then  the  sales  for the month at the bottom of the document, youP               may wish to follow this general format in your report so the usersL               will have less of a difference to adjust to when converting.     tP Introduction to Datatrieve                                              Page  19 Application Design               4.  Existing data.    P               This will probably also fall under the category of "Hard Work", asP               in most cases the report desired may not be defined, though it mayP               be that the reason the application was designed in the first placeM               was to derive certain information from an existing data base.  S             5.  Hard Work.    P               It may be that the report will have to be designed from scratch.    P      The  subject  of  actually  using  the report writer is one that requires aA      dedicated session, and will not be further discussed here.     