Looks like you are missing O_Ccsid, which triggers the text conversion.

When creating the file, and wanting text conversion, you need the 5th parm and these oflag values: O_Ccsid + O_Textdata + O_Text_Creat
You need to pass the 5th parm program's ccsid (zero for job ccsid).



I've found that opening the file once to create it tends to work better overall. Then Opening the file again for output.
// To create
Fd = Open( Filename
: O_Rdwr +O_Creat +O_Ccsid + O_Textdata + O_Text_Creat + O_TRUNC + O_INHERITMODE
: M_RWX : ccsid : 0);
If Fd < 0;
Errormsg = 'Error text: ' + %Char(Error_globalErrNo()) +' '+ %Trim(Error_globalErrNoTxt());
Endif;

If Fd < 0;
Return UTLF_FAILURE;
Else;
rc = Close( Fd );
Endif;


// To Output with text conversion from JOB ccsid.
Fd = Open( Filename
: O_Rdwr + O_Textdata+ O_CCSID+ O_APPEND
: M_RWX : ccsid : 0);



To set the CCSID of existing files use Qp0lSetAttr. This is sometimes necessary when the system auto creates the file with 1252.


// Get Qlg_Path_Name_t
/COPY QSYSINC/QRPGLESRC,SYSTYPES

// --------------------------------------------------
// Procedure name: UTLF_SetCcsid
// Purpose: set a file's CCSID.
// Runs the API to change a files CCSID.
// Does not modify the file contents.

// Returns: n/a
// Parameter: Filename
// Parameter: CCSID
// --------------------------------------------------
Dcl-Proc UTLF_SetCcsid Export;
Dcl-Pi *N;
Filename Varchar(1024) Const;
FileCCSID Uns(10) Const;
End-pi;
Dcl-Pr Qp0lSetAttr Int(10) EXTPROC('Qp0lSetAttr');
Path_Name Likeds(Qlg_Path_Name_t) Const;
Pr_Attarr Pointer VALUE;
Pr_Bytprv Uns(10) VALUE;
Pr_Flwsymlnk Uns(10) VALUE;
End-Pr;
Dcl-ds apiBuffer_t Len(16) Qualified;
NextOffset Uns(10);
AttrId Uns(10);
Size Uns(10);
End-ds;
Dcl-ds CCSID_DS Qualified;
k Likeds(apiBuffer_t);
CCSID Int(10);
End-ds;
Dcl-ds FilePath Likeds(Qlg_Path_Name_t);

UTLF_Init_Qlg_Path_Name( Filename : Filepath );
Clear CCSID_DS;
CCSID_DS.k.AttrId = 27;
CCSID_DS.K.Size = %Size(CCSID_DS.Ccsid);
CCSID_DS.Ccsid = FileCCSID;
Callp Qp0lSetAttr( FilePath : %Addr(ccsid_ds) : %Size( Ccsid_ds) : 1 );

End-proc;

--
Chris Hiebert
Lead Software Developer
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.

From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of konsult@xxxxxxxxxxxxxxx
Sent: Tuesday, December 2, 2025 8:01 AM
To: midrange-l <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Writing to IFS from RPGLE but needs UTF-8


I need to create a file in the IFS and the file HAS to be encoded in UTF-8

(CCSID 1208).



The machine is unfortunately running on V7R1 and that is due to a software

package that cannot (as I am told be migrated to more current releases). So

writing with SQL is out of the equation, sadly.





I have tested a function based on Scott Klements writings and while it works

with conversion to ASCII it fails when I change to CCSID 1208.





As per the example the IFS file is first created with 1208 as the CCSID.

This works and is coded thus:





c eval fd = open('/home/ao/ch5_file3.txt':



c O_CREAT+O_WRONLY+O_CCSID:



c S_IWUSR+S_IRUSR+S_IRGRP+S_IROTH:



c 1208)





But when the file is closed an reopened this open gets an error:





c eval fd = open('/home/ao/ch5_file3.txt':



c O_WRONLY+O_TEXTDATA)





I receive an "open() conversion error"





Any suggestions? I assume that I need some other parameters for the second

open when using UTF-8 but I have as yet not found which one to use or

possibly omit.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.