How to create ASCII text file from HS2014 (on RHEL) unicode
I'm a beginner for hs2014
I try to write text file in ASCII format (encode CP874) from HS2014 (run on RHEL)
I try to use
o file:"WNSK\CP874\"
o file:"RSK\CP874\"
o file:"WNSK\THAW\
o file:"WNS"
but output file still in UTF-8 encoding
please advise me
Thk.
Use translate table:
ClassMethod create(file) As %Status { set stream = ##class(%Stream.FileCharacter).%New() set stream.TranslateTable = "CP874" set sc = stream.LinkToFile(file) quit:$$$ISERR(sc) sc do stream.WriteLine("Hello") quit stream.%Save() }
Eduard, can you explain the main difference between Sagun's method of translation table setting:
and yours in this very case? The latter is a piece of code of %Stream.FileCharacter.cls which actually sets a table:
It seems that it's some other problem, perhaps a bug.
Sagun, if you provide us with a small piece of your code where you open the file, use it, and write it, it would be easier to say something.
It's better to use stream wrappers instead of open/use directly.
I'm not sure what's the correct way to set codepage with open command.
Just because of higher abstraction level of streams; nothing special inside: just the same Open/Use/etc COS commands. So, choosing one or another way of working with files can't be the source of errors itself.
By the way, `open file:("NWK\table\")` is a proven and documented way of translation table setting. AFAIK, its only limitation is that it works with Open command only rather than with Use command.
Can you please link me to the documentation?
"NWK" is not a good search term for three separate one-character parameters. You want the OPEN Mode Parameters section of the Sequential File I/O chapter of the Caché I/O Device Guide:
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...
Dear Alexey Maslove
n fileno,seq,resfile,ind,ind2,seq2 s resfile="" s ind="" f s ind=$o(^ztonEDI("TXT","OUT-DATA",ind)) q:$g(ind)="" d .s fileno="" f s fileno=$o(^ztonEDI("TXT","OUT-DATA",ind,fileno)) q:$g(fileno)="" d ..s resfile="/Flatfile/"_fileno_".txt" ..o resfile:"RSK\CP874\" ..u resfile ..s seq="" f s seq=$o(^ztonEDI("TXT","OUT-DATA",ind,fileno,"SEQ",seq)) q:$g(seq)="" d ...w $g(^ztonEDI("TXT","OUT-DATA",ind,fileno,"SEQ",seq))_$c(13),$c(10) ..c resfile .k ^ztonEDI("TXT","OUT-DATA",ind) q
Sagun, this code would fail with <WRITE> error as after opening the file for reading:
..o resfile:"RSK\CP874\"
it tries to write into it:
...w $g(^ztonEDI("TXT","OUT-DATA",ind,fileno,"SEQ",seq))_$c(13),$c(10)
What this code needs as the first remedy is a change of the Open command to:
..o resfile:"NWK\CP874\"
... and second thing is to insert a Close command before the correspondent Open, e.g.
even if you are quite sure that the file is closed at the moment of opening. The reason is to avoid the cases when your program have failed with error without closing the file, so its open parameters (at least, the translation table setting) keep unchanged despite of subsequent Open command. Such cases often happen during development / debugging, when the error trap code is completely switched off or greatly simplified.
Dear Alexey Maslov
It work ! Thank for your advise :)