Midrange News for the IBM i Community


Posted by: renojim
Writing text to IFS
has no ratings.
Published: 16 Dec 2015
Revised: 17 Dec 2015 - 500 days ago
Last viewed on: 30 Apr 2017 (1111 views) 

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 text to IFS Published by: renojim on 16 Dec 2015 view comments(4)

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?

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Writing text to IFS
Posted: 1 years 4 months 15 days 15 hours 34 minutes ago
Edited: Wed, 16 Dec, 2015 at 16:17:02 (501 days ago)

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.

 

 

Posted by: Ringer
Premium member *
Comment on: Writing text to IFS
Posted: 1 years 4 months 15 days 14 hours 8 minutes ago

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

 

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Writing text to IFS
Posted: 1 years 4 months 15 days 12 hours 9 minutes ago

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 

 

Posted by: renojim
Premium member *
Comment on: Writing text to IFS
Posted: 1 years 4 months 14 days 19 hours 27 minutes ago

Worked beautifully, Thanks!