Estou utilizando o pacote DDE do Forms 5 para ler uma planilha Excel.
Eu passo o nome do arquivo através de parâmetros que o usuário informa. Quando um parâmetro é passado errado o DDE.App_Begin não vai localizar o arquivo e dá erro.
Preciso tratar este erro por exception e não estou conseguindo.
alguém já fez isso e pode me ajudar?
EXCEPTION
WHEN DDE.DDE_APP_FAILURE THEN
MESSAGE('Word não inicializou.');
WHEN DDE.DDE_PARAM_ERR THEN
MESSAGE('Um valor nullo foi passado para DDE');
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
MESSAGE('DDE não pode iniciar uma conversação');
WHEN DDE.DMLERR_NOTPROCESSED THEN
MESSAGE('Uma transação falhou');
ORACLE FORMS DDE EXAMPLE FOR MS WORD
Document ID: 9570228.61
Title: WIN: Oracle Forms DDE Example for MS Word
Creation Date: 30-November-95
Last Revision Date: 30-November-95
Revision Number: 0
Product Version: 4.X
Platform: DESKTOP
Information Type: ADVISORY
Impact: LOW
Abstract: This is an example that explains how to use DDE between
Forms4.X and MS Word.
Keywords: DDE;FORMS;WORD;DYNAMIC;DATA;EXCHANGE
------------------------------------------------------------------------
Oracle Forms DDE Example for MS Word
This bulletin gives a general overview of how to create a DDE link
between a MS Word Document and Oracle Forms 4.X. It includes the code
required in Oracle Forms to perform the DDE Link. This could be applied
to any Windows Application that supports DDE, not just MS Word. This
sample is based on using the EMP table owned by SCOTT/TIGER.
Note: Refer to the Dynamic Data Exchange Chapter 12 in the Oracle
Forms4.5 Advance Techniques Manual, or Chapter 5 in the Oracle Forms
for Windows Installation Guide Version 4.0 for more information on
Oracle Forms DDE.
Dynamic Data Exchange (DDE) is a function in MS Windows that allows
applications to communicate and exchange Data. DDE client support is
provided in Oracle Forms as a procedural option, that can be accessed
through PL/SQL procedures and triggers.
The following is a sample trigger for using DDE to an MS Word Template.
/* DECLARE VARIABLES */
DECLARE
APPID PLS_INTEGER;
CONVID PLS_INTEGER;
DOCID PLS_INTEGER;
SYS_DATE CHAR(8);
EMP_NAME CHAR(40);
/* BEGIN TRIGGER DDE SAMPLE */
BEGIN
/* SET DATE */
SELECT TO_CHAR(SYSDATE,'MM/DD/YY') INTO SYS_DATE FROM DUAL;
/* SET EMPLOYEE_NAME */
-- EMP_NAME := 'TESTING 1 2 3 4';
SELECT ENAME INTO EMP_NAME FROM EMP where job = 'PRESIDENT';
/* START WORD */
APPID := DDE.APP_BEGIN('h:\WINWORD\WINWORD.EXE',
DDE.APP_MODE_MINIMIZED);
/* INITIATE CONVERSATION WITH WORD */
CONVID := DDE.INITIATE('WINWORD','SYSTEM');
/* OPEN WORD TEMPLATE */
DDE.EXECUTE(CONVID,'[FileOpen "h:\winword\SAMPLE.DOT"]', 10000);
/* INITIATE CONVERSATION WITH WORD TEMPLATE */
DOCID := DDE.INITIATE('WINWORD','h:\winword\SAMPLE.DOT');
/* BEGIN TRANSFER TO WORD */
DDE.POKE(DOCID,'BOOKMARK1', SYS_DATE,DDE.CF_TEXT,10000);
DDE.POKE(DOCID,'BOOKMARK2', EMP_NAME,DDE.CF_TEXT,10000);
/* SAVE THE TEMPLATE */
DDE.EXECUTE(DOCID,'[FileSaveAs "f:\winword\output.doc"]', 10000);
/*END TRANSFER TO WORD */
DDE.TERMINATE(CONVID);
/* HANDLE EXCEPTIONS */
EXCEPTION
WHEN DDE.DDE_APP_FAILURE THEN
MESSAGE('WORD FOR WINDOWS CANNOT START.');
WHEN DDE.DDE_PARAM_ERR THEN
MESSAGE('A NULL VALUE WAS PASSED TO DDE');
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
MESSAGE('DDE CANNOT ESTABLISH A CONVERSATION');
WHEN DDE.DMLERR_NOTPROCESSED THEN
MESSAGE('A TRANSACTION FAILED');
/* END OF TRIGGER */
END;
CREATING A DEFAULT FORM
------------------------
1. Startup Oracle Forms Designer and create a default form.
2. Add a button through the layout editor.
3. Create a WHEN-BUTTON-PRESSED Trigger. add the code listed in this
document in the trigger.
4. Compile the trigger and generate the form.
CREATING A MS-WORD TEMPLATE
---------------------------
Once you have successfully generated the form you will need to
create a word template.
1. Startup MS Word and select the file menu then new.
2. Select template and click on the OK button.
3. Add the text and other formatting to the template.
4. Save the new template with the name sample.dot.
ADDING DDE LINKS
-----------------
Now you need to add the DDE links to Oracle Forms.
1. Place your cursor in the sample.dot template were you want a field
to be added.
2. Select the edit menu and then bookmark.
3. Create a bookmark with the name BOOKMARK1 and click on the OK
button.
4. Move your cursor to the next location that you want to link to
Oracle Forms and create another bookmark with the name BOOKMARK2.
5. Save the changes and exit MS Word.
You are now ready to run the DDE sample form. Run the form and
engage the trigger, by pressing on the button. It should then startup
MS Word and transfer the data from Oracle Forms to MS Word.
AppID PLS_INTEGER;
DOCID PLS_INTEGER;
conv_established BOOLEAN := FALSE;
V_NM_DESTINO VARCHAR2(32000);
V_DS_CLASSE VARCHAR2(32000);
V_DS_LOCAL VARCHAR2(32000);
-- para abrir o arquivo --
V_NM_DESTINO := V_NM_DIRETORIO||V_NM_ARQUIVO||'.XLS';
CONV_ESTABLISHED := FALSE;
V_DS_CLASSE := win_api_environment.read_registry('HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.xls',null, FALSE);
V_DS_LOCAL := win_api_environment.read_registry('HKEY_CLASSES_ROOT\'||V_DS_CLASSE||'\shell\open\command',null, FALSE);
AppID := DDE.App_Begin (V_DS_LOCAL,DDE.App_Mode_minimized);
WHILE NOT CONV_ESTABLISHED LOOP
BEGIN
DOCID := DDE.INITIATE('EXCEL','SYSTEM');
CONV_ESTABLISHED := TRUE;
EXCEPTION
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
CONV_ESTABLISHED := FALSE;
END;
END LOOP;
DDE.Execute(docID, '[Open("'||V_NM_DESTINO||'")]',10000);
docid := DDE.INITIATE('EXCEL',V_NM_DESTINO);
-- para ler o dado -- se o excel for em ingles, ao invez de L usa-se R(row)
DDE.Request (docID, REPLACE('L'||V_NR_LINHA||'C'||V_NR_COLUNA,' '), V_DS_DADO, DDE.Cf_Text, 100000);
--fecha o excel e o arquivo --
DDE.TERMINATE(docID);
dde.app_end(appid);
/* Establish a conversation with Excel */
/* The following loop will not end until a conversation with Excel
has been established. Therefore, it can result in a endless loop,
so use with caution. */
WHILE NOT conv_established LOOP
BEGIN
convid := DDE.INITIATE('Excel', 'Sistema');
conv_established := TRUE;
EXCEPTION
WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
conv_established := FALSE;
END; -- loop
END LOOP;
....
Mas nesse local em específico fica no looping e não sai mais, ou seja, não estabele a comunicação com o excel (DDE.INITIATE). Gostaria de saber se tenho que instalar alguma coisa da DDE no meu micro ou no servidor onde está o oracle?Alguém poderia me ajudar??
Obrigado.