home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128CPM / PIPMAG-4.ARC / DBASE.IMP < prev    next >
Encoding:
Text File  |  2019-04-13  |  6.4 KB  |  197 lines

  1.                          dBASE Importing and Exporting
  2.  
  3.                                       by
  4.  
  5.                                      RICHY
  6.  
  7.        One  of the things I like most about dBase is the ease  of importing 
  8. data, which is a big work saver when I get to save  all the  time needed to 
  9. enter the data manually. Special  options  of the  APPEND FROM and COPY TO 
  10. commands make it easy to import  and export data with dBase. The easiest way 
  11. to import data is to  use a  word processer and format the data as regular 
  12. text  into  rows and  columns. Here is an example, (I have put the "to  be"  
  13. field names above the columns): 
  14.  
  15.                               Area
  16.   State           City        code
  17.  
  18. Missouri       Cape Girardeau 314
  19. Pennsylvania   Norristown     215
  20. California     El Monte       818
  21. Hawaii         Honolulu       808
  22.  
  23.  
  24.        Each row or line equals one record, each column equals one field.  
  25. Simply  line  up  the fields and end  each  line  with  a carriage  return. 
  26. Then count the digits of each column  and  note them down for when you go to 
  27. CREATE your data base. For the above example count the digits for each column. 
  28. The correct counts  are State  = 15, City = 15, and Areacode = 3. Below is a 
  29. look at  the data base structure for this data base: 
  30.  
  31. Structure for file: M:AREACODE.DBF
  32. Number of records: 00000
  33. Date of last update: 00/00/00
  34. Primary use database
  35. Fld   Name   Type   Width   Dec
  36. 001     STATE        C    015
  37. 002     CITY         C    015
  38. 003     AREACODE     C    003
  39.  
  40. ** Total **             00034
  41.  
  42.  
  43.        Below shows how to import data from a text file. The "sdf" at the end 
  44. of the command line tells dBase that the file which is being appended from is 
  45. in the System Data Format: 
  46.  
  47. . use areacode
  48. . append from areacode.txt sdf
  49. 00004
  50.  records added
  51. . list
  52.  
  53. 00001  Missouri        Cape Girardeau  314
  54. 00002  Pennsylvania    Norristown      215
  55. 00003  California      El Monte        818
  56. 00004  Hawaii          Honolulu        808
  57.  
  58.        NOTE: This process is not sensitive to file tail. The .sdf tail is an 
  59. option to help you keep track of what type of file  it is. No tail is 
  60. necessary for the process. 
  61.  
  62.        Now here is a look at the records using the edit option of dBase. This 
  63. shows that the importing was perfect, with the  first character  of  the 
  64. fields falling right after the colon.  If  you find this not to be the case 
  65. when you use the System Data Format, (.sdf),  then check the uniformity of 
  66. your columns,  recount  the digits  of  your columns, and check this against  
  67. the  data  base structure. 
  68.  
  69. RECORD # 00001
  70. STATE     :Missouri       :
  71. CITY      :Cape Girardeau :
  72. AREACODE  :314:
  73.  
  74. RECORD # 00002
  75. STATE     :Pennsylvania   :
  76. CITY      :Norristown     :
  77. AREACODE  :215:
  78.  
  79. RECORD # 00003
  80. STATE     :California     :
  81. CITY      :El Monte       :
  82. AREACODE  :818:
  83.  
  84. RECORD # 00004
  85. STATE     :Hawaii         :
  86. CITY      :Honolulu       :
  87. AREACODE  :808:
  88.  
  89.        Text  is just as easy to extract with dBase with the  COPY TO command: 
  90.  
  91. . use areacode
  92. . copy to areacode sdf
  93. 00004
  94.  records copied
  95. .
  96.  
  97.        This  extracts  the data and copies it into  a  text  file named  
  98. areacode.txt. Any tail may be supplied if desired.  If  no tail is provided 
  99. dBase will use the .txt tail. 
  100.  
  101. . copy to areacode.doc sdf
  102.  
  103.        The  above  command  line will give  a  text  file  called 
  104. areacode.doc. 
  105.  
  106.  
  107.        The other file type used for dBase importing and exporting is  the 
  108. delimited type. Instead of outputting a file  in  perfect rows  and columns, 
  109. this method outputs a file which is  delimited with commas, apostrophes, 
  110. quotation marks, and others as you  can specify.  I won't get into a lot of 
  111. detail here, but  simply  say this  is an excellent way to backup a .dbf file. 
  112. Here is how  you would use the delimited option: 
  113.  
  114. . use areacode
  115. . copy to areacode.cdf delimited
  116. 00004
  117.  records copied
  118. .
  119.  
  120.        Here is what the output would look like:
  121.  
  122.  
  123. 'Missouri','Cape Girardeau','314'
  124. 'Pennsylvania','Norristown','215'
  125. 'California','El Monte','818'
  126. 'Hawaii','Honolulu','808'
  127.  
  128.        Notice  the byte count would be less, since  the  trailing spaces  have 
  129. been trimmed. This can save up to 50% in disk  space for keeping a backup data 
  130. file. Here is how you would import  the data back into a .dbf file. 
  131.  
  132. . append from areacode.cdf delimited
  133.  
  134.        NOTE:  It  would be a good idea at the time of  backup  to keep a copy 
  135. of the .dbf structure along with the delimited backup data file. Here is how 
  136. to make an easy copy of the structure: 
  137.  
  138. . copy structure to backup
  139.  
  140.        This will give you a .dbf file named backup.dbf which will be empty and 
  141. ready to use in case of a loss of the original. 
  142.  
  143.  
  144.        When  using  the delimited option for output, you  have  a choice of 
  145. how the file is delimited. Fields will be separated  by commas,  but you can 
  146. select the character you wish the fields  to be  bracketed  with. There is a 
  147. WITH option you can use at this point. Say you have apostrophes in a field, 
  148. and you want to avoid confusing  the  process, since the apostrophe '  is  the  
  149. default character dBase uses to bracket each field. Here are 4  examples, and  
  150. their  output.  Notice the last one I inserted  a  comma  in Cape,Girardeau.  
  151. (The bracketing of each field allows for  commas to be a natural part of a 
  152. character field with out messing up the process of delimited file types. 
  153.  
  154. copy to filename.cdf delimited with *
  155.  
  156. would yield
  157.  
  158. *Missouri*,*Cape Girardeau*,*314*
  159. *Pennsylvania*,*Norristown*,*215*
  160. *California*,*El Monte*,*818*
  161. *Hawaii*,*Honolulu*,*808*
  162.  
  163. Copy to filename.cdf delimited with "
  164.  
  165. would yield
  166.  
  167. "Missouri","Cape Girardeau","314"
  168. "Pennsylvania","Norristown","215"
  169. "California","El Monte","818"
  170. "Hawaii","Honolulu","808"
  171.  
  172. Copy to filename.cdf delimited with +
  173.  
  174. would yield
  175.  
  176. +Missouri+,+Cape Girardeau+,+314+
  177. +Pennsylvania+,+Norristown+,+215+
  178. +California+,+El Monte+,+818+
  179. +Hawaii+,+Honolulu+,+808+
  180.  
  181. Copy to filename.cdf delimited
  182.  
  183. would yield
  184.  
  185. 'Missouri','Cape,Girardeau','314'
  186. 'Pennsylvania','Norristown','215'
  187. 'California','El Monte','818'
  188. 'Hawaii','Honolulu','808'
  189.  
  190.  
  191.        If  the  WITH  option was used, then  you  would  need  to include  it  
  192. to import the data back into dBase, using  the  same delimiter you had use 
  193. when exporting the file. 
  194.  
  195.        Well that wraps up this little article. Hope it helps  you out as you 
  196. explore the power of dBase.
  197.