Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

SaveAsFormattedText() NOT WORKING POWERBUILDER 10

First I am retrieving rows in a script and then I am using  dw_1.SaveAsFormattedText(ls_client_path,EncodingANSI!,",","'")  to write a text file.
This text file is read by a batch prog every hour. The file has to be comma separated. the problem is I have to use this function b/c the rows may contain non alphabet charac like &,*,% etc due to bad data input The batch prog rejects the whole file even if one rec or line  contains these special charac. so I have to wrap each value in Quotes. The function works OK except for the fact that it adds comma at the end of each line for some reason and that's why the file gets rejected. I am attaching the file.
One more problem is even if we remove the comma at the end of each line some fields like name contain comma inside due to bad data input again the file gets rejected. Please this is urgent

string ls_Emp_Input
lds_client.dataobject = 'ds_dnd_client'
lds_client.SetTransObject(SQLCA)
ll_rowcount = lds_client.Retrieve()
 
lb_exists = FileExists(ls_emp_path)
IF lb_exists THEN
	FileDelete(ls_emp_path)
END IF
//Hrehman 10/22/2008 
if lds_client.SaveAsFormattedText(ls_emp_path,EncodingANSI!,",","'")= -1 then
	MessageBox("ARCS Error","Error occurred saving the Employee file.")
end if
 
ll_FLength = FileLength64(ls_emp_path)
 
li_FileNum = FileOpen(ls_emp_path,textmode!)
 
ll_fileread =  FileReadEx(li_FileNum, ls_Emp_Input)
ls_Emp_Input = "F1,F2,F3,F4,F5~r~n" + ls_Emp_Input
 
FileClose(li_FileNum)
 
li_FileNum = FileOpen(ls_emp_path, textmode!, Write!, LockWrite!, replace!)
ll_filewrite = FileWriteEx(li_FileNum, ls_Emp_Input)
FileClose(li_FileNum)

Open in new window

clients.txt
0
HARLIBRA
Asked:
HARLIBRA
1 Solution
 
sandeep_patelCommented:
are you using the same code whatever is pasted here? Your output file has all values enclosed in quote and are comma separated. while your arguments are not matching with it..

Also you can not avoid comma (separater character) at the end of line while using this function. However you can remove that using file read and file write function.

Read file in linemode and write the line to new filed except last character.

OR
modify batch job which should not reject the file if last character in line is comma.

And if you don't have control over the data input you can't include any character as separater character and some day it will be rejected. OR Your batch job should be smart to understand that if there is comma between quotes then it's a valid data.

Regards,
Sandeep
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now