This is a method how we can save the output of report into an CSV file.This is the new thing I learnt.First of all I would like to mention, what the requirement is and further will tell the appropriate solution for it.
REQUIREMENT is as Following:
- We have an oracle form from which we are calling an oracle report when user press the PREVIEW button.
- PARAMETER FORM
- Now if user press the PREVIEW button, first a prompt should be shown which will ask user to enter the path and name of CSV file in which user wants to save the output of called report.
- SAVE PROMPT
- When user clicks on the save button in the above picture, then a .csv file will be saved at the specified path and an oracle report will be displayed.
How it should be done:
- I used the follwing function for the save prompt to pop up, in “WHEN-BUTTON-PRESSED” trigger on the PREVIEW button: v_file_path:=GET_FILE_NAME(‘D:\’, ‘file_name1.csv’, ‘CSV Files (*.csv)|*.csv|’, NULL,SAVE_FILE, TRUE);
- Whatever path user will enter in save prompt that will be stored in variable v_file_path and an empty csv file will be created at specified path.
- The path of csv file is send as parameter to called report.
- As we are having path of excel file in which we have to export data we will use “BEFORE REPORT“ trigger of oracle report so that before running the actual report data is exported into csv file.
- As we have passed path as a parameter to report so we can use that path in “BEFORE REPORT“ trigger.
- We will use V_OUTFILE :=TEXTIO.FOPEN(FILE_PATH,’W') to open the csv file in write mode where V_OUTFILE variable’s data type is TEXT_IO.FILE_TYPE.
- And TEXT_IO.PUT_LINE(V_OUTFILE,V_OUTSTRING) in which V_OUTSTRING is any chracter string.
- Sample code is as following:
- CODE
- This will store the string in the cells,means each part of string between two commas will go in different cell.
- Donot forget to close the file using TEXT_IO.FCLOSE(v_outfile).
This was all what I used to store the data output of a report into the csv file.This was new to learn for me so i thought i should share it on blog.May be it can be helpful for someone.

