Link to home
Create AccountLog in
Avatar of Drew Stephens
Drew Stephens

asked on

Unable to write ASCII to IFS from RPGLE program

I am creating and writing to an IFS File and want the file to be written in ASCII format.  I am using the C "open" and "write" APIs.  Here is the text I am using to create the file.

//
         flags = O_CREAT + O_RDWR + O_TEXTDATA + O_TEXT_CREAT + O_CCSID
                 + O_TRUNC + O_TEXT_CREAT;
         mode = S_IRWXU;                  // Grant the Owner full rights
         mode += S_IRGRP + S_IWGRP;       // Grant Owner's Group Read and Exec rights
         mode += S_IROTH + S_IWOTH;       // Grant all others Read and Exec rights

         // Create the IFS File...
         fd = open(%trim(scriptPath):
                     flags:
                       mode:
                         CP_WINDOWS);    // Important for CCSID to be Windows Compliant.
          if fd >= *ZEROS;
           callp close(fd);                // Save to the folder
           scriptIsOpen = *OFF;
           // Now that the file is created, open it for processing.
           flags = O_WRONLY + O_TEXTDATA + O_CCSID;
           fd = open(%trim(scriptPath):
                       flags:
                         mode:
                           CP_WINDOWS);    // Important for CCSID to be Windows Commpliant.
          endif;                                                              

Unfortunately, when I write to the file,  The text is being written as EBCDIC (CCSID = 37)  even though the file is defined with the CCSID set to 1252.

Is it possible to write ASCII text to an IFS file via RPGLE?  I found some articles about some UNIX APIs (fopen, fwrite, etc.) that sounded interesting but I couldn't find any examples of how to use them.

Any suggestions?
Avatar of Theo Kouwenhoven
Theo Kouwenhoven
Flag of Netherlands image

Hi Drew,

As far as I know, you can't write ASCII data to an EBCDIC IFS-path.

So you have to create a ASCII map.
Use the navigator to look to the properties of the map.
DON'T make it al PC map, if you do you can't approach it from the iServer
Yes, as long as it is a supported conversion, you can automatically convert EBCDIC to ASCII when writing to an IFS file.  

This works of the file does not already exist.  If file already exists, and is not CCSID 819, this won't work.

file1 = open( '/my/path/and/file.csv'
: O_WRONLY + O_CREAT + O_TRUNC + O_CCSID
: M_RDWR
: 819 );
ASKER CERTIFIED SOLUTION
Avatar of Drew Stephens
Drew Stephens

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Yes, you can use dcxlate or iconv() apis, but why when posix apis will do it for you?

Anyway, glad you found a solution that works for you.