On 2025-02-07 3:12 p.m., smith5646midrange@xxxxxxxxx wrote:
I have a program that writes data to the IFS.

Strings are concatenated into dataString. Eventually dataString is written
to the IFS. It used to only write UTF-8 so it utilized the CCSID on the
variable as follows.

dcl-s dataString varchar(1048576) ccsid(1208);

Now my client has times they want to write ebcdic instead of utf8. ...

When you use open() to open an IFS file for output and create, you can specify 5 parameters. The 4th parameter is the CCSID you you want the file to be created with and the 5th parameter is the CCSID of the data you will pass to the write() function.

https://www.ibm.com/docs/api/v1/content/ssw_ibm_i_75/apis/open.htm

Try this:
/copy qsysinc/qrpglesrc,ifs

dcl-s utf8_string varchar(100) ccsid(1208);
dcl-s ifs_handle int(10);
dcl-s oflag int(10);
dcl-s omode int(10);
dcl-s bytes int(10);
dcl-s rc int(10);

utf8_string = '12345';

oflag = O_WRONLY
+ O_CREAT
+ O_TEXT_CREAT
+ O_TRUNC
+ O_CCSID
+ O_TEXTDATA
+ O_SHARE_NONE;
omode = S_IRUSR
+ S_IWUSR
+ S_IRGRP
+ S_IROTH;

ifs_handle = open ('ccsid_37' : oflag : omode
: 37 : 1208);
bytes = write (ifs_handle
: %addr(utf8_string : *data)
: %len(utf8_string));
rc = close (ifs_handle);

ifs_handle = open ('ccsid_1208' : oflag : omode
: 1208 : 1208);
bytes = write (ifs_handle
: %addr(utf8_string : *data)
: %len(utf8_string));
rc = close (ifs_handle);

return;

After I ran my program, WRKLNK option 8 shows that file ccsid_37 has CCSID 37 and file ccsid_1208 has CCSID 1208. WRKLNK option 5 shows "12345" for both files.

When I do DMP for the files, I see this for the "SPACE" section of the output:

DMP for file ccsid_37:

SPACE-
000000 F1F2F3F4 F5
(x'F1F2F3F4F5' is is "12345" in CCSID 37)

DMP for file ccsid_1208:

SPACE-
000000 31323334 35

(x'3132333435' is "12345" in CCSID 1208)



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.