[CLOSED] -READ with comma delimited & variable length source
I have a file that looks like this: /media/rackspace/db2/clients/Jones/2011/2011-10/2011-10-01/852/ISA_006940860_000003234.edi,852,20110925,20111001,006940860,4014677150,16747,4 /media/rackspace/db2/clients/Jones/2011/2011-10/2011-10-01/852/ISA_014492501_400001168.edi,852,20110925,20111001,014492501,4014677150,40474,2
If I don't create DEFAULT or SET values for the variables in the -READ, the procedure failes. If I define the variables, the date returned matches the lenght of the variables I set up as the default. If I uset .Axx. syntax to define the langth, I get the results that match my format.
What I need is to read each item between the commas fully, so I can manipulate the results.
Running Windows vers 773This message has been edited. Last edited by: Kerry,
Steve
February 17, 2012, 01:01 PM
susannah
set up 1 variable, with a specified length of blanks equal to the largest expected line in your file make sure its full of blanks to initialize it, otherwise you're reading adjacent garbage in memory read your line into that space -READ INP &BIGTHING Use the TRUNCATE function then to shrink it down to real size, and then the .LENGTH will work. then token thru (or posit) to look for commas and set each of your individual variables... i have a routine somewhere that loops thru a long string, looking for the posit of commas, until posit returns a zero At each step, i set a REMAINDER string starting with the current posit and going to the end of the string....and then operate on that Remainder... if you follow what i'm saying, i'll look up that code and give it to you, but it wont be till monday
In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
February 17, 2012, 02:47 PM
Steve C
Hi Susan,
I thought of this too, but I am being stubborn. The documentation says that -READ can read from a comma delimited file. I guess I was hoping for too much. If it cannot do the parsing into the various variables, it really cannot read a comma delimited file.
I was thinking of reading in each single line and then using the GETTOK to pick it apart at each comma. Seems to be an overkill too. All of this will take a lot of time, for a very simple and one off process to figure out how to file a full directory's files into appropriate structures.
So, here is the question to IBI: Is the -READ supported for comma delimited files, the way one would expect it, or is it not?
Steve
February 17, 2012, 02:54 PM
njsden
Steve, the odd lines in your sample output don't seem to be comma-separated but slash-separated.
Is that the way your file looks or is that just a wrapping effect of the content you posted?
You can write a master file that will parse the .csv, then you don't have to -read set pcomma = on remember that?
but like new jersey says, looks like DFIX with delimiter = /
or..if its both, then the way i sugested is perfect. i had a file i had to read every day from the cashregister vendor (name gratefully forgotten) that had 2 different formats in it...the overall format was comma delimited, but one field inside was a comment field with crlf that had to be parsed ...that was fun...
In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
February 18, 2012, 02:24 PM
Danny-SRL
Steve, I copied your data and put it into a sequential file. Then I ran your code with a few small changes:
-* File SteveC01.fex
FILEDEF INP DISK focalpoint/stevec01.txt
-RUN
-LOOP
-READ INP,&DIR,&FTYPE,&S_DATE,&E_DATE,&TPID,&MFG,&SIZE,&COUNT
-IF &IORETURN NE 0 THEN GOTO DONE;
-TYPE &DIR; &FTYPE; &E_DATE
-GOTO LOOP
-DONE
Notice: The comma after -READ INP No blanks between the &variables