Blog Archive

RPGLE write data to IFS - Using C APIs open() close() Write()

h dftactgrp(*no) bnddir('QC2LE')              
h option (*nodebugio)                         
                                              
d/copy *libl/qrpglesrc,IFSIO_H                
                                             
d fd              s             10I 0         
d crlf            c                   x'0D25' 
d $xml            s            512a           
                                              
d $file_name      s             50            
d $file_path      s            100            
                                              
d ProgStatus     sds                          
d  Parms            *PARMS                    
d  ProgName         *PROC                     
d  ErrMsgID              40     46            
d  ErrMsg                91    169            
d  JobName              244    253            
d  Userid               254    263            
d  JobNumber            264    269            
                                              
 *                                            
 *----- Main Routine                           
*                                                          
c                   exsr      @open_file                    
c                   exsr      @write_data                   
c                   exsr      @close_file                   
c                   eval      *inlr = *on                   
c                   return                                  
 *                                                          
 *----- Open IFS file                                       
 *                                                          
c     @open_file    begsr                                   
                                                            
c                   eval      $file_name = 'Mydata.xml'     
c                   eval      $file_path = '/Myxml/data/' + 
c                                          %trim($file_name)
 /free                                                      
                                                            
   fd = open(%trim($file_path)                              
             : O_WRONLY+O_CREAT+O_TRUNC+O_CCSID             
             : S_IRGRP + S_IWGRP + S_IXGRP                  
             : 819);                                        
   callp close(fd);                                         
   fd = open(%trim($file_path):O_WRONLY+O_TEXTDATA);        
                                                            
   $xml = '<?xml version="1.0" encoding="UTF-8"?>' + crlf +
          '<MyData>' + crlf;                               
   callp write(fd: %addr($xml): %len(%trim($xml)));        
                                                           
 /end-free                                                 
                                                           
c                   endsr                                  
 *                                                         
 *----- Close IFS file                                     
 *                                                         
c     @close_file   begsr                                  
                                                           
 /free                                                     
                                                           
   $xml = '</MyData>' + crlf;                              
   callp write(fd: %addr($xml): %len(%trim($xml)));        
   callp close(fd);                                        
                                                           
 /end-free                                                 
                                                           
c                   endsr                                  
 *                                                         
 *----- Write Data into the IFS file                       
*                                                    
c     @write_data   begsr                             
                                                      
 /free                                                
                                                      
   $xml = '<Name>' +                                  
            'My name is $user_id' +                   
          '</Name>' + crlf;                           
   callp write(fd: %addr($xml): %len(%trim($xml)));   
                                                      
   $xml = '<Date>' +                                  
            'Today is ' + %char(%date()) +            
          '</Date>' + crlf;                           
   callp write(fd: %addr($xml): %len(%trim($xml)));   
                                                      
 /end-free                                            
                                                      
c                   endsr                             
 *                                                    
 *----- Initial Routine                               
 *                                                    
c     *inzsr        begsr                             
                          
c                   endsr     

Output for the above program in IFS

<?xml version="1.0" encoding="UTF-8"?>     
<MyData>                                   
<Name>My name is $user_id</Name>           
<Date>Today is 2011-06-08</Date>           
</MyData>         

Click here if you need source for IFSIO_H


6 comments :

  1. Hello,
    When I compiled this RPGLE, got following compilation errors, WRITE and CLOSE are not defined and Compiler not able to open the /COPY or /INCLUDE file; directive ignored. Few other 7030 errors but I believe, if you please kindly explain how to fix those three major errors, will resolve all other 7030 errors.
    Thanks - Hashim

    ReplyDelete
  2. Hello,
    When I compiled this RPGLE, got following compilation errors, WRITE and CLOSE are not defined and Compiler not able to open the /COPY or /INCLUDE file; directive ignored. Few other 7030 errors but I believe, if you please kindly explain how to fix those three major errors, will resolve all other 7030 errors.
    Thanks - Hashim

    ReplyDelete
  3. Hello Hashim
    You can get the copy member IFSIO_H from Scott Klement:
    http://www.scottklement.com/rpg/ifs.html
    You'll find sample programs and a tutorial there.
    I guess once you have that member in the library list the program will compile alright.
    Regards
    Stefan
    softd.ch

    ReplyDelete

  4. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball | 192.168.1.1

    ReplyDelete
  5. With the mental approach we can dissect the proportion of typical individuals or the general population enduring with a mental issue, by this we can likewise gauge the proportion of training quality.Online Typing Services

    ReplyDelete