FW: How do I force export from within a loop

John Esak john at valar.com
Wed Aug 17 14:25:26 PDT 2005



-----Original Message-----
From: Doug Campbell [mailto:doug.campbell at yestechtoday.com]
Sent: Wednesday, August 17, 2005 2:56 PM
To: john at valar.com
Cc: mschw at athenet.net
Subject: Re: How do I force export from within a loop


>>John Esak wrote:

>>This is not correct. If Stuart has explained it that way in his book, no
>>matter how many times he's reprinted it, he's still wrong. A WRITE will in
>>no way export a line to an export file. Unless, the EXPORT line itself is
>>within the loop (getnext or any other kind of loop which gets successive
>>records) nothing will be added to the export file. So, unless you mean
>>something else, or Stuart explained it some other way, this is just not
>>correct.
>>...
>>
>>
>>
>>
> Hi John,
> I'm going to have to side with Mike on this one. I don't know if my
> reply to the
> original question made it to the list (as often they are rejected), but
> the code
> snippet I included is almost verbatim from a working program. I only
> execute
> the EXPORT statement one time, and then I do all of my buffer output
> through
> repetitive use of the WRITE command. I certainly agree with you that
> hitting
> the EXPORT again in a loop should accomplish the same thing. It just seems
> strange to me to keep re-defining the output stream. I'm a C coder by
> nature,
> and I relate EXPORT to fopen() and WRITE to fflush(). My code snippet
> copied
> at bottom, in case it missed the list.
>
> Regards,
> Doug Campbell
> Yes! Tech Today, Inc.

> :
> : export ascii mybuf=/tmp/names.csv r=\n f=,
> - - - - -
> : 'output header row (if desired)
> : mybuf(1)="First Name"; mybuf(2)="Last Name"; write mybuf
> - - - - -
> :
> : lookup names k=1 i=a -nx
> - - - - -
> loop: not names
> : goto done
> - - - - -
> : names 'output data row for each lookup record found
> : mybuf(1)=names(1) ; mybuf(2)=names(2) ; write mybuf
> - - - - -
> :
> : getnext names ; goto loop
> - - - - -
> done:
> : ....

Hmmm, well, as soon as I saw that Mr. Tartaglia had gotten some success from
using the WRITE in his getnext loop. I went and tried the procedure
immediately. It did NOT work.  Okay, I wrote my note to the list. I knew it
doesn't work that way. WRITE does a WRITE, ExpORT does an EXPORT. :-)

Then I get Doug's letter and wonder what is up. Turns out, we are both
right. Well, the WRITE-EXPORT will NOT work in *clerk.... which, of course,
is where I tried it out. (Murphy, of course.)  However, it does work in
*report. So, I called Ken... Turns out he was checking things out also and
had just discovered this. I told him that it did NOT work for me in clerk
and he said that he remembered (like me) that EXPORT itself did not used to
work in clerk... the early days. It was only an output function. Then,
somewhere along the line (Dave Roeger, he thinks) probably *added* the code
which allows WRITE to update an EXPORT at least when you're in report. Ken
was also under the impression that WRITE would not refresh an EXPORT.
Neither apparently did Ron Kracht, who he had just asked also.

So, there you have it, I (we all, actually) stand corrected. Using a WRITE
in a getnext loop will send out the export again. However, it is still not
and probably never will be a documented function of WRITE. And, it will
probably never be changed to work that way in clerk also. Who knows. In any
case, I think it is important to understand the very _different_ nature of
the EXPORT command and the WRITE command. If you mix up the purpose of these
two commands, there will be other times when you will not get the desired
results.

So, I apologize for stating it according to the docs and the intended
behavior of each command. I don't think would ever use it that way, but then
again, if your understanding of things allows you to picture the workings in
this way, no problem.

As for the C analogy. Okay, for all practical purposes the EXPORT could be
an fopen(), however the WRITE is not like a flush() to me. Think of it this
way. If you did not get another record and issued another WRITE, you would
get another line written to the file. If you had just opened a file with
lookup r=free and did more than one WRITE, by your logic here you might
expect to see multiple free records written... which obviously won't happen.

So, to keep things straight, I like to think of needing to go through the
EXPORT line to actually send the data out. The fact that WRITE was modified
to do this (in report only) is a fluke and was probably added for a specific
need one time, which is why it remains undocumented and probably never will
be.

It may sound strange, but I do all of my importing and exporting from a
stand file in clerk. Always have. It just gives me more flexibility when
querying for which records to manipulate. I suppose I should have tried this
in report before sending out my message... but, even when I found it to
work, I still would not recommend it. Adding a new line to a file, or a new
record to a filepro key is not the job of WRITE. As always, this is only
IMHO. And after learning this today... the H does not mean Honest it means
Humble!  Thanks Doug.


--
John Esak
Visit The FP Room www.tinyurl.com/97y9u 24/7

Author of:
The filePro Survivor Series
Video training for filePro on CD
Samples at: www.valar.com/training



More information about the Filepro-list mailing list