KEMBAR78
Report To Excel | PDF | Microsoft Excel | Comma Separated Values
0% found this document useful (0 votes)
20 views3 pages

Report To Excel

This document provides a guide on how to run Oracle Reports to export data to Excel in a delimited format using the rwrun60 command. It includes two implementation methods: one using the HOST command in Oracle Forms 6i and another using WebUtil, along with important considerations such as file path permissions and output format. The document also offers enhanced error handling and troubleshooting tips for successful report execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Report To Excel

This document provides a guide on how to run Oracle Reports to export data to Excel in a delimited format using the rwrun60 command. It includes two implementation methods: one using the HOST command in Oracle Forms 6i and another using WebUtil, along with important considerations such as file path permissions and output format. The document also offers enhanced error handling and troubleshooting tips for successful report execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

# Running Oracle Reports to Export Data to Excel (DELIMITED Format) Using RWRUN60

The command you've provided (`rwrun60 report=myreport.rdf destype=file desname="C:\


data.xls" desformat=DELIMITED`) is a command line instruction to execute an Oracle
Report and export the output as a delimited file (typically CSV) with an .xls
extension. Here's a comprehensive explanation and implementation guide:

## Understanding the Command Components

```
rwrun60 // Oracle Reports runtime executable
report=myreport.rdf // The report definition file to run
destype=file // Output destination type (file)
desname="C:\data.xls" // Output file path and name
desformat=DELIMITED // Output format (comma-delimited)
```

## How to Implement This in Oracle Forms 6i

### Method 1: Using HOST Command (Direct Execution)

```plsql
PROCEDURE run_report_to_excel IS
v_cmd VARCHAR2(2000);
v_ret NUMBER;
BEGIN
-- Build the complete command with connection details
v_cmd := 'rwrun60 userid=' || GET_APPLICATION_PROPERTY(USERNAME) || '/' ||
GET_APPLICATION_PROPERTY(PASSWORD) || '@' ||
GET_APPLICATION_PROPERTY(CONNECT_STRING) ||
' batch=yes module=myreport.rdf ' ||
'destype=file desname="C:\data.xls" desformat=DELIMITED';

-- Add any required parameters


v_cmd := v_cmd || ' PARAMFORM=NO P_EMPNO=' || :block.empno;

-- Execute the command


v_ret := HOST(v_cmd, NO_SCREEN);

-- Check return status


IF v_ret = 0 THEN
MESSAGE('Report executed successfully. File created: C:\data.xls');
-- Optional: Open the file automatically
CLIENT_HOST('cmd /c start excel "C:\data.xls"', FALSE);
ELSE
MESSAGE('Report execution failed with return code: ' || v_ret);
END IF;
EXCEPTION
WHEN OTHERS THEN
MESSAGE('Error: ' || SQLERRM);
END;
```

### Method 2: Using WebUtil (If Installed)

```plsql
PROCEDURE run_report_via_webutil IS
v_cmd VARCHAR2(2000);
v_ret NUMBER;
BEGIN
-- Build the command (similar to above)
v_cmd := 'rwrun60 userid=scott/tiger@orcl batch=yes module=myreport.rdf ' ||
'destype=file desname="C:\data.xls" desformat=DELIMITED';

-- Execute using WebUtil


v_ret := CLIENT_HOST(v_cmd);

IF v_ret = 0 THEN
MESSAGE('Excel file created successfully');
ELSE
MESSAGE('Error creating Excel file');
END IF;
END;
```

## Important Considerations

1. **File Path Permissions**:


- Ensure the Oracle process has write permissions to C:\
- Consider using a more appropriate directory like C:\TEMP\

2. **Report Location**:
- The myreport.rdf file must be accessible to the Reports runtime
- Either place it in the REPORTS_PATH or specify full path

3. **Output Format**:
- DELIMITED creates a CSV file (not a true Excel file)
- For actual Excel format, use `desformat=SPREADSHEET` (requires Excel driver)

4. **Common Issues**:
```plsql
-- Troubleshooting additions to your command:
v_cmd := v_cmd || ' debug=yes log="C:\report.log"'; // Generate log file
v_cmd := v_cmd || ' trace=yes'; // Enable tracing
```

5. **Alternative for True Excel Format**:


```plsql
v_cmd := 'rwrun60 userid=scott/tiger@orcl module=myreport.rdf ' ||
'destype=file desname="C:\data.xls" desformat=SPREADSHEET ' ||
'batch=yes';
```

## Enhanced Version with Error Handling

```plsql
PROCEDURE export_to_excel_enhanced IS
v_cmd VARCHAR2(3000);
v_ret NUMBER;
v_dir VARCHAR2(256) := 'C:\TEMP\'; -- Better directory choice
BEGIN
-- Verify directory exists using WebUtil
-- (Alternative: Use Java in Forms if WebUtil not available)

-- Build command with timestamped filename


v_cmd := 'rwrun60 userid=' || GET_APPLICATION_PROPERTY(USERNAME) || '/' ||
GET_APPLICATION_PROPERTY(PASSWORD) || '@' ||
GET_APPLICATION_PROPERTY(CONNECT_STRING) ||
' batch=yes module=myreport.rdf ' ||
'destype=file desname="' || v_dir || 'data_' ||
TO_CHAR(SYSDATE, 'YYYYMMDD_HH24MISS') || '.xls" ' ||
'desformat=DELIMITED PARAMFORM=NO';

-- Add dynamic parameters


IF :block.param1 IS NOT NULL THEN
v_cmd := v_cmd || ' P_PARAM1="' || :block.param1 || '"';
END IF;

-- Execute
v_ret := HOST(v_cmd, NO_SCREEN);

-- Handle results
IF v_ret = 0 THEN
MESSAGE('Excel file created successfully in ' || v_dir);
ELSE
RAISE FORM_TRIGGER_FAILURE;
END IF;
EXCEPTION
WHEN OTHERS THEN
MESSAGE('Error exporting to Excel. Code: ' || v_ret || ' - ' || SQLERRM);
-- Log error to file if needed
END;
```

You might also like