In many Oracle Forms applications, there is a need to write data or export information directly to the client’s local machine. Traditionally, Oracle Forms operates on the application server, meaning file operations happen on the server by default. However, with the help of WebUtil, developers can bridge this gap and perform file operations on the client side.
This tutorial explains how to write files at the client side in Oracle Forms using WebUtil. You will learn about the setup requirements, built-in procedures, and practical coding examples that demonstrate how to export data into text or CSV files on the user’s system.
A. Why Use WebUtil for Client-Side File Writing?
By default, the UTL_FILE package or standard Oracle Forms operations only interact with the server-side filesystem. But in real-world scenarios, end users often want the output saved on their local desktops or laptops. WebUtil enables this functionality by extending Forms’ capabilities with Java libraries.
Key reasons to use WebUtil:
- Write files directly to the client machine (Desktop, Documents, etc.).
- Export query results or reports as text, CSV, or XML.
- Simplify user experience by avoiding manual downloads from server.
- Maintain security while allowing controlled client-side operations.
B. WebUtil Setup Requirements
Before writing files on the client side, ensure that WebUtil is correctly configured:
- Install WebUtil
- Copy the
webutil.plllibrary into your Oracle Forms library folder. - Attach and compile it in your form.
- Copy the
- Grant Required Permissions
- Ensure that the
frmwebutil.jaris signed and available in theforms/javadirectory. - Configure
formsweb.cfgto load WebUtil.
- Ensure that the
- Test WebUtil
- Run the
webutil_demo.fmbprovided with Oracle Forms to confirm that client-side operations are enabled.
- Run the
C. Writing Files at Client Side Using WebUtil
WebUtil provides the CLIENT_TEXT_IO package, which mirrors the standard TEXT_IO package but works on the client machine instead of the server.
C.1 Opening a File
DECLARE
v_file CLIENT_TEXT_IO.FILE_TYPE;
BEGIN
v_file := CLIENT_TEXT_IO.FOPEN('C:\Users\Public\Documents\test.txt', 'w');
END;
- The first parameter is the full client-side file path.
- The second parameter is the mode:
'w'= write'a'= append'r'= read
C.2 Writing Content to the File
DECLARE
v_file CLIENT_TEXT_IO.FILE_TYPE;
BEGIN
v_file := CLIENT_TEXT_IO.FOPEN('C:\Users\Public\Documents\employee.txt', 'w');
CLIENT_TEXT_IO.PUT_LINE(v_file, 'Employee Report');
CLIENT_TEXT_IO.PUT_LINE(v_file, '----------------');
CLIENT_TEXT_IO.PUT_LINE(v_file, 'ID, Name, Department');
CLIENT_TEXT_IO.PUT_LINE(v_file, '101, John Smith, Finance');
CLIENT_TEXT_IO.PUT_LINE(v_file, '102, Mary Adams, IT');
CLIENT_TEXT_IO.FCLOSE(v_file);
END;
Explanation:
CLIENT_TEXT_IO.PUT_LINEwrites a line of text into the file.- Always close the file with
CLIENT_TEXT_IO.FCLOSEto avoid memory leaks.
C.3 Appending Data
If you want to add new content without overwriting the file:
DECLARE
v_file CLIENT_TEXT_IO.FILE_TYPE;
BEGIN
v_file := CLIENT_TEXT_IO.FOPEN('C:\Users\Public\Documents\employee.txt', 'a');
CLIENT_TEXT_IO.PUT_LINE(v_file, '103, David Miller, HR');
CLIENT_TEXT_IO.FCLOSE(v_file);
END;
C.4 Writing Data Dynamically from a Table
Here’s an example that fetches employee data from a database table and writes it into a CSV file on the client machine:
DECLARE
v_file CLIENT_TEXT_IO.FILE_TYPE;
CURSOR c_emp IS
SELECT empno, ename, deptno
FROM emp;
BEGIN
v_file := CLIENT_TEXT_IO.FOPEN('C:\Users\Public\Documents\employees.csv', 'w');
-- Write header row
CLIENT_TEXT_IO.PUT_LINE(v_file, 'Employee No,Employee Name,Department No');
-- Write data rows
FOR rec IN c_emp LOOP
CLIENT_TEXT_IO.PUT_LINE(v_file,
rec.empno || ',' || rec.ename || ',' || rec.deptno);
END LOOP;
CLIENT_TEXT_IO.FCLOSE(v_file);
END;
This example will create a well-formatted CSV file that can be opened directly in Excel.
D. Error Handling in Client File Writing
Always include error handling when working with WebUtil, since client access can be restricted:
BEGIN
DECLARE
v_file CLIENT_TEXT_IO.FILE_TYPE;
BEGIN
v_file := CLIENT_TEXT_IO.FOPEN('C:\Temp\output.txt', 'w');
CLIENT_TEXT_IO.PUT_LINE(v_file, 'Testing WebUtil Client Write');
CLIENT_TEXT_IO.FCLOSE(v_file);
EXCEPTION
WHEN OTHERS THEN
MESSAGE('Error while writing file: ' || SQLERRM);
RAISE;
END;
END;
This ensures that users receive meaningful error messages if file writing fails due to permissions or incorrect paths.
E. Best Practices
To make your implementation reliable and user-friendly, follow these best practices:
- Allow User to Choose Path – Use
CLIENT_GET_FILE_NAMEto let users select file location interactively. - Check File Permissions – Ensure the client user has write access to the target directory.
- Always Close Files – Use
CLIENT_TEXT_IO.FCLOSEafter writing to prevent corruption. - Use Try-Catch Blocks – Handle errors gracefully and inform users clearly.
- Export in Common Formats – Prefer
.txtor.csvfor easy accessibility.
Conclusion
Writing files at the client side in Oracle Forms is made possible with WebUtil’s CLIENT_TEXT_IO package. Instead of restricting file operations to the server, developers can allow users to save reports, data extracts, or logs directly on their local machine. By following the examples in this tutorial, you can implement flexible client-side file writing in your Oracle Forms applications with ease.
This approach improves usability, reduces server dependency, and provides a modern touch to traditional Oracle Forms systems.

