Skip to main content  
        iSeries home   |   Easy400     |   CGIDEV2  
Public source
 
About it
IBMi and Unicode
IBMi and Base64
CRLF commands
DSPSTMF command
 
Display the Change Log
 
Download
 
 

 
About CVT101  
by Giovanni B. Perotti (Italy)
Reading or writing an IFS stream file is not much of a job for a RPG programmer. IBM i provides an automated way to translate character strings from the job CCSID (example: 37. But it must not be 65535!) to the IFS stream file CCSID (example: 819, US ASCII).
This automated translation takes place whenever a stream file is opened with the open flag O_TEXTDATA.
See the following example:
  • Reading non-unicode stream files
    Reading an IFS stream file through an ILE-RPG program is usually no problem, as the stream file data can be automatically translated from the stream file code page to the job CCSID.
    Let us take, as an example, the stream file containing this page, intro.htm, code page 819.
    The ILE-RPG code to read it is pretty simple (See CVT101/SAMPLERPG member STMFREAD):
     /copy CVT101/qrpglesrc,hspecs                                      
     /copy CVT101/qrpglesrc,hspecsbnd                                   
                                                                        
    D Stmf            s            256    inz('/cvt101/html/intro.htm') 
    D Handle          s             10i 0                               
    D Buffer          s          10000                                  
    D DataLen         s             10i 0                               
    D rc              s             10i 0                               
    D O_RDONLY        s             10i 0 inz(1)                        
    D O_TEXTDATA      s             10i 0 inz(16777216)                 
    D open            pr            10i 0 extproc('open')               
    D  filename                       *   value options(*string)        
    D  openflags                    10i 0 value                         
    D  mode                         10u 0 value options(*nopass)        
    D  codepage                     10u 0 value options(*nopass)        
    D read            pr            10i 0 extproc('read')               
    D  filehandle                   10i 0 value                         
    D  datareceived                   *   value                         
    D  nbytes                       10u 0 value                         
    D close           pr            10i 0 extproc('close')              
    D  filehandle                   10i 0 value                       
     /free                                                                               
                                                                                         
        Handle=open(%trim(Stmf):O_RDONLY + O_TEXTDATA);         // Open the stream file  
                                                                                         
        // Loop reading the stream file into "Buffer"                                    
        DataLen=1;                                                                       
        dow DataLen>0;                                                                   
            DataLen=read(Handle:%addr(Buffer):%size(Buffer));                            
            // ... process the stream file data ...                                      
        enddo;                                                                           
                                                                                         
        rc=close(Handle);                                       // Close the stream file 
                                                                                         
        return;                                                 // Back to caller        
    The data read into the buffer are automatically converted to the job CCSID (or to the job default CCSID, if the job CCSID is 65535). This is why the program can understand and process (if needed) that data.
    This is done by specifying the flag O_TEXTDATA on the open() of the stream file.
However, if the IFS stream file is a UNICODE or a BASE64 encoded one, it is necessary to convert it to a "regular" CCSID stream file, in order to take advantage from the automated translation to the job CCSID provided with the open flag O_TEXTDATA.

This CVT101 utility provides tools to perform UNICODE and BASE64 transform to a "regular" CCSID.
See the next pages.


    Contact