FND_FILE: PL/SQL File I/O

The FND_FILE package contains procedures to write text to log and output files. These procedures are supported in all types of concurrent programs.

For testing and debugging, you can use the procedures FND_FILE.PUT_NAMES and FND_FILE.CLOSE. Note that these two procedures should not be called from a concurrent program.

FND_FILE supports a maximum buffer line size of 32K for both log and output files.

Attention: This package is not designed for generic PL/SQL text I/O, but rather only for writing to request log and output files.

See: PL/SQL File I/O Processing

FND_FILE.PUT

Summary
procedure FND_FILE.PUT

 (which  IN NUMBER,
  buff	 IN VARCHAR2);
Description Use this procedure to write text to a file (without a new line character). Multiple calls to FND_FILE.PUT will produce concatenated text. Typically used with FND_FILE.NEW_LINE.

Arguments (input)

which Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT.
buff Text to write.

FND_FILE.PUT_LINE

Summary
procedure FND_FILE.PUT_LINE
 (which	IN NUMBER,
  buff	IN	VARCHAR2);
Description Use this procedure to write a line of text to a file (followed by a new line character). You will use this utility most often.

Arguments (input)

which Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT.
buff Text to write.

Example

Using Message Dictionary to retrieve a message already set up on the server and putting it in the log file (allows the log file to contain a translated message):

 FND_FILE.PUT_LINE( FND_FILE.LOG, fnd_message.get );

Putting a line of text in the log file directly (message cannot be translated because it is hardcoded in English; not recommended):

 fnd_file.put_line(FND_FILE.LOG,'Warning: Employee '||
                     l_log_employee_name||' ('||
                     l_log_employee_num ||
                          ') does not have a manager.');

FND_FILE.NEW_LINE

Summary
procedure FND_FILE.NEW_LINE
  (which	IN NUMBER,
	 LINES 	IN NATURAL := 1);
Description Use this procedure to write line terminators (new line characters) to a file.

Arguments (input)

which Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT.
lines Number of line terminators to write.

Example

To write two new line characters:

 fnd_file.new_line(FND_FILE.LOG,2);

FND_FILE.PUT_NAMES

Summary
procedure FND_FILE.PUT_NAMES
 	(p_log IN VARCHAR2,
   p_out IN VARCHAR2,
  (p_dir IN VARCHAR2);
Description Sets the temporary log and out filenames and the temp directory to the user-specified values. DIR must be a directory to which the database can write. FND_FILE.PUT_NAMES should be called before calling any other FND_FILE function, and only once per session.

Attention: FND_FILE.PUT_NAMES is meant for testing and debugging from SQL*Plus; it does nothing if called from a concurrent program.

BEGIN
	fnd_file.put_names('test.log', 'test.out',
		'/local/db/8.0.4/db-temp-dir/'); 	
	fnd_file.put_line(fnd_file.output,'Called stored 			
procedure'); 
	/* Some logic here... */ 
	fnd_file.put_line(fnd_file.output, 'Reached point A'); 
	/* More logic, etc... */ 
	fnd_file.close;
END; 

Arguments (input)

p_log Temporary log filename.
p_out Temporary output filename.
p_dir Temporary directory name.

Example

BEGIN
 fnd_file.put_names('test.log', 'test.out',
  '/local/db/8.0.4/db-temp-dir/'); 
 fnd_file.put_line(fnd_file.output,'Called stored  
procedure'); 
 /* Some logic here... */ 
 fnd_file.put_line(fnd_file.output, 'Reached point A'); 
 /* More logic, etc... */ 
 fnd_file.close;
END; 

FND_FILE.CLOSE

Summary
procedure FND_FILE.CLOSE;
Description Use this procedure to close open files.

Attention: Use FND_FILE.CLOSE only in command lines sessions. FND_FILE.CLOSE should not be called from a concurrent program.

Example

BEGIN
 fnd_file.put_names('test.log', 'test.out',
  '/local/db/8.0.4/db-temp-dir/');    fnd_file.put_line(fnd_file.output,'Called stored 
procedure'); 
 /* Some logic here... */ 
 fnd_file.put_line(fnd_file.output, 'Reached point A'); 
 /* More logic, etc... */ 
 fnd_file.close;
END; 

Error Handling

The FND_FILE package can raise one exception, FND_FILE.UTL_FILE_ERROR, which is raised to indicate an UTL_FILE error condition. Specifically, the procedures FND_FILE.PUT, FND_FILE.PUT_LINE and FND_FILE.NEW_LINE can raise FND_FILE.UTL_FILE_ERROR if there is an error. In addition to this package exception, FND_FILE can also raise predefined PL/SQL exceptions such as NO_DATA_FOUND or VALUE_ERROR.

FND_FILE will raise a UTL_FILE_ERROR if it is not able to open or write to a temporary file. It is up to the concurrent program to error out or complete normally, after the FND_FILE.UTL_FILE_ERROR exception is raised. FND_FILE keeps the translated message in the message stack before raising the UTL_FILE_ERROR exception. Developers can get the message for FND_FILE errors and use it as a Request Completion text. It is up to the caller to get the message from the message stack by using the FND_MESSAGE routine within an exception handler.

The concurrent manager will keep all the temporary file creation errors in the request log file.