import of csv
Jose Lerebours
fpgroups at gmail.com
Sun Dec 3 09:51:27 PST 2017
Have you looked at the filePro array methods to see if they offer
anything at all?
Given: $array=array( 'column A'=>1, 'column B'=>30, 'column C'=>780 );
Code: for($array as $key=>$val) { if(strtoupper($key) ==
strtoupper("column name")) { return($val); } }
So, in filePro, you can do something similar:
/* define arrays */
dim colName[50](20,allup);
dim colNumber[50](3,.0);
/* populate arrays */
colName[1]='column A'; colNumber[1]='1'
colName[2]='column B'; colNumber[2]='30'
colName[3]='column C'; colNumber[3]='780'
Then, within a "GOSUB", you can loop through the set arrays till you
match colName[###] to the targeted column name extracted from CSV and
return the associated colNumber[###] value ... You can also just arrange
the column names in the numeric order in which the field number is
expected to be so, no matter how deep in the CSV the column is, your
fixed array will return the number you are looking for thus eliminating
the need of colNumber[] ...
Now let me wait for better ways to do this! ;-)
On 12/03/2017 12:33 PM, James Flanagan via Filepro-list wrote:
> Filepro 5.7.00.0D94
> FreeBSD
>
> I am trying to write an import routine of csv files where the columns will not be consistent each time. instead, the header row will determine which column contains which value. this will become part of a daily routine import, but there will be no way for me to control the column assignments for each file.
>
> is there any way to refer to the field number of the import with a variable instead of a static number? Thank you very much,
>
> file 1:
> first name,last name,…
> Mike,Jones,…
>
> file 2
> phone number, city, last name,…
> 555-555-1212,Atlanta,Jones,...
>
>
> ::declare local cnt(6,.0):
> ::':
> ::cnt="1":
> ::fn="/tmp/transfer/"{@pm:
> loop::':
> ::import ascii inf=(fn) r=\n f=~:
> :cnt eq "1":po="1";goto get_poc:
> :not inf:delete;exit:
> ::lookup customer r=free -e:
> ::customer(1)=inf(po):
> ::close customer:
> ::cnt=cnt+”1"
> ::goto loop:
> ::':
> get_poc::':
> :inf(po) co “last name":goto loop:
> ::po=po+"1":
> ::goto get_poc:
> ::':
>
> inf(po) co “last name"
> ^
> Process contains a syntax error at position indicated.
>
>
>
>
>
>
> James Flanagan
> Flantec.com <http://flantec.com/>
>
> email: James at Flantec.com <mailto:James at Flantec.com>
> mobile: 760-458-8498
> home: 219-221-6219
> text: 7604588498 at txt.att.net <mailto:7604588498 at txt.att.net>
>
> aim: Flantec
> oovoo: Flantec
> Skype: Flantec
> ichat: Flantec at mac.com <mailto:Flantec at mac.com>
>
> home: 1901 Cidermill Road
> Michigan City, IN 46360
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mailman.celestial.com/pipermail/filepro-list/attachments/20171203/e07cda01/attachment.html>
> _______________________________________________
> Filepro-list mailing list
> Filepro-list at lists.celestial.com
> Subscribe/Unsubscribe/Subscription Changes
> http://mailman.celestial.com/mailman/listinfo/filepro-list
--
Jose D. Lerebours
954-559-7186
https://www.cargosaas.com
http://www.ezbookeep.com
http://www.ezdaemon.com
http://www.fp2php.com
More information about the Filepro-list
mailing list