Creating HTML file in IFS in RPGLE

Creating HTML file in IFS in RPGLE
Creating HTML file in IFS in RPGLE, unlink, ifspath,  HTML, The C language prototype in RPGLE, int *__errno(void);, char *strerror(int errnum), strerror() returns, char string, open(), write(), close(), SQLRPGLE , ifs , RPGLE, write data into the IFS file, Closes the file, open(), write(),  close(),  c apis, as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial, working with ifs
Creating HTML file in IFS in RPGLE

HTML Format (Webpages)

HTML stands for HyperText Markup Language. The HTML used to design the web pages and email templates since we need to have formatted text and fancy things in our webpages. Plain text is regular text with no formatting options such as Bold, Italics, Underline, Tables, Images, special layout options etc.

HTML uses markup tags that tells the web browser how to display text, images and other forms of multimedia on the webpage. Commonly used tags are <h1>, <h2>, <p>, <table>, <li> etc.

HTML elements always have opening tags, content in the middle and closing tags. Attributes can provide additional information about the element and are included in the opening tag.

RPGLE Program for Create HTML file in IFS

RPG Code in Fixed format to Create a HTML file in IFS.
     HDFTACTGRP(*NO)                                                                                
     FPF1       IF   E             DISK                                                             
                                                                                                    
     D unlink          PR            10I 0 ExtProc('unlink')                                        
     D ifspath                         *   Value options(*string)                                   
                                                                                                    
                                                                                                    
     D errorifs        PR              *   ExtProc('__errno')                                       
                                                                                                    
     D strerror        PR              *   ExtProc('strerror')                                      
     D error_num                     10I 0 value                                                    
                                                                                                    
                                                                                                    
     D close           PR            10i 0 extproc('close')                     *                   
     D fileds                        10i 0 value                                *file descriptor    
                                                                                                    
     D write           PR            10i 0 extproc('write')                     * 32 bit, no. of byt
     D fileds                        10i 0 value                                *file descriptor    
     D buffer                          *   value                                * pointer to byte   
     D noofbytes                     10U 0 value                                * 32 bits           
                                                                                                    
     D open            PR            10I 0 extproc('open')                                          
     D ifspath                         *   value options(*string)               *ifs path           
     D oflag                         10I 0 value                                *string of 32 bits  
     D mode                          10U 0 value options(*nopass)               * 9 bits            
     D codepage                      10U 0 value options(*nopass)               *                   
                                                                                                    
      * <-----oflag---->                                                                            
     D O_readonly      C                   1                                                        
     D O_writeonly     C                   2                                                        
     D O_readwrite     C                   4                                                        
     D O_createfileifnotexist...                                                                    
     D                 C                   8                                                        
     D O_exclusivecreate...                                                                         
     D                 C                   16                                                       
     D O_truncateto0bytes...                                                                        
     D                 C                   64                                                       
     D O_appendtofile  C                   256                                                      
     D O_converttextbycodepage...                                                                   
     D                 C                   8388608              
     D O_openintextmode...                                      
     D                 C                   16777216             
      *                                                         
      * <-----mode---->                                         
      * owner,group,other (RWX)                                 
      *                                         owner authority 
     D M_readowner     C                   256                  
     D M_writeowner    C                   128                  
     D M_executeowner  C                   64                   
      *                                         group authority 
     D M_readgroup     C                   32                   
     D M_writegroup    C                   16                   
     D M_executegroup  C                   8                    
      *                                         other people    
     D M_readother     C                   4                    
     D M_writeother    C                   2                    
     D M_executeother  C                   1                    
      *                                                         
     Difspath          s            512a                        
     Dreturn_unlink    s             10i 0 inz                                                 
     Doflag            s             10I 0                                                     
     Dmode             s             10U 0                                                     
     Dcodepage         s             10U 0 inz(819)                             * ascii cccsid 
     Dfiledescriptor   s             10i 0                                                     
     Difsdata          s            400a   inz                                                 
     Dreturn_write     s             10i 0 inz                                                 
     Dreturn_close     s             10i 0 inz                                                 
                                                                                               
                                                                                               
     Derror_ptr        S               *                                                       
     Derror_num        S             10I 0 based(error_ptr)                                    
                                                                                     c         
     Derrormsg_ptr     S               *                                                       
     Derror_msg        S            500a   based(errormsg_ptr)                                 
                                                                                               
     DCRLF             C                   CONST(x'0D25')                                      
     Dleftcurlybrace   C                   CONST(u'007B')                                      
     Drightcurlybrace  C                   CONST(u'007D')                                      
                                                                                               
     C                   EVAL      ifspath ='/home/easyclass/employeeTable.html'  
                                                                                  
     C                   EVAL      return_unlink = unlink(%trim(ifspath))         
                                                                                  
     C                   IF        return_unlink < 0                              
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      oflag = O_writeonly +                          
     C                                     O_createfileifnotexist +               
     C                                     O_converttextbycodepage                
     C                   EVAL      mode = M_readowner +                           
     C                                    M_writeowner +                          
     C                                    M_executeowner                          
                                                                                  
     C                   EVAL      filedescriptor = open(%trim(ifspath):          
     C                                                   oflag:                   
     C                                                   mode:                    
     C                                                   codepage)                
                                                                            
     C                   IF        filedescriptor < 0                       
     C                   EVAL      error_ptr = errorIFS()                   
     C                   EVAL      errormsg_ptr = strerror(error_num)       
     C                   RETURN                                             
     C                   ENDIF                                              
                                                                            
     C                   EVAL      return_close = close(filedescriptor)     
                                                                            
     C                   IF        return_close = -1                        
     C                   EVAL      error_ptr = errorIFS()                   
     C                   EVAL      errormsg_ptr = strerror(error_num)       
     C                   RETURN                                             
     C                   ENDIF                                              
                                                                            
     C                   EVAL       oflag = O_writeonly +                   
     C                                      O_openintextmode                
                                                                            
     C                   EVAL       filedescriptor = open(%trim(ifspath):   
     C                                                    oflag)            
                                                                               
     C                   IF        filedescriptor < 0                          
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
      * start creating HTML table for employee                                 
     C                   EVAL      ifsdata = '<html>'                          
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata))) 
                                                                               
     C                   IF        return_write < %len(%trim(ifsdata))         
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
     C                   EVAL      ifsdata = CRLF + '<style>'                  
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))   
                                                                                 
     C                   IF        return_write < %len(%trim(ifsdata))           
     C                   EVAL      error_ptr = errorIFS()                        
     C                   EVAL      errormsg_ptr = strerror(error_num)            
     C                   RETURN                                                  
     C                   ENDIF                                                   
                                                                                 
     C                   EVAL      ifsdata = CRLF + 'table, th, td ' +           
     C                                       %char(leftcurlybrace)               
     C                   EVAL      return_write = write(filedescriptor:          
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))   
                                                                                 
     C                   IF        return_write < %len(%trim(ifsdata))           
     C                   EVAL      error_ptr = errorIFS()                        
     C                   EVAL      errormsg_ptr = strerror(error_num)            
     C                   RETURN                                                  
     C                   ENDIF                                                   
                                                                                 
     C                   EVAL      ifsdata = CRLF + '  border:1px solid black;'  
     C                   EVAL      return_write = write(filedescriptor:         
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))  
                                                                                
     C                   IF        return_write < %len(%trim(ifsdata))          
     C                   EVAL      error_ptr = errorIFS()                       
     C                   EVAL      errormsg_ptr = strerror(error_num)           
     C                   RETURN                                                 
     C                   ENDIF                                                  
                                                                                
     C                   EVAL      ifsdata = CRLF + %char(rightcurlybrace)      
     C                   EVAL      return_write = write(filedescriptor:         
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))  
                                                                                
     C                   IF        return_write < %len(%trim(ifsdata))          
     C                   EVAL      error_ptr = errorIFS()                       
     C                   EVAL      errormsg_ptr = strerror(error_num)           
     C                   RETURN                                                 
     C                   ENDIF                                                  
                                                                                
     C                   EVAL      ifsdata = CRLF + '</style>'                  
     C                   EVAL      return_write = write(filedescriptor:              
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))       
                                                                                     
     C                   IF        return_write < %len(%trim(ifsdata))               
     C                   EVAL      error_ptr = errorIFS()                            
     C                   EVAL      errormsg_ptr = strerror(error_num)                
     C                   RETURN                                                      
     C                   ENDIF                                                       
                                                                                     
     C                   EVAL      ifsdata = CRLF + '<body>'                         
     C                   EVAL      return_write = write(filedescriptor:              
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))       
                                                                                     
     C                   IF        return_write < %len(%trim(ifsdata))               
     C                   EVAL      error_ptr = errorIFS()                            
     C                   EVAL      errormsg_ptr = strerror(error_num)                
     C                   RETURN                                                      
     C                   ENDIF                                                       
                                                                                     
     C                   EVAL      ifsdata = CRLF + '<h2>Employee Table</h2>'        
     C                   EVAL      return_write = write(filedescriptor:             
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))      
                                                                                    
     C                   IF        return_write < %len(%trim(ifsdata))              
     C                   EVAL      error_ptr = errorIFS()                           
     C                   EVAL      errormsg_ptr = strerror(error_num)               
     C                   RETURN                                                     
     C                   ENDIF                                                      
                                                                                    
     C                   EVAL      ifsdata = CRLF + '<table style="width:100%">'    
     C                   EVAL      return_write = write(filedescriptor:             
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))      
                                                                                    
     C                   IF        return_write < %len(%trim(ifsdata))              
     C                   EVAL      error_ptr = errorIFS()                           
     C                   EVAL      errormsg_ptr = strerror(error_num)               
     C                   RETURN                                                     
     C                   ENDIF                                                      
                                                                                    
     C                   EVAL      ifsdata = CRLF + '  <tr>'                        
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata))) 
                                                                               
     C                   IF        return_write < %len(%trim(ifsdata))         
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
     C                   EVAL      ifsdata = CRLF + '    <th>EMPID</th>'       
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata))) 
                                                                               
     C                   IF        return_write < %len(%trim(ifsdata))         
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
     C                   EVAL      ifsdata = CRLF + '    <th>EMPNAME</th>'     
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      ifsdata = CRLF + '    <th>MANAGERID</th>'      
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      ifsdata = CRLF + '  </tr>'                     
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C     1             SETLL     PF1                                            
     C                   READ      PF1                                            
     C                   DOW       not%eof(pf1)                                   
                                                                                  
     C                   EVAL      ifsdata = CRLF + '  <tr>'                      
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                      
     C                   ENDIF                                                       
                                                                                     
     C                   EVAL      ifsdata = CRLF + '    <td>' + EMPID + '</td>'     
     C                   EVAL      return_write = write(filedescriptor:              
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))       
                                                                                     
     C                   IF        return_write < %len(%trim(ifsdata))               
     C                   EVAL      error_ptr = errorIFS()                            
     C                   EVAL      errormsg_ptr = strerror(error_num)                
     C                   RETURN                                                      
     C                   ENDIF                                                       
                                                                                     
     C                   EVAL      ifsdata = CRLF + '    <td>' + EMPNAME +           
     C                                       '</td>'                                 
     C                   EVAL      return_write = write(filedescriptor:              
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))       
                                                                                     
     C                   IF        return_write < %len(%trim(ifsdata))               
     C                   EVAL      error_ptr = errorIFS()                            
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      ifsdata = CRLF + '    <td>' + MANAGERID +      
     C                                       '</td>'                              
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      ifsdata = CRLF + '  </tr>'                     
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
     C                   READ      PF1                                         
     C                   ENDDO                                                 
                                                                               
     C                   EVAL      ifsdata = CRLF + '</table>'                 
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata))) 
                                                                               
     C                   IF        return_write < %len(%trim(ifsdata))         
     C                   EVAL      error_ptr = errorIFS()                      
     C                   EVAL      errormsg_ptr = strerror(error_num)          
     C                   RETURN                                                
     C                   ENDIF                                                 
                                                                               
     C                   EVAL      ifsdata = CRLF + '</body>'                  
     C                   EVAL      return_write = write(filedescriptor:        
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      ifsdata = CRLF + '</html>'                     
     C                   EVAL      return_write = write(filedescriptor:           
     C                                    %addr(ifsdata):%len(%trim(ifsdata)))    
                                                                                  
     C                   IF        return_write < %len(%trim(ifsdata))            
     C                   EVAL      error_ptr = errorIFS()                         
     C                   EVAL      errormsg_ptr = strerror(error_num)             
     C                   RETURN                                                   
     C                   ENDIF                                                    
                                                                                  
     C                   EVAL      return_close = close(filedescriptor)           
     C                   IF        return_close = -1                              
     C                   EVAL      error_ptr = errorIFS()               
     C                   EVAL      errormsg_ptr = strerror(error_num)   
     C                   RETURN                                         
     C                   ENDIF                                          
                                                                        
     C                   EVAL      *INLR = *ON                          
     C                   RETURN                                                                               
RPG Code in /Free and /End-Free format to Create a HTML file in IFS.
     HDFTACTGRP(*NO)                                                                                
     FPF1       IF   E             DISK                                                             
                                                                                                    
     D unlink          PR            10I 0 ExtProc('unlink')                                        
     D ifspath                         *   Value options(*string)                                   
                                                                                                    
                                                                                                    
     D errorifs        PR              *   ExtProc('__errno')                                       
                                                                                                    
     D strerror        PR              *   ExtProc('strerror')                                      
     D error_num                     10I 0 value                                                    
                                                                                                    
                                                                                                    
     D close           PR            10i 0 extproc('close')                     *                   
     D fileds                        10i 0 value                                *file descriptor    
                                                                                                    
     D write           PR            10i 0 extproc('write')                     * 32 bit, no. of byt
     D fileds                        10i 0 value                                *file descriptor    
     D buffer                          *   value                                * pointer to byte   
     D noofbytes                     10U 0 value                                * 32 bits           
                                                                                                    
     D open            PR            10I 0 extproc('open')                                          
     D ifspath                         *   value options(*string)               *ifs path           
     D oflag                         10I 0 value                                *string of 32 bits  
     D mode                          10U 0 value options(*nopass)               * 9 bits            
     D codepage                      10U 0 value options(*nopass)               *                   
                                                                                                    
      * <-----oflag---->                                                                            
     D O_readonly      C                   1                                                        
     D O_writeonly     C                   2                                                        
     D O_readwrite     C                   4                                                        
     D O_createfileifnotexist...                                                                    
     D                 C                   8                                                        
     D O_exclusivecreate...                                                                         
     D                 C                   16                                                       
     D O_truncateto0bytes...                                                                        
     D                 C                   64                                                       
     D O_appendtofile  C                   256                                                      
     D O_converttextbycodepage...                                                                   
     D                 C                   8388608              
     D O_openintextmode...                                      
     D                 C                   16777216             
      *                                                         
      * <-----mode---->                                        
      * owner,group,other (RWX)                                 
      *                                         owner authority 
     D M_readowner     C                   256                  
     D M_writeowner    C                   128                  
     D M_executeowner  C                   64                   
      *                                         group authority 
     D M_readgroup     C                   32                   
     D M_writegroup    C                   16                   
     D M_executegroup  C                   8                    
      *                                         other people    
     D M_readother     C                   4                    
     D M_writeother    C                   2                    
     D M_executeother  C                   1                    
      *                                                         
     Difspath          s            512a                        
     Dreturn_unlink    s             10i 0 inz                                                 
     Doflag            s             10I 0                                                     
     Dmode             s             10U 0                                                     
     Dcodepage         s             10U 0 inz(819)                             * ascii cccsid 
     Dfiledescriptor   s             10i 0                                                     
     Difsdata          s            400a   inz                                                 
     Dreturn_write     s             10i 0 inz                                                 
     Dreturn_close     s             10i 0 inz                                                 
                                                                                               
                                                                                               
     Derror_ptr        S               *                                                       
     Derror_num        S             10I 0 based(error_ptr)                                    
                                                                                     c         
     Derrormsg_ptr     S               *                                                       
     Derror_msg        S            500a   based(errormsg_ptr)                                 
                                                                                               
     DCRLF             C                   CONST(x'0D25')                                      
     Dleftcurlybrace   C                   CONST(u'007B')                                      
     Drightcurlybrace  C                   CONST(u'007D')                                      
                                                       
      /free                                            
       ifspath = '/home/easyclass/employeeTable.html'; 
       return_unlink = unlink(%trim(ifspath));         
       if return_unlink < 0;                           
         error_ptr = errorIFS();                       
         errormsg_ptr = strerror(error_num);           
       endif;                                          
                                                       
       oflag = O_writeonly +                           
               O_createfileifnotexist +                
               O_converttextbycodepage;                
       mode =                                          
              M_readowner +                            
              M_writeowner +                           
              M_executeowner;                          
                                                       
       filedescriptor = open(%trim(ifspath):           
                             oflag:                    
                             mode:                     
                             codepage);              
                                                     
       if filedescriptor < 0;                        
         error_ptr = errorIFS();                     
         errormsg_ptr = strerror(error_num);         
         return;                                     
       endif;                                        
                                                     
       return_close = close(filedescriptor);         
       if return_close = -1;                         
         error_ptr = errorIFS();                     
         errormsg_ptr = strerror(error_num);         
         return;                                     
       endif;                                        
                                                     
                                                     
       oflag = O_writeonly +                         
               O_openintextmode;                     
                                                     
       filedescriptor = open(%trim(ifspath):         
                             oflag);                        
                                                            
       if filedescriptor < 0;                               
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       // start creating HTML table for employee            
       ifsdata = '<html>';                                  
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       ifsdata = CRLF + '<style>';                          
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                                  
         errormsg_ptr = strerror(error_num);                      
         return;                                                  
       endif;                                                     
                                                                  
       ifsdata = CRLF + 'table, th, td ' + %char(leftcurlybrace) ;
       return_write = write(filedescriptor:%addr(ifsdata):        
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                                  
         errormsg_ptr = strerror(error_num);                      
         return;                                                  
       endif;                                                     
                                                                  
       ifsdata = CRLF + '  border:1px solid black;';              
       return_write = write(filedescriptor:%addr(ifsdata):        
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + %char(rightcurlybrace);               
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '</style>';                           
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '<body>';                          
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '<h2>Employee Table</h2>';         
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                              
       ifsdata = CRLF + '<table style="width:100%">';         
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '  <tr>';                             
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '    <th>EMPID</th>';                 
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '    <th>EMPNAME</th>';              
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '    <th>MANAGERID</th>';            
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       ifsdata = CRLF + '  </tr>';                          
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
                                                            
                                                            
       setll 1 pf1;                                         
       read pf1;                                            
       dow not%eof(pf1);                                    
                                                              
         ifsdata = CRLF + '  <tr>';                           
         return_write = write(filedescriptor:%addr(ifsdata):  
                        %len(%trim(ifsdata)));                
         if return_write < %len(%trim(ifsdata));              
           error_ptr = errorIFS();                            
           errormsg_ptr = strerror(error_num);                
           return;                                            
         endif;                                               
                                                              
         ifsdata = CRLF + '    <td>' + EMPID + '</td>';       
         return_write = write(filedescriptor:%addr(ifsdata):  
                        %len(%trim(ifsdata)));                
         if return_write < %len(%trim(ifsdata));              
           error_ptr = errorIFS();                            
           errormsg_ptr = strerror(error_num);                
           return;                                            
         endif;                                               
                                                              
         ifsdata = CRLF + '    <td>' + EMPNAME + '</td<';     
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));                  
           error_ptr = errorIFS();                                
           errormsg_ptr = strerror(error_num);                    
           return;                                                
         endif;                                                   
                                                                  
         ifsdata = CRLF + '    <td>' + MANAGERID + '</td>';       
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));                  
           error_ptr = errorIFS();                                
           errormsg_ptr = strerror(error_num);                    
           return;                                                
         endif;                                                   
                                                                  
         ifsdata = CRLF + '  </tr>';                              
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));             
           error_ptr = errorIFS();                           
           errormsg_ptr = strerror(error_num);               
           return;                                           
         endif;                                              
                                                             
         read pf1;                                           
       enddo;                                                
                                                             
       ifsdata = CRLF + '</table>';                          
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '</body>';                           
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '</html>';                         
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       return_close = close(filedescriptor);               
       if return_close = -1;                               
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;       
       endif;          
                       
       *inlr = *on;    
       return;         
      /end-free                                                                                                                                  
RPG Code in Fully Free format to Create a HTML file in IFS.
**FREE                                        
CTL-OPT DFTACTGRP(*NO);                       
                                              
DCL-F PF1;                                    
                                              
DCL-PR unlink int(10) EXTPROC('unlink');      
  ifspath pointer VALUE options(*string);     
END-PR;                                       
                                              
DCL-PR errorifs pointer EXTPROC('__errno');   
END-PR;                                       
                                              
DCL-PR strerror pointer EXTPROC('strerror');  
  error_num int(10) VALUE;                    
END-PR;                                       
                                              
DCL-PR close int(10) EXTPROC('close');        
  fileds int(10) VALUE;                       
END-PR;                                       
                                            
DCL-PR write int(10) EXTPROC('write');      
  fileds  int(10) VALUE;                    
  buffer  pointer VALUE;                    
  noofbytes uns(10) VALUE;                  
END-PR;                                     
                                            
DCL-PR open int(10) EXTPROC('open');        
  ifspath pointer VALUE options(*string);   
  oflag   int(10) VALUE;                    
  mode uns(10) VALUE options(*nopass);      
  codepage uns(10) VALUE options(*nopass);  
END-PR;                                     
// * <-----oflag---->                      
DCL-C O_readonly 1;                         
DCL-C O_writeonly 2;                        
DCL-C O_readwrite 4;                        
DCL-C O_createfileifnotexist 8;             
DCL-C O_exclusivecreate 16;                 
DCL-C O_truncateto0bytes 64;                
DCL-C O_appendtofile  256;                                       
DCL-C O_converttextbycodepage 8388608;                           
DCL-C O_openintextmode 16777216;                                 
//    * <-----mode---->                                          
//    * owner,group,other (RWX)                                  
//    *                                         owner authority  
DCL-C M_readowner 256;                                           
DCL-C M_writeowner 128;                                          
DCL-C M_executeowner 64;                                         
//    *                                         group authority  
DCL-C M_readgroup 32;                                            
DCL-C M_writegroup 16;                                           
DCL-C M_executegroup 8;                                          
//    *                                         other people     
DCL-C M_readother 4;                                             
DCL-C M_writeother 2;                                            
DCL-C M_executeother 1;                                          
                                                                 
DCL-S ifspath CHAR(512);                                         
DCL-S return_unlink int(10);                                     
DCL-S oflag int(10);                                    
DCL-S mode  uns(10);                                    
DCL-S codepage uns(10) inz(819); // ascii codepage      
DCL-S filedescriptor int(10);                           
DCL-S ifsdata char(500) inz;                            
DCL-S return_write int(10) inz;                         
DCL-S return_close int(10) inz;                         
                                                        
DCL-S error_ptr pointer;                                
DCL-S error_num int(10) based(error_ptr);               
                                                        
DCL-S errormsg_ptr pointer;                             
DCL-S error_msg char(500) based(errormsg_ptr);          
                                                        
DCL-C CRLF CONST(x'0D25');                              
DCL-C leftcurlybrace CONST(u'007B');                    
DCL-C rightcurlybrace  CONST(u'007D');                  
                                                        
       ifspath = '/home/easyclass/employeeTable.html'; 
       return_unlink = unlink(%trim(ifspath));         
       if return_unlink < 0;                           
         error_ptr = errorIFS();                       
         errormsg_ptr = strerror(error_num);           
       endif;                                          
                                                       
       oflag = O_writeonly +                           
               O_createfileifnotexist +                
               O_converttextbycodepage;                
       mode =                                          
              M_readowner +                            
              M_writeowner +                           
              M_executeowner;                          
                                                       
       filedescriptor = open(%trim(ifspath):           
                             oflag:                    
                             mode:                     
                             codepage);              
                                                     
       if filedescriptor < 0;                        
         error_ptr = errorIFS();                     
         errormsg_ptr = strerror(error_num);         
         return;                                     
       endif;                                        
                                                     
       return_close = close(filedescriptor);         
       if return_close = -1;                         
         error_ptr = errorIFS();                     
         errormsg_ptr = strerror(error_num);         
         return;                                     
       endif;                                        
                                                     
                                                     
       oflag = O_writeonly +                         
               O_openintextmode;                     
                                                     
       filedescriptor = open(%trim(ifspath):         
                             oflag);                        
                                                            
       if filedescriptor < 0;                               
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       // start creating HTML table for employee            
       ifsdata = '<html>';                                  
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       ifsdata = CRLF + '<style>';                          
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                                  
         errormsg_ptr = strerror(error_num);                      
         return;                                                  
       endif;                                                     
                                                                  
       ifsdata = CRLF + 'table, th, td ' + %char(leftcurlybrace) ;
       return_write = write(filedescriptor:%addr(ifsdata):        
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                                  
         errormsg_ptr = strerror(error_num);                      
         return;                                                  
       endif;                                                     
                                                                  
       ifsdata = CRLF + '  border:1px solid black;';              
       return_write = write(filedescriptor:%addr(ifsdata):        
                      %len(%trim(ifsdata)));                      
       if return_write < %len(%trim(ifsdata));                    
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + %char(rightcurlybrace);               
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '</style>';                           
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '<body>';                          
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '<h2>Employee Table</h2>';         
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                              
       ifsdata = CRLF + '<table style="width:100%">';         
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '  <tr>';                             
       return_write = write(filedescriptor:%addr(ifsdata):    
                      %len(%trim(ifsdata)));                  
       if return_write < %len(%trim(ifsdata));                
         error_ptr = errorIFS();                              
         errormsg_ptr = strerror(error_num);                  
         return;                                              
       endif;                                                 
                                                              
       ifsdata = CRLF + '    <th>EMPID</th>';                 
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '    <th>EMPNAME</th>';              
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '    <th>MANAGERID</th>';            
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
       ifsdata = CRLF + '  </tr>';                          
       return_write = write(filedescriptor:%addr(ifsdata):  
                      %len(%trim(ifsdata)));                
       if return_write < %len(%trim(ifsdata));              
         error_ptr = errorIFS();                            
         errormsg_ptr = strerror(error_num);                
         return;                                            
       endif;                                               
                                                            
                                                            
                                                            
       setll 1 pf1;                                         
       read pf1;                                            
       dow not%eof(pf1);                                    
                                                              
         ifsdata = CRLF + '  <tr>';                           
         return_write = write(filedescriptor:%addr(ifsdata):  
                        %len(%trim(ifsdata)));                
         if return_write < %len(%trim(ifsdata));              
           error_ptr = errorIFS();                            
           errormsg_ptr = strerror(error_num);                
           return;                                            
         endif;                                               
                                                              
         ifsdata = CRLF + '    <td>' + EMPID + '</td>';       
         return_write = write(filedescriptor:%addr(ifsdata):  
                        %len(%trim(ifsdata)));                
         if return_write < %len(%trim(ifsdata));              
           error_ptr = errorIFS();                            
           errormsg_ptr = strerror(error_num);                
           return;                                            
         endif;                                               
                                                              
         ifsdata = CRLF + '    <td>' + EMPNAME + '</td<';     
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));                  
           error_ptr = errorIFS();                                
           errormsg_ptr = strerror(error_num);                    
           return;                                                
         endif;                                                   
                                                                  
         ifsdata = CRLF + '    <td>' + MANAGERID + '</td>';       
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));                  
           error_ptr = errorIFS();                                
           errormsg_ptr = strerror(error_num);                    
           return;                                                
         endif;                                                   
                                                                  
         ifsdata = CRLF + '  </tr>';                              
         return_write = write(filedescriptor:%addr(ifsdata):      
                        %len(%trim(ifsdata)));                    
         if return_write < %len(%trim(ifsdata));             
           error_ptr = errorIFS();                           
           errormsg_ptr = strerror(error_num);               
           return;                                           
         endif;                                              
                                                             
         read pf1;                                           
       enddo;                                                
                                                             
       ifsdata = CRLF + '</table>';                          
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));                 
       if return_write < %len(%trim(ifsdata));               
         error_ptr = errorIFS();                             
         errormsg_ptr = strerror(error_num);                 
         return;                                             
       endif;                                                
                                                             
       ifsdata = CRLF + '</body>';                           
       return_write = write(filedescriptor:%addr(ifsdata):   
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       ifsdata = CRLF + '</html>';                         
       return_write = write(filedescriptor:%addr(ifsdata): 
                      %len(%trim(ifsdata)));               
       if return_write < %len(%trim(ifsdata));             
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;                                           
       endif;                                              
                                                           
       return_close = close(filedescriptor);               
       if return_close = -1;                               
         error_ptr = errorIFS();                           
         errormsg_ptr = strerror(error_num);               
         return;       
       endif;          
                       
       *inlr = *on;    
       return;              

Explanation of the above code

  • We first delete the file if exist using unlink() api.
  • Then we create if not exist and open the ifs stream file in write only mode (ASCII text file by passing codepage 819- windows supported) using the open() api.
  • Now, we close the file using close() api.
  • Again, open the html file using open() api in write only mode and text mode so that we can write the html markup tage in the form of text in the .html stream file on the ifs.
  • Now, start writing the html content for employee table on the ifs stream file. We will read file PF1 data to be printed in table data in html format. Also, using CRLF character to write every text being written on each write() api call on the next line.
  • Finally, we close the file using close() api.
  • Please note that we used two constants as below:
    Here, we used unicode values for these two variables as these character might be translated on different ccsid and resulted in incorrect .html file content generated.

    DCL-C leftcurlybrace CONST(u'007B');
    DCL-C rightcurlybrace CONST(u'007D');

    Output of the above code

    File EmployeeTable.html will get created on the ifs that is an ASCII text file(codepage - 819) but with html capabilities.So when you download this html file using ACS and open with notepad you will see the below output generated by the program.

    <html>
    <style>
    table, th, td {
      border:1px solid black;
    }
    </style>
    <body>
    <h2>Employee Table</h2>
    <table style="width:100%">
      <tr>
        <th>EMPID</th>
        <th>EMPNAME</th>
        <th>MANAGERID</th>
      </tr>
      <tr>
        <td>1         </td>
        <td>NAME1               </td>
        <td>MNGR1     </td>
      </tr>
      <tr>
        <td>2         </td>
        <td>NAME2               </td>
        <td>MNGR1     </td>
      </tr>
    </table>
    </body>
    </html>
    

    If you open the above downloaded html file using google chrome browser you will see the above html code gets formatted into the table format when displayed on the browser.

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain