Let’s Import

See all articles from CATS v6 n9
Author(s): Duane Parker
Publication: CATS Newsletter
Pub Details: CATS v6 n9 (Volume 6, Issue 9)
Date: January 1989
Pages: 4-5

Here I had 132 files on a disk, where is the one I want? If they were only in alphabetical order! The computer should be able to do that, but how? There is probably a utility in Super-Media Manager, or some- place, but what can we do with only the QL’s software? Put the directory into a file, order the lines, and print it. I don’t have a “sort” procedure in S-BASIC – what to do? ARCHIVE will order lists! First I need to import, and the QL User’s Guide (information section, pp. 1&2), tells me how. Several lines of code did it. (Flp_ or ram_ can be used to replace mdv_, if these devices are available.)

10 OPEN_NEW #6, mdv1_dir
20 DIR #6, mdv1_ :CLOSE #6
30 OPEN #6, mdv1_dir:REMark Makes dir list, opens it, & resets to beginning of the file
40 OPEN_NEW #7,mdv1_dir_exp
50 FOR i=1 TO 2:INPUT #6,x$:PRINT x$:REMark Removes the DIR title lines & shows them
60 PRINT #7,'"file$"'
70 FOR i=1 TO 200
80 IF EOF(#6) THEN EXIT i
90 INPUT #6,x$:PRINT #7,'"';x$;'"'
100 END FOR i
110 CLOSE #6:CLOSE #7:STOP

Now my “dir_exp” file is in the proper format and can be imported into ARCHIVE. The fields (only one in this case, “file$”) must be on the first line & enclosed in quotes. The rest of the lines must have all the fields in each line, with the character fields in quotes and the fields separated by commas. The lines are terminated with line feeds (<LF>, ASCII code 10, as S-BASIC does with “PRINT”). I then booted up ARCHIVE and typed: IMPORT “mdv1_dir_exp” AS “mdv1_dir”. Once the drive stopped, a DISPLAY command showed that the database was there and already OPENed. With an “ORDER file$ ;A” and then “DUMP”, I had my printed, alphabetized directory.

So importing can work. With a bit different program that uses the INPUT #i,x$:PRINT #j,x$ idea I copied COMPUSERVE’s “GO” index into a file, and them imported it into an ARCHIVE database. Information that comes from on-line sources is nicely terminated with a carriage return (<CR>, ASCII code 13) and a <LF> so the INPUT,PRINT idea serves as a simple method to generate files for IMPORTing.

We can even get DBASE databases into ARCHIVE, now that there are good program to transfer files from MS-DOS formats to the QDOS format. These utilities are IBMCOPY or DISCOVER and are available from dealers. DBASE III+ has the “COPY TO” command that will generate almost what is needed by ARCHIVE if the “DELIMITED” ) qualifier is used. The format of this command is:

COPY TO <filename>[fieldnames] DELIMITED.

The command, that is used with an open database, will generate a file with the contents of the designated fields (or all fields, if none are listed) with each data item separated by commas, and char- acter fields in quotes, almost as ARCHIVE requires. Please note that the < > and [ ] designate, respectively, re- quired and optional user imput, for this command and the <, >, [, and ] are not entered as part of the command. For example, if the DBASE database contained two character fields and one numerical field (item, brand, on_hand; for example) the DELIMited file lines might be:

“Disks, flpy”,”3-M”,500 “Ribbons”,”Epson, FX80″,20 etc.

Of course, the missing line for ARCHIVE is the field definition, “item$”,”brand$”,”on_hand”

We can put this into the export file by making a separate file with this line in it and joining it with the DELIMITED file. On a PC, we can use a simple editing program (EDLIN, SIDEKICK, etc.), MS-DOS (the procedure is: “COPY CON A:\fields.txt”, then type on screen: “items$”,”brand$”,”on_hand”, and then press F6), or a word- processing program (save the line as an ASCII text file) to generate this one-line file. The MS-DOS command: “COPY fields.txt + ourdb.txt archive.exp” serves to combine the two needed files into the one “exp” file that we need, with the field definitions in the first line, followed by the data in the required format. Then IBMCOPY is used to convert archive.exp to QDOS’s format and copy it on a QL disk or mdv.

The fields line can also be added to the “ourdb_txt” file with the use of the QL if we have already transferred it to the QDOS media (mdv’s, flp’s, or ram_disk’s). The QDOS COPY command does not chain files together, as MS-DOS does with the use of “+”, but we can OPEN_NEW #j,archive_exp file, PRINT the needed line to it, and then from the OPENed #i, ourdb_txt file repeatedly INPUT #i,x$: PRINT #j,x$ until all lines are printed. Of course, the files must then be CLOSEd. Easier and quicker is the SPL command from TOOL_KIT2, it will chain OPENed files together: SPL #i TO #j:SPL #k to #j, etc., does the job. Therefore, the following lines will make the proper file for import:

10 OPEN_NEW #5, mdv1_fields_txt
20 PRINT #5,"item$","brand$","on_hand"
30 OPEN #6, mdv1_ourdb_txt
40 OPEN_NEW#7, mdv1_archive_exp
50 SPL #5 to #7
60 SPL #6 TO #7
70 CLOSE #5,#6,#7:STOP

Thus, such files can be imported into an ARCHIVE dbf-file. Since DBASE’s field format is different than ARCHIVE’s, some changes must be made. DBASE field names may be only 10 characters long, so they will all be within the 13 character limit that ARCHIVE allows.

DBASE has five types of fields,

1) character (length up to 254),

2) numeric (decimal or integer, 3) logical (true, false),

4) date, and

5) memo (for blocks of text).

ARCHIVE has just the character (up to 255 charcters long) and numeric field types. DBASE requires that the length of character fields be designated when the database is created, and as records are added it fills out each field with spaces. In contrast, ARCHIVE stores the fields only to their actual length (the length of the character field is held in the first byte of the field, while numeric fields are a standard length). Thus, a DBASE db will usually occupy more file space than its equivalent ARCHIVE dbf. Memo fields are handled differently than the rest and probably can not be exported. Logical fields can not be directly exported, since they get printed as T and F, without quotes, in the DELIMITED file. The DBASE logical field names can be edited and changed to character fields, then “COPY TO, DELIMITED” command adds the quotes. Thus “T” and “F” can be imported into an ARCHIVE db fields. I have not done anything with “date” fields, but I assume that if they are converted into a standardized fromat by DBASE in the DELIMITED file they will also be enclosed in quotes.

I have thrashed around and around with these IMPORT files, many times getting error messages from ARCHIVE when the import files contained errors. From the results I have been able to develop the following requirements. So, if your “IMPORT” fails check this list.

Items required in the file:

1) The filename must have an extension, any extension (_exp, _a, etc.).

2) The 1st line must be the fields & fields must have $ for string fields & no designation for numerical fields.

3) All field-names must be delimited by ” “, and separated by commas.

4) All the data must be in the proper order in each line. Strings must be enclosed in quotes, ” “, while numeric data must be without quotes. Items must be separated by commas.

5) Data items may not have a ” sign in them; ARCHIVE becomes confused with this situation and will put the wrong data per field.

6) Fields may not have control charcters in them ( ASCII: #0-27, ARCHIVE takes them to be <LF>’s).

7) Fields may not be > 255 characters including the “”. Thus, only 253 characters can be IMPORTED, even though two more characters may be added later with ARCHIVE’s ALTER command. (Long DBASE fields can cause trouble here, they may be one character too long for ARCHIVE.)

8) The lines may be terminated by line feeds (ASCII #10), alone or carriage returns (ASCII #13) and line feeds, together, in any combination. QL S-BASIC, adds only the <LF>, while the export features of all of the PSION applications programs, except QUILL, put a <CR> and a <LF> at the end of each data set.

9) The PSION programs also add a CTRL Z character (#26) to the end of the file, but this apparently is not necessary for an ARCHIVE IMPORT procedure.

It should also be possible to export from ARCHIVE to DBASE db’s, since ARCHIVE will generate a DELIMITED file that may be imported into DBASE (by use of “APPEND FROM <filename> DELIMITED”). The DBASE db must be first created and opened with the “USE <db-name>” command. The created database must contain the proper number and types of fields in agreement with the “exp” file. DBASE does not use the first line to define its fields. The first line of the ARCHIVE export file may cause a problem, since it may have text (numeric field names) in items in which numbers are expected. The DBASE software may allow one to continue APPENDing after such an error has occurred. Otherwise the first line will have to be edited out of the export file.

I have limited this importing of db’s to DBASE since this is what I have available to me. Similar principles

[The article breaks off here in the printed issue; no continuation is printed.]

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.