Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
Writing a text file to the IFS from RPG, tried using fopen, fputs, _C_IFS_fopen, _C_IFS_fputs, everything which way I can find to do it, opening the file with different CCSID's, including 819, I can create and write to the file, but no matter what, I go to Ops Navigator, drag the file from the IFS to my desktop and open it with a text editor, I get all @'s, plus some other goop. I've done this before without a problem, can't figure it out this time. Is it obvious, what I'm doing wrong?
This is a classic issue.
To do what you want, you first have to create the file as CCSID(819) using whatever you want. I use the open and open64 functions (C runtime) instead of _C_IFS_fopen because open64 is simpler when creating a file.
Then close the file, once it has been initially opened and created. if you used open64() be sure to use close() to close it.
Then use your _C_IFS_fopen with CCSID(0) which is probably the default. Then upon a fwrite, the data will automatically be converted to 819 from your job's CCSID.
So if you are already creating it as 819, fine, then remember once it is created, close it, and re-open it as CCSID(0) for the autoconvert option. Note: if the file already exists prior to running your program, and it is CCSID(819) you don't have to do the initial open/create step. But I figure this isn't the case or you wouldn't be asking.
A blank in EBCDIC CCSID 37 is hex 40, which happens to be an @ in ASCII (CCSID 1252 and 819). So your text editor thinks it's @.
There is a way to open/create the file without having to close it but I forget the combo of flags. I can probably find it if you want it.
Chris Ringer
Check out the bottom of this page. It shows you how to do it booths ways. It's in C but the technique is the same for RPG.
https://www-01.ibm.com/support/knowledgecenter/mobile/#!/ssw_ibm_i_71/apis/open.htm