How to rename an IFS object from RPGLE

Here is a coding example of using the RNM command with QCMDEXC in RPG to rename an IFS object.

Define fields:

0084.00 d cmdstr          s             500a   varying
0085.00 d oldFile         s             100 
0086.00 d newFile         s             100

Define Prototypes:

0110.00 D Cmd             PR                   ExtPgm('QCMDEXC') 
0111.00 D command                       200A   const 
0112.00 D length                         15P 5 const

Define Procedure Interface:


0114.00 d* Procedure Interface for this program  
0115.00 d******************************************************
0116.00 d entry           pi 
0117.00 d  pFile                        100a 


0208.00 * Rename IFS file (note: new file name does not include path) 


0209.00 c              eval oldFile = pFile 
0210.00 c              eval newFile = %subst(pFile:12:20) 
0211.00 c              eval %subst(newFile:6:1) = '1' 
0212.00 c              eval cmdstr='RNM' + 
0213.00 c                  ' OBJ(''' + %trim(oldfile) + ''')' + 
0214.00 c                  ' NEWOBJ(''' + %trim(newfile) + ''')' 
0215.00 c              callp Cmd(cmdstr:%len(cmdstr))


  
This might be a good place to add monitor and on-error just to make sure the rename worked. The file could be locked or the name of your "to file" might already exist.