Adding header to a delimited export

Brian K. White brian at aljex.com
Mon Jan 10 12:03:16 PST 2005


----- Original Message ----- 
From: "Matthew Williams" <matthew.d.williams at gmail.com>
To: <filepro-list at lists.celestial.com>
Sent: Monday, January 10, 2005 1:46 PM
Subject: Re: Adding header to a delimited export


> Still troubled...although I can't believe I didn't think of the
> variable in the first place, I guess I wasn't in developer mindset;
> stuck in networking mindset at the moment...
>
> When I run it I still receive the same output as before, a bunch of
> records the way they're supposed to be but still without the header.
> Am I missing something simple or have a syntax error somewhere?
>
> Here is what i've got:
> 1  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If:
>       Then: export word plant = /upss/ups.txt -r=\n -f=,
> 2  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If:
>       Then: F="Y"

delete line 2 entirely

> 3  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If: F ne "N"
>       Then: plant(1)="CustomerID";plant(2)="Country";plant(3)="Attention"
> 4  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If: F ne "N"
>       Then: plant(4)="Company";plant(5)="Address1";plant(6)="Address2"
> 5  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If: F ne "N"
>       Then: 
> plant(7)="City";plant(8)="State";plant(9)="Phone";plant(10)="Zip"
> 6  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If:
>       Then: F="N"

in line 6, define F to be global
then: f(1,*,g)="N"

also, here you need to run the export command again or else this first data 
record will just overwrite the header.
actually, the header never gets written in the first place, you fill the 
fields with header values, and then overwrite them with data values, and 
then the final values get written when processing reaches the end and goes 
to read the next record.

That is why I suggested putting the export into a gosub, it needs to get run 
twice once (if you follow that), and it's always a recipe for bugs having 
duplicate copies of lines that might change rather than having one line in a 
gosub that gets called more than once.

> 
>   -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If: F ne "N"
>       Then: plant(1)=1;plant(2)=2;plant(3)=3;plant(4)=4;plant(5)=5
>       ...................
> 
>   -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>       If:
>       Then: end

Except it's yucky to perform several tests at each new record instead of 
one.

use gosubs
put the header stuff into a gosub and have one test line, if f ne "n" then 
gosub header
put the export line into a gosub and call it from two places, once at the 
top of the table, once at the top of "gosub header"

If you have 5.0 my first example was ideal except for the slip-ups ken 
pointed out re: ends & returns.
(you'll notice he didn't suggest some completely other better method but 
merely pointed out a few mental typo's from writing out the example too 
fast)

If you don't have 5.0 then it goes like this:

if: x ne "x"
then: gosub header
if:
then: x(1,*,g) = "x"
if:
then: gosub exp
if:
then: plant(1)=1;plant(2)=2;plant(3)=3;plant(4)=4;plant(5)=5
if:
then: end
exp: if: '*** export ***
then: export ...
if:
then: return
header: if: '*** header ***
then: gosub exp
if:
then: plant(1)="customer" ...
if:
then: return


Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx  Linux SCO  Prosper/FACTS AutoCAD  #callahans Satriani



More information about the Filepro-list mailing list