Take advantage of this simple IFS file access utility.
Do you have an application that reads a data file from the IFS? This utility will allow your application to prompt the user to select the file to be processed. The utility is made up of an RPGLE program (SELECTSTMF) and a display file (SLCTSTMFFM). Figure 1 shows the main screen for SELECTSTMF.
Figure 1: Here's your main screen.
The user has two available options. Option 1 is used to identify the file name to be passed back to the caller or to select a subfolder when multiple folders exist in the current path. To navigate back to the parent folder, use option 1 on the subfile record that displays an object link of "[parent folder]" as shown in Figure 2.
Figure 2: Navigate to the parent folder.
A user can also use the option 5 to display additional information about a given file on the IFS. Figure 3 shows the results of option 5.
Figure 3: Use option 5 to display file information.
The utility has three parameters. The first parameter identifies the initial folder displayed to the user. The second parameter is used to identify whether or not the user should be allowed to navigate to subfolders from the initial folder. This value is specified as a value of Y or N. The third parameter is used to pass the full path to the selected file back to the caller.
The example below shows calling the utility from a CL program, starting at the home folder and allowing subfolder navigation:
chgvar &strPath value('/home')
chgvar &rtnFile value(' ')
call selectstmf parm(&strPath 'Y' &rtnFile)
The RPG program used by this utility calls the C language IFS functions OPENDIR to open each folder, READDIR to read the contents of that folder, and CLOSEDIR to close the folder when it's no longer needed.
To download the source code for this utility, click here.