WordStar  does not make it easy to reuse the same DATAFILE within  the  same 
document.

I had a particular need to use the same DATAFILE twice in the same  document 
as  I wanted the first pass to pick out the A items and the second  pass  to 
pick  out the B items.  I also wanted to be able to print both the A  and  B 
items in the order that they appeared in the DATAFILE.

The job printed out a set of legal TEXTS with cross-reference NOTES attached 
to  them.  The operator wanted the choice of either printing out  the  TEXTS 
alone, the NOTES alone, the TEXTS with the NOTES interspersed, or the  TEXTS 
with the NOTES as an appendix.  The NOTES, when interspersed with the  TEXT, 
were to print immediately  after  the matching text and not at the bottom of 
the page as footnotes are  printed.  Each of these choices requires only one 
pass  through  the DATAFILE except the choice of printing the  NOTES  as  an 
appendix which requires two passes.

I created a single DATAFILE that had two fields.  The first field has a  T/N 
CODE  and the second field holds the CONTENTS of the TEXT or NOTE.   A  NOTE 
did not always exist for every TEXT but a TEXT existed for every NOTE.

The following files are simplified versions of the files actually used.

Please note that there are two caveats when using a .DF to call a  DATAFILE.  
(1)  You  must NOT bracket a .DF with a .IF/.EI loop.   Your  document  will 
function  normally, but the DATAFILE pointer may not correctly  set  itself, 
especially  the second time that you try to use the same DATAFILE.  And  (2) 
you  probably should not put your .DFs in the file being merge-printed  (aka 
TOPFILE) but in files that are called by a .FI.

TOPFILE looks like:
      .CS
      .SV DEFAULT,4
      .DM You can either
      .DM (1) Print the TEXTS alone
      .DM (2) Print the NOTES alone
      .DM (3) Print the NOTES in WITH the text or
      .DM (4) Print the NOTES AFTER the text (appendix form)
      .DM (0) Exit this document 
      .AV "Which do you want (Default is &DEFAULT&)? ",PATH
      .. If PATH="" then set PATH = DEFAULT
      .. Put in a trap to make sure that the answer is 0 to 4
      .. If PATH is zero, go BOTm
      .FI TAKEACTI.ON
      .IF &PATH&<>4
      .GO BOTM
      .EI
      .SV PATH,5
      .FI TAKEACTI.ON

Here   you can see that if we want to print the NOTES after the   TEXT,  the  
TAKEACTI.ON  file will make two consecutive passes through  the  same  DATA-
FILE.   The first pass, you will see, prints all the TEXT passages  and  the 
second pass prints all the NOTE passages.

The TAKEACTI.ON file looks like:
      .DF DATAFILE
      .FI LOOP

The LOOP file looks like:
      .RV CODE,CONTENTS
      .. If the code is empty, GO BOTM, else
      .IF &PATH&=1
      ..and if CODE is TEXT, print CONTENTS and then GO TOP
      .EI
      .IF &PATH&=2
      ..and if CODE is NOTE, print CONTENTS and then GO TOP
      .EI
      .IF &PATH&=3
      ..print CONTENTS (either TEXT or NOTE) and then GO TOP
      .EI
      .IF &PATH&=4
      ..and if CODE is TEXT, print CONTENTS and then GO TOP
      .EI
      .IF &PATH&=5
      ..and if CODE is NOTE, print the appendix version of it then GO TOP
      .EI
      .GO TOP

So, here, in one mergeprint of TOPFILE, we can access the same DATAFILE  for 
two  different purposes.  Theoretically, we can use this method  to   access 
the  same DATAFILE (or even different DATAFILEs) for an unlimited number  of 
passes  so long as the first DATAFILE is completely processed before we  .DF 
the  same file or another DATAFILE.

The  key is to put every .DF command in a separate file that is  subordinate 
to the file actually being merge-printed.

If you find that you have a system hang when using this file, it is probably 
because your .GO TOP has encountered an exploded SYMSEQ.  There are  library 
files  from  Rich Zuris on this problem.  Take a look at them.   Your  basic 
solution is to take any file with a GO TOP command and convert it to a  non-
document  file.  Put any document or formatting controls in a file  that  is 
either  above or below the file containing the GO TOP.  In my case,  the  GO 
TOP  file is the LOOP file but all the formatting is controlled by  TOPFILE.  
Go  back to the GO TOP file in NON-document mode and use ^QQ^B  to  reformat 
the entire file from the very beginning.

If  you have any questions about the .DF, please drop me a  CompuServe  mail 
message.  Jeff Elliot.
/EXIT
