1. Fernando Leal
  2. PowerBuilder
  3. Wednesday, 3 March 2021 15:57 PM UTC

Hi All, 

I need obtein the CSV file with the ; separator en PB2019 R2, Could you help, please? 

This is the code 

 

choose case ls_extension
case 'CSV'
               dw_1.Saveas(c:\file, CSV!, TRUE)
end choose

This is the example file, obtein now

GTIN,Serial Number,Expiration Date,CRYPTO,Purchase Order,CLN
97794990003924,100196,220721,1783,369947,L4612
97794990003924,100197,220721,1784,369947,L4644

 

 

thanks and regards, 

Fernando.

 

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 3 March 2021 17:27 PM UTC
  2. PowerBuilder
  3. # Permalink

Greetings, Fernando -

There are no options available to specify a line-ending separator or an alternative value separator character, as far as I know. What you get using the CSV! SaveAsType is the standard comma-separated-value format.

If you require something different, you may have to save the data as a CSV-file, then open and read the file, add the semi-colons as needed and write out a new version of the file yourself.

Regards, John

Comment
  1. Fernando Leal
  2. Wednesday, 3 March 2021 19:14 PM UTC
Hi John,

thanks.

Fernando.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 3 March 2021 19:21 PM UTC
Hi Fernando;

I agree with John .. write the CSV via a SaveAs() command and then Read it back into the PB App (or another PB App EXE) and replace the "," with ";". For super fast replacing, have a look at my "fn_replace_all" global function in my framework. Feel free to copy this GF into your App and use it. The framework is free and open source.

FYI: http://sourceforge.net/projects/stdfndclass/files/FrameWork/Integrated

Tip: for super large files, use the FileRead() command that grabs 32K chunks of a file at a time, replace & write that back out. Then grab the next 32K chunk. That will use very little memory. HTH

Regards ... Chris
  1. Helpful
  1. Fernando Leal
  2. Thursday, 4 March 2021 15:13 PM UTC
Hi Chris,

thanks for this information.

I created this function.



/*function: f_dw_saveasformattedtext(dw_1, ls_filename, ';')

parameters: adw_dw(datawindow/datastore), as_filename (string), as_separator(string)

*/



long ll_row, ll_rows, ll_colcount, ll_colindex

string ls_colname, ls_coltype, ls_value, ls_lineval

int li_filenum

any la_anyval



long ll_row1, ll_rows1, ll_colcount1, ll_colindex1

string ls_colname1, ls_coltype1, ls_value1, ls_lineval1

int li_filenum1

any la_anyval1









ll_rows = adw_dw.rowcount()

ll_colcount = long(adw_dw.Describe("DataWindow.Column.Count"))

li_filenum = FileOpen(as_filename, LineMode!, Write!, LockWrite!, Append!)

if li_filenum = -1 or isnull(li_filenum) = true then

return -1

end if



ls_lineval1 = ''

for ll_colindex1 = 1 to ll_colcount

ls_colname1 = adw_dw.describe("#" + string(ll_colindex1) + ".DBName")

//ls_lineval1 = ls_colname1

if ll_colindex1 = 1 then

ls_lineval1 = ls_colname1

else

ls_lineval1 +=as_separator + ls_colname1

end if



next //rows



FileWrite(li_filenum, ls_lineval1)





for ll_row = 1 to ll_rows

ls_lineval = ''

for ll_colindex = 1 to ll_colcount

ls_colname = adw_dw.describe("#" + string(ll_colindex) + ".Name")

//ls_lineval += ls_colname + char(13)

ls_coltype = adw_dw.Describe ( ls_colname + ".ColType" )

CHOOSE CASE Lower ( Left ( ls_coltype , 5 ) )

CASE "char(", "char","strin" // CHARACTER DATATYPE

la_anyval = adw_dw.GetItemString ( ll_row, ls_colname )

CASE "date" // DATE DATATYPE

la_anyval = adw_dw.GetItemDate ( ll_row, ls_colname )

CASE "datet" // DATETIME DATATYPE

la_anyval = adw_dw.GetItemDateTime ( ll_row, ls_colname )

CASE "decim" // DECIMAL DATATYPE

la_anyval = adw_dw.GetItemDecimal ( ll_row, ls_colname )

CASE "numbe", "long", "ulong", "real", "int" // NUMBER DATATYPE

la_anyval = adw_dw.GetItemNumber ( ll_row, ls_colname )

CASE "time", "times" // TIME DATATYPE

la_anyval = adw_dw.GetItemTime ( ll_row, ls_colname )

CASE ELSE

SetNull ( la_anyval )

END CHOOSE

ls_value = string(la_anyval)

if trim(ls_lineval) = '' then

ls_lineval = ls_value

else

ls_lineval += as_separator + ls_value

end if

next //columns

FileWrite(li_filenum, ls_lineval)

next //rows



return 1



regards,

Fernando.

  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Thursday, 4 March 2021 13:06 PM UTC
  2. PowerBuilder
  3. # 1

use SaveAsAscii or SaveAsFormattedText:

dwcontrol.SaveAsAscii ( string filename {, string separatorcharacter {,string quotecharacter {, string lineending {, boolean retainnewlinechar } } } } )



Comment
  1. Fernando Leal
  2. Thursday, 4 March 2021 14:34 PM UTC
Hi Mike, very good solution.

thanks and regards,

Fernando.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.