Knowledge Shared (Beta)


Posted by: Bob Cozzi
IT Researcher
Cozzi Productions, Inc.
North Aurora, IL
Page 1401 has no ratings.
Deleting IFS Files in RPG IV
Updated: 02 Dec 2009 - 277 days ago
Last viewed on: 05 Sep 2010 (506 views)
Deleting IFS Files in RPG IV

The UNLINK API can be used from RPG IV to remove files from the IFS. The IFS is the stream file system of the IBM i operating system.

Syntax Diagram

return-code = unlink( ifs-file )

The following example illustrates unlink() being used in an RPG IV program. Note that control statements in this example allow it to be compiled at any release level of the IBM i operating system.

      /IF DEFINED(*V6R1M0)                                        
     H MAIN(DLTIFS)                                               
      /ELSE                                                       
     H BNDDIR('QC2LE')                                            
      /ENDIF                                                      
     H DFTACTGRP(*NO)  BNDDIR('RPGOPEN/RPGOPEN')                  
      /INCLUDE rpgopen/qcpysrc,joblog                             
                                                                  
     D DLTIFS          PR                  EXTPGM('DLTIFS')       
                                                                  
     D unlink          PR            10I 0 extProc('unlink')      
     D  ifsFile                        *   VALUE OPTIONS(*STRING) 
                                                                  
      /IF DEFINED(*V6R1M0)                                        
     P dltIFS          B                                          
      /endif                                                      
                                                                  
     D dltIFS          PI                                         

     D oldFile         S            640A                      
                                                              
      /IF NOT DEFINED(*V6R1M0)                                
     C                   EVAL      *INLR = *ON                
      /ENDIF                                                  
      /free                                                   
           oldFile = '/userfile/mystuff/sales.xls';           
           if ( unlink(%trimR(oldFile)) = -1);                
               joblog('Delete of %s failed.':%trimR(oldFile));
           else;                                              
               joblog('File %s deleted.':%trimR(oldFile));    
           endif;                                             
      /end-free                                               
      /IF DEFINED(*V6R1M0)                                    
     P dltIFS          E                                      
      /endif
Return to ClassANova.com home page.