Focal Point
[CLOSED] Enclosing numbers within double quotes in CSV file

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

May 17, 2012, 01:21 AM
Fazlina
[CLOSED] Enclosing numbers within double quotes in CSV file
I am creating a CSV file out of Webfocus 7.6.9. Except for the numeric columns, the rest are all enclosed within double quotes. I am using COMT format.

Can any of you kindly let me know what should I have to do if i want even the numeric fields also to be enclosed within double quotes in the generated CSV file.

Please note the columns I choose in the SELECT clause is dynamic and thereby i wouldnt know the datatype of the column before itself.

This message has been edited. Last edited by: Kerry,
May 17, 2012, 01:35 AM
Waz
You could convert the number to text before writing to the CSV file.

You will have to determine the format of the column first.

This can be done by either:
1. Check SYSCOLUM to get the format for thereturned hold file.
2. Use CHECK FILE ... HOLD to get the columns and formats.

With the list of columns and formats you can use DM to build computes in the TABLE...HOLD FORMAT COMT.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 22, 2012, 03:50 AM
WF World
quote:
With the list of columns and formats you can use DM to build computes in the TABLE...HOLD FORMAT COMT


Waz,

we could read the file format but how can we replace the numeric data-type to alpha. So that we can get format to text file where all the numeric values converted to alpha with double-quotes.


WebFOCUS 8.1.03
Windows, Linux All Outputs
May 22, 2012, 10:55 AM
rfbowley
I would suggest reading the "Using Functions" book. Look up

EDIT
FTOA
PTOA

Those three should cover everything you need.


Robert F. Bowley Jr.
Owner
TaRa Solutions, LLC

In WebFOCUS since 2001
May 22, 2012, 05:30 PM
Waz
Except if there are any dates.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 24, 2012, 02:29 AM
WF World
Hi,

I could read the integers and format it to alpha. But when I retrieve the data to Text file using COMMA, I see spaces in between quotes, this is due to specifying the alpha format to A50.
In between the code I couldn't use Trim function. Could you please help me in removing spaces by using Trim function or STRREP.



  
CHECK FILE CAR HOLD AS H1
-RUN
DEFINE FILE H1
FLAG/D2 = IF FORMAT OMITS 'A' THEN 1 ELSE 0;
END
 
TABLE FILE H1
PRINT
FIELDNAME
-*WHERE FIELDNAME EQ 'COUNTRY' OR 'CAR' OR 'SALES' OR 'DEALER_COST'
WHERE FLAG EQ 1
ON TABLE SAVE AS H1_SAVE
END
 
-RUN
-SET &RECS1 = &LINES ;
-SET &CNTR1 = 0;
-REPEAT :ENDREP1 &RECS1 TIMES
-SET &CNTR1 = &CNTR1+1;
-READ H1_SAVE &FLD_NM.&CNTR1.A66
-*-TYPE &FLD_NM.&CNTR1
-SET &NAME.&CNTR1 =&FLD_NM.&CNTR1 ||'_A';
-TYPE &NAME.&CNTR1
-:ENDREP1
-TYPE VALUE IS &FLD_NM1
-TYPE LOOP_CNT IS &RECS1
-RUN
 
TABLE FILE H1
PRINT
FORMAT
-*WHERE FIELDNAME EQ 'COUNTRY' OR 'CAR' OR 'SALES' OR 'DEALER_COST'
WHERE FLAG EQ 1
ON TABLE SAVE AS H2_SAVE
END
-RUN
-SET &RECS2 = &LINES ;
-SET &CNTR2 = 0;
-REPEAT :ENDREP2 &RECS2 TIMES
-SET &CNTR2 = &CNTR2+1;
-READ H2_SAVE &FMT.&CNTR2.A8
-TYPE &FMT.&CNTR2
-:ENDREP2
-TYPE VALUE IS &FMT1
-TYPE LOOP_CNT IS &RECS2
-RUN
 
 
 
 
-SET &CNTR3 = 0;
DEFINE FILE CAR
-REPEAT :ENDREP3 &RECS1 TIMES
-SET &CNTR3 = &CNTR3+1;
&NAME.&CNTR3/A50 = FTOA(&FLD_NM.&CNTR3, '(&FMT.&CNTR2)', &NAME.&CNTR3);
-:ENDREP3
END
-SET &CNTR4 = 0;
TABLE FILE CAR
PRINT
-REPEAT :ENDREP4 &RECS1 TIMES
-SET &CNTR4 = &CNTR4+1;
&NAME.&CNTR4
 
-:ENDREP4
-*ON TABLE SAVE
ON TABLE PCHOLD FORMAT COMMA
END



WebFOCUS 8.1.03
Windows, Linux All Outputs
May 24, 2012, 05:46 PM
Waz
The issue will be the A50.

Here is something a little simpler you may be able to use.

CHECK FILE CAR HOLD AS CARFIELDS
-RUN

TABLE FILE CARFIELDS
PRINT COMPUTE CODE/A258 = IF EDIT(FORMAT,'9') EQ 'A' THEN FIELDNAME ELSE 'COMPUTE A_' || FIELDNAME || '/A' || EDIT(EXLEN) || '=FTOA(' || FIELDNAME || ',''(' || FORMAT || ')'',A_' || FIELDNAME || ');' ;
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE AS FEX_FIELDS
END
-RUN

TABLE FILE CAR
PRINT
-INCLUDE FEX_FIELDS
ON TABLE PCHOLD FORMAT COMMA
END



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 25, 2012, 04:49 AM
WF World
Yes, this resolves our issue. You made our life easy and simple.. Big Grin

You are truly awesome and genius. Cool
Thanks for all your help.


WebFOCUS 8.1.03
Windows, Linux All Outputs
May 27, 2012, 05:23 PM
Waz
Oh dear, I think I'm getting a BIG HEAD.....


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 28, 2012, 06:39 AM
Tony A
Not wishing to steal Waz's thunder, but you will need a slight change to the CODE evaluation for integers -

PRINT COMPUTE CODE/A258 = IF EDIT(FORMAT,'9') EQ 'A' THEN FIELDNAME
                     ELSE IF EDIT(FORMAT,'9') EQ 'I' THEN 'COMPUTE A_' || FIELDNAME ||'/A' || EDIT(EXLEN) || '=TRIM(''L'', EDIT(' || FIELDNAME || '), ' || EDIT(EXLEN) || ', ''0'',' || EDIT(EXLEN) || ', A_' || FIELDNAME || ');'
                     ELSE 'COMPUTE A_' || FIELDNAME || '/A' || EDIT(EXLEN) || '=FTOA(' || FIELDNAME || ',''(' || FORMAT || ')'',A_' || FIELDNAME || ');' ;

Of course you may find other formats that you need to cater for differently, but the important thing is Waz has given you an excellent starting point from which to build.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
May 28, 2012, 05:30 PM
Waz
Aaahhh,

Big head deflated, thanks Tony, I needed that.

Big Grin


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 28, 2012, 05:46 PM
Tony A
Waz,

You supplied the boat and the rod, all I did was apply a little caulking!

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10