Focal Point
CSV file

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1161038331

February 24, 2005, 09:11 AM
<Alberto>
CSV file
Hello,
I need to create a file where every fields are separeted by ; and characters without blanks and numeric filds without leading zeros.
I work with a sequential file, for example (where b is blank):

AAAAAAA000001.00BBBBB002
bbAAAAA000001.00bbbbb002
bbbbbCC000000.00bbbbD003

I need to get this file:

AAAAAAA;1.00;BBBB;2;
AAAAA;1.00;;2;
CC;.00;D;3;

I have already tried to do it using the saving format COM, but I don't want "" for character and I need ; as separator and no comma.
I will appriciate any help or shortcut to do it.

Thanks
Alberto
February 24, 2005, 03:41 PM
Leah
I do something like this in the past, of course I was putting in the double qoute, but I'm sure the theory applies.
DEFINE FILE RTRTTBL
TMP_NAME/A32 = GETTOK(AA003,32,2,',',32,TMP_NAME);
SFX_NAME/A5 = GETTOK(AA003,32,3,',',5,SFX_NAME);
FMN_NAME/A32 = LJUST(32,TMP_NAME,FMN_NAME);
FST_NAME/A32 = GETTOK(FMN_NAME,32,1,' ',32,FST_NAME);
LST_NAME/A32 = GETTOK(AA003,32,1,',',32,LST_NAME);
ATTEMPTI/I6 = CRS_ATTEMPTED_HRS * 100;
EARNEDI/I6 = CRS_EARNED_HRS * 1000;
POINTSI/I6 = CRS_QPTS * 1000;
ATTEMPT/A5 = EDIT (ATTEMPTI,'$$99.99');
EARNED/A6 = EDIT (EARNEDI,'$99.999');
POINTS/A6 = EDIT (POINTSI,'$99.999');
TERMX/A6 = EDIT(TERM_CYT,'9999-9');
COURSELINE/A150= STU_ID | ',' | TERMX |
',"' | EDIT(CRS_ID,'9999$$$$') | '-' |
EDIT(CRS_ID,'$$$$9999') | '",' | ATTEMPT | ',' | EARNED | ',' |
OFFICIAL_GRADE | ',' | POINTS | ',' ;
NAMELINE/A150= STU_ID | ',' | FST_NAME | ',' | LST_NAME | ',' | RT25K;
END
February 24, 2005, 03:54 PM
susannah
as a corollary, here's an article on how to READ files with different delimeters.
[URL=http://techsupport.informationbuilders.com/sps/91671095.html ]http://techsupport.informationbuilders.com/sps/91671095.html [/URL]
February 26, 2005, 08:17 AM
<JG>
I'm assuming that what you want is a variable length output file so as to minimize it.

look at the following


your master probably looks like this
FILE=x1, SUFFIX=FIX
SEGNAME=ROOT_SEG, SEGTYPE=S1, $
FIELD=FIELD1, ALIAS=FIELD1, USAGE=A7, ACTUAL=A7, $
FIELD=FIELD2, ALIAS=FIELD2, USAGE=D9.2S, ACTUAL=A9, $
FIELD=FIELD3, ALIAS=FIELD3, USAGE=A5, ACTUAL=A5, $
FIELD=FIELD4, ALIAS=FIELD4, USAGE=I4S, ACTUAL=A4, $
-*
your data like this
AAAAAAA000001.00 002
AAAAA000001.00 002
CC000000.00 D003
-*
-*
FILEDEF X1 DISK C:\IBI\APPS\BASEAPP\X1.FTM
FILEDEF X2 DISK C:\temp\X2.FTM
-RUN
SET HOLDLIST=PRINTONLY
DEFINE FILE X1
DELIM/A1=';';
END
TABLE FILE X1
PRINT
COMPUTE FIELD2A/A9=FTOA(FIELD2, '(D9.2)', 'A9'); NOPRINT
COMPUTE FIELD4A/D5.0=FIELD4; NOPRINT
COMPUTE FIELD4B/A5=FTOA(FIELD4A, '(D5.0)', 'A5'); NOPRINT
COMPUTE OUTLINE/A29=LJUST(7,FIELD1,'A7') || DELIM || LJUST(9,FIELD2A,'A9') || DELIM || LJUST(5,FIELD3,'A5') || DELIM || LJUST(5,FIELD4B,'A5') ;
ON TABLE SAVE AS X2
END
-RUN
FILEDEF X3 DISK C:\temp\X3.FTM (RECFM V
-RUN
-LOOP
-READ X2 &OUTLINE.A29.
-IF &IORETURN NE 0 GOTO EXIT;
-SET &NLINE= TRUNCATE(&OUTLINE);
-WRITE X3 &NLINE
-GOTO LOOP
-EXIT

This message has been edited. Last edited by: <Mabel>,
March 02, 2005, 09:39 AM
<Alberto>
Actually my files are not so simple as in the example. I have about 20 files and most of them have more then 70 fields, so it will take long.

Thanks to all
March 02, 2005, 02:03 PM
HÃ¥kan
I suppose the best option would be FORMAT TAB and then run some kind of utility to replace the X'09 with X'3B. You will also have to left-justify alpha fields. Something like this:

TABLE FILE infile
PRINT *
ON TABLE SET NULL ON
ON TABLE HOLD FORMAT TAB
END
March 02, 2005, 09:16 PM
Chris Boylan
Why not create one big field that is a concatenation of all fields with the delimeter thrown in between? The only trick, of course, is getting rid of those pesky leading zeroes in the numbers which you can do with a combination of LJUST and FTOA.

Here's a sample using the CAR file:



DEFINE FILE CAR
LINE/A256=COUNTRY||';'||CAR||';'||
LJUST(3,FTOA(SEATS,'(F3)','A3'),'A3')||';';
END
TABLE FILE CAR
PRINT LINE
ON TABLE SAVE
END
If you edit the output file you'll see it looks exactly as you have described.

This message has been edited. Last edited by: <Mabel>,