Discussion:
Write UTF-8 file to IFS from ILE-RPG gives allways 0 bytes
(too old to reply)
Marc HB9CPW
2005-09-30 12:36:05 UTC
Permalink
Hi *all

After some hours of reading, testing i can't find a solution for the
following problem:

I changed a little working sample program which writes a tab-delimited
file to the ifs.

When the program is used with CodePage 819 it works perfect.

I changed the codepage from 819 to 1208 UTF-8.
It is possible to create the file with codepage 1208 (checked with
OpsNav). But if the IFS-File is opened for writing, errorcode -1 appears
and nothing goes to the file.

Does anybody have a tip what has to be changed to get the UTF-8 file ?

Many thanks.

Marc


***** Code snipets below
The complete program is here (sorry some comments are in german):
*************************************************
http://mypage.bluewin.ch/hb9cpw/wrtifsutf8.ilerpg
*************************************************

d open pr 10i 0 extproc('open')
d filename * value
d openflags 10i 0 value
d mode 10u 0 value options(*nopass)
d codepage 10u 0 value options(*nopass)

d codepage s 10u 0 inz(1208)

c* create the file
c eval oflag = o_creat + o_codepage + o_rdwr
c eval omode = s_irwxu + s_iroth
c eval filename = %trim(filename) + null
c eval err_flag = open(%addr(filename)
c : oflag
c : omode
c : codepage
c )
c if err_flag < 0
c exsr e99
c endif
c*
c* close the file
c eval rc = close(err_flag)
c*
c* open the file
c eval oflag = o_wronly + o_textdata
c*
c eval err_flag = open(%addr(filename)

c : oflag

c )

c if err_flag < 0 <--- here -1
appears
c exsr e99

c endif
René H. Hartman
2005-09-30 16:13:00 UTC
Permalink
Just a thought: do you have the 'Support for UNICODE' licpgm option
installed? Not sure if it's a separate product ID or an option to the
OS.
--
Post by Marc HB9CPW
Hi *all
After some hours of reading, testing i can't find a solution for the
I changed a little working sample program which writes a tab-delimited
file to the ifs.
When the program is used with CodePage 819 it works perfect.
I changed the codepage from 819 to 1208 UTF-8.
It is possible to create the file with codepage 1208 (checked with
OpsNav). But if the IFS-File is opened for writing, errorcode -1 appears
and nothing goes to the file.
Does anybody have a tip what has to be changed to get the UTF-8 file ?
Many thanks.
Marc
Markus Buehler www.pitag.ch
2005-10-03 06:19:19 UTC
Permalink
Thank you for your answer Rene.

These programs are installed:
5722SS1 V5R3M0 L00 OS/400 - Bibliothek QGPL
5722SS1 V5R3M0 L00 OS/400 - Bibliothek QUSRSYS
5722SS1 V5R3M0 L00 Betriebssystem IBM OS/400
5722SS1 V5R3M0 OS/400 - Erweiterte Basisunterstützung
5722SS1 V5R3M0 OS/400 - Online-Informationen
5722SS1 V5R3M0 OS/400 - Extended Base Directory Support
5722SS1 V5R3M0 OS/400 - IBM System /36-Umgebung
5722SS1 V5R3M0 OS/400 - IBM System /38-Umgebung
5722SS1 V5R3M0 OS/400 - Bibliothek mit Beispielprogrammen
5722SS1 V5R3M0 OS/400 - AFP-Verträglichkeitsschriftarten
5722SS1 V5R3M0 OS/400 - *PRV CL-Compiler-Unterstützung
5722SS1 V5R3M0 OS/400 - Host-Server
5722SS1 V5R3M0 OS/400 - System Openness Includes
5722SS1 V5R3M0 OS/400 - GDDM
5722SS1 V5R3M0 OS/400 - Erw. Unterstützung f. Landessprachen
5722SS1 V5R3M0 OS/400 - ObjectConnect
5722SS1 V5R3M0 OS/400 - Qshell
5722SS1 V5R3M0 OS/400 - Domain Name System
5722SS1 V5R3M0 OS/400 - Digital Certificate Manager
5722SS1 V5R3M0 OS/400 - PSF/400 1-45 IPM Printer Support
5722SS1 V5R3M0 OS/400 - International Components für Unicode
5722AC3 V5R3M0 Crypto Access Provider 128-bit
5722DG1 V5R3M0 IBM HTTP-Server
5722JC1 V5R3M0 Toolbox for Java
5722JV1 V5R3M0 Developer Kit for Java
5722JV1 V5R3M0 Java Developer Kit 1.3
5722QU1 V5R3M0 Abfrage
5722ST1 V5R3M0 DB2 Query Mgr and SQL DevKit
5722TC1 V5R3M0 TCP/IP Utilities
5722WDS V5R3M0 WebSphere Development Studio for iSeries
5722WDS V5R3M0 iSeries Tools - Application Development
5722WDS V5R3M0 ILE RPG
5722WDS V5R3M0 IBM System /36-kompatibles RPG II
5722WDS V5R3M0 RPG/400
5722WDS V5R3M0 ILE RPG *PRV Compiler
5722WDS V5R3M0 ILE COBOL
5722WDS V5R3M0 IBM System /36-kompatibles COBOL
5722WDS V5R3M0 IBM System /38-kompatibles COBOL
5722WDS V5R3M0 OPM COBOL
5722WDS V5R3M0 ILE COBOL *PRV Compiler
5722WDS V5R3M0 WebSphere Dev Studio Client - Server Support
5763XD1 V3R2M0 Client Access/400 Optimiert für Windows
5722XE1 V5R3M0 iSeries Access für Windows
5763XK1 V3R1M0 Client Access/400 für Windows 3.1
5763XK1 V3R1M0 CA/400 - Windows 3.1 SBCS
5763XK1 V3R1M0 CA/400 - Windows 3.1 DBCS
5763XK1 V3R1M0 CA/400 - Windows 3.1 PC5250 Koreanisch
5763XK1 V3R1M0 CA/400 - Windows 3.1 PC5250 Traditionelles Ch
5763XK1 V3R1M0 CA/400 - Windows 3.1 PC5250 Vereinfachtes Chi
5733XT1 V1R1M0 XML Toolkit for iSeries
5733XT1 V1R1M0 XML Parsers version 4.0
5733XT1 V1R1M0 XML Parsers version 4.0 development
5733XT1 V1R1M0 XML Toolkit Option 3 (see documentation)
5733XT1 V1R1M0 XML Toolkit Option 4 (see documentation)
5733XT1 V1R1M0 XML Toolkit Option 5 (see documentation)
5733XT1 V1R1M0 XML Toolkit Option 6 (see documentation)
5733XT1 V1R1M0 XML Toolkit Option 7 (see documentation)
5733XT1 V1R1M0 XML Toolkit Option 8 (see documentation)
5722XW1 V5R3M0 iSeries Access Family
5722XW1 V5R3M0 iSeries Access Enablement Support
Post by René H. Hartman
Just a thought: do you have the 'Support for UNICODE' licpgm option
installed? Not sure if it's a separate product ID or an option to the
OS.
stefano[dot]tassi[at]gruppopro[dot]it
2005-10-03 07:06:59 UTC
Permalink
If you specify O_TEXTDATA, when the data is read from the file, it is
converted from the CCSID of the file to the CCSID of the
job (1208 to 37 or another single byte ccsid).
open() fails when the file CCSID and open CCSID are not the same and
one of them is not
strictly single-byte or double-byte and return [ECONVERT] error.
Try to remove the O_TEXTDATA from the open statement.

HTH
Marc HB9CPW
2005-10-03 07:37:31 UTC
Permalink
Thank you Stefano for the tip.
I think when the O_TEXTDATA is removed from the open statement no
translation takes place.

This is what's in the file:
ę����ㅁ�Ӗ��
%ԉ�����@⃈�������ƅ�����@��������
%٤����@���������ƅ�����@@�������
%Ѥ��`ׁ���@Ԗ��������@打�����@��������
%Չ��@ȅ������@C��@c�����@打�����@��������
%ƅ������@�����م�����@@�������
%
Post by stefano[dot]tassi[at]gruppopro[dot]it
If you specify O_TEXTDATA, when the data is read from the file, it is
converted from the CCSID of the file to the CCSID of the
job (1208 to 37 or another single byte ccsid).
open() fails when the file CCSID and open CCSID are not the same and
one of them is not
strictly single-byte or double-byte and return [ECONVERT] error.
Try to remove the O_TEXTDATA from the open statement.
HTH
stefano[dot]tassi[at]gruppopro[dot]it
2005-10-03 11:10:33 UTC
Permalink
This post might be inappropriate. Click to display it.
Marc HB9CPW
2005-10-03 12:19:25 UTC
Permalink
Hi Stefano

I only found the %ucs2 BIF:
d outrec s 256
d outrecu s 256c inz(*LOVAL)
eval outrecu = %ucs2(outrec)
eval buflen = %len(%trim(outrecu))
eval rc = write(err_flag: %addr(outrecu): buflen)

In the ifs-file this looks like this:
D r i v e r T e M i c h a e l S c h u m a c h e r R u b e n s
B a r r i c h e l l o J u a n - P a b l o M o n t o y a B W N i c
k H e i d f e l d ä ö ü Ä Ö Ü B F e r n a n d o A l o n s o R

Strange it's not UTF-8 there are 2 bytes per character but the first
is always X'00'. Character D is x'00' x'44' and so on. The special
characters have also X'00'.

Maybe there is another trick for UTF-8.

Thank you for your help, this is really tricky !

Marc
Post by stefano[dot]tassi[at]gruppopro[dot]it
Hi Mark!
May be you must use a unicode variable/buffer in your write()
U'xxxx' or the %UCS built-in-function in order to
translate an SBCS string to an unicode string (data type = C)
HTH
stefano[dot]tassi[at]gruppopro[dot]it
2005-10-03 13:23:39 UTC
Permalink
this encoding is UCS-2, (sorry) not UTF-8.
UTF-8 is an encoding that "compress" data (UTF-8 treats ASCII data
(ISO8859-1) without conversion,
UCS2 puts before each charater hex '00'.
UCS-2 sounds like UTF-16, with 2 bytes/character: is an unicode
encoding.
UCS-2 is currently supported by ccsid 13488.
There are no biff in rpg to translate char filds to UTF-8 encoding.

a trick can be (if your input data is only SBCS) use ascii translation
with some api (e.g. QDCXLATE)

D translate pr ExtPgm('QDCXLATE')
D length 5P 0 const
D data 32766A options(*varsize)
D table 10A const

callp Translate(len:Data:'QASCII');

HTH
Marc HB9CPW
2005-10-03 13:56:11 UTC
Permalink
Thank you Stefano
I will try this, but first i'll read about "qdxlate". Have no idea where
UTF-8 is specified.
Marc
Post by stefano[dot]tassi[at]gruppopro[dot]it
this encoding is UCS-2, (sorry) not UTF-8.
UTF-8 is an encoding that "compress" data (UTF-8 treats ASCII data
(ISO8859-1) without conversion,
UCS2 puts before each charater hex '00'.
UCS-2 sounds like UTF-16, with 2 bytes/character: is an unicode
encoding.
UCS-2 is currently supported by ccsid 13488.
There are no biff in rpg to translate char filds to UTF-8 encoding.
a trick can be (if your input data is only SBCS) use ascii translation
with some api (e.g. QDCXLATE)
D translate pr ExtPgm('QDCXLATE')
D length 5P 0 const
D data 32766A options(*varsize)
D table 10A const
callp Translate(len:Data:'QASCII');
HTH
Loading...