/* This macro must be run from within the MFF database that you wish to */
/* import into.  It reads a text file that is formatted as: */
/*     one record per line and */
/*     each field is separated by a separation character and */
/*     the fields are in the same order as in the MFF database */

/* For instance, the following line from the text file could be imported */
/* into the address_book database on the master diskette: */
/*  Gary\Samad\Software Visions, Inc.\P.O. Box 3319\Framingham\MA\01701 */

/* This is the separator character.  Currently set to TAB which is used */
/* by MaxiPlan and ProWrite, among others */
sep = '09'x;

/* all pipes ('|') are turned into NEWLINES for multi-line fields */
/* change this if you please */
alt_newline_char = '|';

/* open the text file for import */
options results;
options failat 20;
string_request "Enter the name of the import file:";
if ((rc ~= 0) | (result = "")) then exit;

if (open(importfile,result) ~= 1) then
  do;
    display "I could not open the file '" || result || "' for importing.";
    exit;
  end;

/* read the first record */
text_rec = readln(importfile);

/* read all of the records in the file and import them! */
do while (~EOF(importfile))

  /* translate backslashes into NEWLINES (so that we work with export.mffm) */
  text_rec = translate(text_rec,'0A'x,alt_newline_char);

  /* get all of the fields out of the record and into a database record */
  /*   NOTE THAT YOU MAY TAKE THIS SECTION OUT AND REPLACE IT WITH    */
  /*   SOME CODE THAT SPECIFICALLY PARSES YOUR OWN FILE FORMAT!       */
  /*   WITH CLEVER CODE, YOU CAN HANDLE ABSOLUTELY ANY FORMAT HERE!   */
  rec. = "";
  i = 1;
  do while (text_rec ~= "")
    /* grab one field from the text line */
    parse var text_rec rec.i.value (sep) text_rec;

    i = i + 1;
  end;

  /* add the record to the database */
  add rec;
  if (rc ~= 0) then exit rc;

  /* read the next record */
  text_rec = readln(importfile);
end;
