Introduction
Many Forms applications utilize Text_IO to read and write data from the file system. When moving your Forms application to the Web, Text_IO works in exactly the same manner as client/server. However, you must now remember that your application is running on the application server and not the client machine.
This may infact be the behavior you desire (for example, using Text_IO to write out auditing information). However, it could be that you need Text_IO to access the machine at which the user is sitting. For example, a salesman logs onto the Forms application and wants the application to read sales data from his local machine.
WebUtil provides you the functionality to perform client side Text_IO.
Set Up
For the steps to set up WebUtil, please refer to the WebUtil Familiarization Manual available as part of the software download.
Changing code
Consider the following code:
PROCEDURE WRITE_ITEM_BLOCK (FILENAME IN VARCHAR2) IS
MYFILE TEXT_IO.FILE_TYPE;
CUR_REC NUMBER;
BEGIN
GO_BLOCK('S_ITEM');
CUR_REC := :SYSTEM.CURSOR_RECORD;
IF :SYSTEM.BLOCK_STATUS != 'NEW' THEN
FIRST_RECORD;
MYFILE := TEXT_IO.FOPEN(FILENAME, 'W');
TEXT_IO.PUTF(MYFILE,'Item_ID,Proudct_ID,Description'||CHR(10));
LOOP
TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.ITEM_ID)||',');
TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.PRODUCT_ID)||',');
TEXT_IO.PUTF(MYFILE, :S_ITEM.DESCRIPTION||',');
TEXT_IO.PUTF(MYFILE, CHR(10));
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
TEXT_IO.FCLOSE(MYFILE);
END IF;
GO_RECORD(CUR_REC);
END;
This code will go through the records of a block and output the data to a named file. To perform the same functionality, but on the client side, attatch the WebUtil object library and PL/SQL library, and replace any instance of TEXT_IO with CLIENT_TEXT_IO.
The resulting code will now work, as before, but write the file to the client machine.
PROCEDURE WRITE_ITEM_BLOCK (FILENAME IN VARCHAR2) IS
MYFILE CLIENT_TEXT_IO.FILE_TYPE;
CUR_REC NUMBER;
BEGIN
GO_BLOCK('S_ITEM');
CUR_REC := :SYSTEM.CURSOR_RECORD;
IF :SYSTEM.BLOCK_STATUS != 'NEW' THEN
FIRST_RECORD;
MYFILE := CLIENT_TEXT_IO.FOPEN(FILENAME, 'W');
CLIENT_TEXT_IO.PUTF(MYFILE,'Item_ID,Proudct_ID,Description'||CHR(10));
LOOP
CLIENT_TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.ITEM_ID)||',');
CLIENT_TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.PRODUCT_ID)||',');
CLIENT_TEXT_IO.PUTF(MYFILE, :S_ITEM.DESCRIPTION||',');
CLIENT_TEXT_IO.PUTF(MYFILE, CHR(10));
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
CLIENT_TEXT_IO.FCLOSE(MYFILE);
END IF;
GO_RECORD(CUR_REC);
END;
No comments:
Post a Comment