home *** CD-ROM | disk | FTP | other *** search
- dBASE Importing and Exporting
-
- by
-
- RICHY
-
- One of the things I like most about dBase is the ease of importing
- data, which is a big work saver when I get to save all the time needed to
- enter the data manually. Special options of the APPEND FROM and COPY TO
- commands make it easy to import and export data with dBase. The easiest way
- to import data is to use a word processer and format the data as regular
- text into rows and columns. Here is an example, (I have put the "to be"
- field names above the columns):
-
- Area
- State City code
-
- Missouri Cape Girardeau 314
- Pennsylvania Norristown 215
- California El Monte 818
- Hawaii Honolulu 808
-
-
- Each row or line equals one record, each column equals one field.
- Simply line up the fields and end each line with a carriage return.
- Then count the digits of each column and note them down for when you go to
- CREATE your data base. For the above example count the digits for each column.
- The correct counts are State = 15, City = 15, and Areacode = 3. Below is a
- look at the data base structure for this data base:
-
- Structure for file: M:AREACODE.DBF
- Number of records: 00000
- Date of last update: 00/00/00
- Primary use database
- Fld Name Type Width Dec
- 001 STATE C 015
- 002 CITY C 015
- 003 AREACODE C 003
-
- ** Total ** 00034
-
-
- Below shows how to import data from a text file. The "sdf" at the end
- of the command line tells dBase that the file which is being appended from is
- in the System Data Format:
-
- . use areacode
- . append from areacode.txt sdf
- 00004
- records added
- . list
-
- 00001 Missouri Cape Girardeau 314
- 00002 Pennsylvania Norristown 215
- 00003 California El Monte 818
- 00004 Hawaii Honolulu 808
-
- NOTE: This process is not sensitive to file tail. The .sdf tail is an
- option to help you keep track of what type of file it is. No tail is
- necessary for the process.
-
- Now here is a look at the records using the edit option of dBase. This
- shows that the importing was perfect, with the first character of the
- fields falling right after the colon. If you find this not to be the case
- when you use the System Data Format, (.sdf), then check the uniformity of
- your columns, recount the digits of your columns, and check this against
- the data base structure.
-
- RECORD # 00001
- STATE :Missouri :
- CITY :Cape Girardeau :
- AREACODE :314:
-
- RECORD # 00002
- STATE :Pennsylvania :
- CITY :Norristown :
- AREACODE :215:
-
- RECORD # 00003
- STATE :California :
- CITY :El Monte :
- AREACODE :818:
-
- RECORD # 00004
- STATE :Hawaii :
- CITY :Honolulu :
- AREACODE :808:
-
- Text is just as easy to extract with dBase with the COPY TO command:
-
- . use areacode
- . copy to areacode sdf
- 00004
- records copied
- .
-
- This extracts the data and copies it into a text file named
- areacode.txt. Any tail may be supplied if desired. If no tail is provided
- dBase will use the .txt tail.
-
- . copy to areacode.doc sdf
-
- The above command line will give a text file called
- areacode.doc.
-
-
- The other file type used for dBase importing and exporting is the
- delimited type. Instead of outputting a file in perfect rows and columns,
- this method outputs a file which is delimited with commas, apostrophes,
- quotation marks, and others as you can specify. I won't get into a lot of
- detail here, but simply say this is an excellent way to backup a .dbf file.
- Here is how you would use the delimited option:
-
- . use areacode
- . copy to areacode.cdf delimited
- 00004
- records copied
- .
-
- Here is what the output would look like:
-
-
- 'Missouri','Cape Girardeau','314'
- 'Pennsylvania','Norristown','215'
- 'California','El Monte','818'
- 'Hawaii','Honolulu','808'
-
- Notice the byte count would be less, since the trailing spaces have
- been trimmed. This can save up to 50% in disk space for keeping a backup data
- file. Here is how you would import the data back into a .dbf file.
-
- . append from areacode.cdf delimited
-
- NOTE: It would be a good idea at the time of backup to keep a copy
- of the .dbf structure along with the delimited backup data file. Here is how
- to make an easy copy of the structure:
-
- . copy structure to backup
-
- This will give you a .dbf file named backup.dbf which will be empty and
- ready to use in case of a loss of the original.
-
-
- When using the delimited option for output, you have a choice of
- how the file is delimited. Fields will be separated by commas, but you can
- select the character you wish the fields to be bracketed with. There is a
- WITH option you can use at this point. Say you have apostrophes in a field,
- and you want to avoid confusing the process, since the apostrophe ' is the
- default character dBase uses to bracket each field. Here are 4 examples, and
- their output. Notice the last one I inserted a comma in Cape,Girardeau.
- (The bracketing of each field allows for commas to be a natural part of a
- character field with out messing up the process of delimited file types.
-
- copy to filename.cdf delimited with *
-
- would yield
-
- *Missouri*,*Cape Girardeau*,*314*
- *Pennsylvania*,*Norristown*,*215*
- *California*,*El Monte*,*818*
- *Hawaii*,*Honolulu*,*808*
-
- Copy to filename.cdf delimited with "
-
- would yield
-
- "Missouri","Cape Girardeau","314"
- "Pennsylvania","Norristown","215"
- "California","El Monte","818"
- "Hawaii","Honolulu","808"
-
- Copy to filename.cdf delimited with +
-
- would yield
-
- +Missouri+,+Cape Girardeau+,+314+
- +Pennsylvania+,+Norristown+,+215+
- +California+,+El Monte+,+818+
- +Hawaii+,+Honolulu+,+808+
-
- Copy to filename.cdf delimited
-
- would yield
-
- 'Missouri','Cape,Girardeau','314'
- 'Pennsylvania','Norristown','215'
- 'California','El Monte','818'
- 'Hawaii','Honolulu','808'
-
-
- If the WITH option was used, then you would need to include it
- to import the data back into dBase, using the same delimiter you had use
- when exporting the file.
-
- Well that wraps up this little article. Hope it helps you out as you
- explore the power of dBase.
-