Thursday, August 30, 2012

How To Create a Text File report from oracle Forms/Reports

Creating a text file and save it on server through Oracle forms:-


declare

 file_path varchar2(2000);
 V_file_str varchar2(2000);
 cursor rec1 is
 SELECT  emp_name,emp_code
  FROM employee_master;
 first_flag char :='F';
BEGIN
file_path:='D:\ORACLE-PROJECTS\files1\'||to_char(sysdate,'dd_mm_yyyy_hh-mi-ss')||'.TXT';

v_file_str:='LIST OF EMPLOYEES'||TO_CHAR(SYSDATE,'DDMMYY')||CHR(10);
SaveTextToFile(v_file_str, file_path, 'w');
             for rec in REC1          
             loop
                           v_file_str:='01'||REC.EMP_CODE||REC.EMP_NAME;
              SaveTextToFile(v_file_str, file_path, 'a');
             end loop;
ENd;

Note:-where savetexttofile is a procedure:-

PROCEDURE SaveTextToFile(p_Text in varchar2, p_FilePath in varchar2, p_mode in varchar2) IS
 v_TextFile text_io.file_type;
 e_FileOpenError exception;
BEGIN
 begin
  v_TextFile := text_io.fopen(p_FilePath, p_mode);
 exception
  when others then
    LAST_ERROR := 'Cannot open file';
   raise e_FileOpenError;
 end;

 text_io.put(v_TextFile, p_Text);

 text_io.fclose(v_TextFile); 
END;
---------------------------


creating a text file through report:-

define a key in cgicmd file

textreport: userid=system/sys@test destype=file desname='c:\test_report.txt' desformat=delimited

create a report and give the desired formatting,

In the form use the following syntax while calling the report:-

rep_url:=/*server path*/||'/reports/rwservlet?textreport&module='|report_name;
             
  WEB.SHOW_DOCUMENT(rep_url,'_blank');

Then the text file will be save in the c: directory.

No comments:

Post a Comment