MilindV
9th August 2012, 06:36
Hi All,
I am facing a small issue while writing (Chinese) multi-byte character string(one of which is Business Partner Name) in a file (on to the server and copying it back to local system).
I have used this functions earlier many a times and it worked fine without any trouble. but then yesterday mb.export$ refused to work and kept giving me return value -3.
So question for you guys/gals is, Does any one know what this -3 means. Programmers Guide just says "character could not be converted". but does not tells you the reason WHY character could not be converted.
I tried passing lval(mb.locale.info(TSS_GET_TSS_NAME)) as the third argument to mb.export$ but no difference in output.
If you have come across such issue earlier and you have managed to resolve this, please share the solution. It will be great help.
Thank You
george7a
9th August 2012, 09:48
I do not have the answer for what does -3 means. I hope the following questions will help you:
1) Is the function working with another input. Is it specific or general problem?
2) Have you tried to export just part (maybe one letter) of the nonworking string?
MilindV
9th August 2012, 12:13
George,
Thanks for quick reply.
1) The problem is general, it is not specific to a particular input string.
2) I tried this as well but no difference in result.
Can this be because of some LN ENV set up problem. some parameters we have to set, some configuration problem?
Because I don't see any other reason for mb.export$ not working, as in previous projects I worked, this function worked.
I tried uni.export but, I did not get desired output.
in case of mb.export I was getting question marks in output
in case of uni.export I get some junk(unreadable characters) in output.
baan1721
28th November 2012, 05:51
Hi Milind,
Were you able to fix the same? I am also trying to write chinese character in file using seq.open but its printing some junk characters.
Can you please help.
regards
Jay
vamsi_gujjula
12th August 2015, 17:04
I am facing a small issue while writing (Chinese) multi-byte character string(one of which is Business Partner Name) in a file (on to the server and copying it back to local system).
i have a same issue , writing Chinese labels to text file and then opening it up in excel
Same thing is working with standard decive whose parameter is "ascii -u:excel"
i understand that the file is in UTF16LE encoding
but when i use utf.export() and write it to file using seq.* functions it doesnt seam to work
Can anyone let me know how it be achieved ...
bdittmar
12th August 2015, 18:21
Hello,
from DEV Guide :
Return values
> 0 the number of converted bytes
-1 the target string was too small to contain the converted string
-2 an incomplete character was found at the end of the string
-3 character could not be converted.
Regards
vamsi_gujjula
13th August 2015, 09:07
returns 8 bytes
attachment what i get
bhushanchanda
13th August 2015, 09:25
Hi Vamsi,
The reason is that, when you use utf8.export() function and insert the result into csv file using seq.* functions, a UTF-8 file is created. If you open this CSV with Notepad or Notepad ++ it will show you the Chinese characters.
Reason - When you open the file with Notepad/Notepad++, it adds the required BOM(Byte Order Mark) characters for UTF-8 file and shows you the data.
The BOM sequence is - 0xEF,0xBB,0xBF
Now, to tackle this programmatically, Following is a hack I use -
Just add this line as your first line to the generated CSV-
cmd.str = chr$(239) & chr$(187) & chr$(191)
seq.puts(trim$(cmd.str),fp)
This is a BOM sequence required for UTF-8 for application like excel.
A sample program -
function main()
{
string tmp_file(100)
long fp
long ret
domain tcmcs.str256m dsca
string cmd.str(200)
tmp_file = creat.tmp.file$( bse.tmp.dir$() )
tmp_file = tmp_file & ".csv"
fp = seq.open(tmp_file,"w+")
seq.flush(fp)
seq.rewind(fp)
cmd.str = chr$(239) & chr$(187) & chr$(191)
seq.puts(trim$(cmd.str),fp)
select tcibd001.*
from tcibd001
as set with 10 rows
selectdo
utf8.export(dsca,tcibd001.dsca,UTF8_STD_MODE)
seq.puts(tcibd001.item&","&dsca,fp)
endselect
seq.close(fp)
|* Transfer from server to client.
}
Tested and works just fine.
The other solution is, just open the CSV file in notepad - > Hit Control + S (Save) -> Close
This will add the BOM sequence and excel will show you the proper data.
vamsi_gujjula
13th August 2015, 10:30
ooo .. so i missed out the BOM .. now i understand .. thanks bhushan.
BOM
Bytes Encoding Form
00 00 FE FF UTF-32, big-endian
FF FE 00 00 UTF-32, little-endian
FE FF UTF-16, big-endian
FF FE UTF-16, little-endian
EF BB BF UTF-8
anyway let me check utf8 , if it works that well and good for me.