Midrange News for the IBM i Community

Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Delete IFS File from within RPG IV
has no ratings.
Published: 18 Feb 2011
Revised: 23 Jan 2013 - 4097 days ago
Last viewed on: 12 Apr 2024 (13836 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Delete IFS File from within RPG IV Published by: Bob Cozzi on 18 Feb 2011 view comments(1)

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() (line 27) 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.

Note that the field containing the IFS file name is VARYING (line 20). As of v5r3 this is no longer necessary if the *TRIM option is included on IFS-based prototypes (line 12).

..... /IF DEFINED(*V6R1M0)                                        
     H MAIN(DLTIFS)                                               
     H BNDDIR('QC2LE')                                            
     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:*TRIM) 
      /IF DEFINED(*V6R1M0)                                        
     P dltIFS          B                                          
     D dltIFS          PI                                         

     D oldFile         S            640A   Varying                   
      /IF NOT DEFINED(*V6R1M0)                                
     C                   EVAL      *INLR = *ON                
           oldFile = '/userfile/mystuff/sales.xls';           
           if ( unlink( oldFile ) = -1);                
               joblog('Delete of %s failed.':%trimR(oldFile));
               joblog('File %s deleted.':%trimR(oldFile));    
      /IF DEFINED(*V6R1M0)                                    
     P dltIFS          E                                      

Return to midrangenews.com home page.
Sort Ascend | Descend


(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Comment on: Delete IFS File from within RPG IV
Posted: 12 years 7 months 21 days 23 hours 43 minutes ago

Note that this is just an example and can easily be modified to delete any IFS file by adding an input parameter. The RMVLNK CL command can be used to do that so this is really just an example of how to delete IFS files within RPG IV.