Programmer's Guide to the Oracle Precompilers, 1.8 | Library |
Product |
Contents |
Index |
When called by a SQL*Forms trigger, the user exit runs, then returns a status code to SQL*Forms (refer to Figure 11 - 1). Your user exit can display messages on the SQL*Forms status line, get and put field values, manipulate Oracle data, do high-speed computations and table lookups--even log on to different databases.
Figure 11 - 1. SQL*Forms Communicating with a User Exit
User exits are harder to write and implement than SQL, PL/SQL, or SQL*Forms commands. So, you will probably use them only to do processing that is beyond the scope of SQL, PL/SQL, and SQL*Forms. Some common uses follow:
To incorporate a user exit into a form, you take the following steps:
Host variables must be named in the user exit Declare Section and must be prefixed with a colon (:) in EXEC IAF statements.
Note: Indicator variables are not allowed in EXEC IAF GET and PUT statements.
EXEC IAF GET field_name1, field_name2, ...
INTO :host_variable1, :host_variable2, ...;
where field_name can be any of the following SQL*Forms variables:
The following example shows how a user exit GETs a field value and assigns it to a host variable:
EXEC IAF GET employee.job INTO :new_job;
All field values are character strings. If it can, GET converts a field value to the datatype of the corresponding host variable. If an illegal or unsupported datatype conversion is attempted, an error is generated.
In the last example, a constant is used to specify block.field. You can also use a host string to specify block and field names, as follows:
set blkfld = 'employee.job';
EXEC IAF GET :blkfld INTO :new_job;
Unless the field is unique, the host string must contain the full block.field reference with intervening period. For example, the following usage is invalid:
set blk = 'employee';
set fld = 'job';
EXEC IAF GET :blk.:fld INTO :new_job;
You can mix explicit and stored field names in a GET statement field list, but not in a single field reference. For example, the following usage is invalid:
set fld = 'job';
EXEC IAF GET employee.:fld INTO :new_job;
EXEC IAF PUT field_name1, field_name2, ...
VALUES (:host_variable1, :host_variable2, ...);
where field_name can be any of the following SQL*Forms variables:
EXEC IAF PUT employee.number, employee.name, employee.job
VALUES (7934, 'MILLER', :new_job);
Like GET, PUT lets you use a host string to specify block and field names, as follows:
set blkfld = 'employee.job';
EXEC IAF PUT :blkfld VALUES (:new_job);
On character-mode terminals, a value PUT into a field is displayed when the user exit returns, rather than when the assignment is made, provided the field is on the current display page. On block-mode terminals, the value is displayed the next time a field is read from the device.
If a user exit changes the value of a field several times, only the last change takes effect.
USER_EXIT(user_exit_string [, error_string]);
where user_exit_string contains the name of the user exit plus optional parameters and error_string contains an error message issued by SQL*Forms if the user exit fails. For example, the following trigger command calls a user exit named LOOKUP:
USER_EXIT('LOOKUP');
Notice that the user exit string is enclosed by single (not double) quotes.
Command Line is the user exit string.
Command Line Length is the length (in characters) of the user exit string.
Error Message is the error string (failure message) if one is defined.
Error Message Length is the length of the error string.
In-Query is a Boolean value indicating whether the exit was called in normal or query mode.
However, the user exit string allows you to pass additional parameters to the user exit. For example, the following trigger command passes two parameters and an error message to the user exit LOOKUP:
USER_EXIT('LOOKUP 2025 A', 'Lookup failed');
You can use this feature to pass field names to the user exit, as the following example shows:
USER_EXIT('CONCAT firstname, lastname, address');
However, it is up to the user exit, not SQL*Forms, to parse the user exit string.
success
The user exit encountered no errors. SQL*Forms proceeds to the success label or the next step, unless the Reverse Return Code switch is set by the calling trigger step.
failure
The user exit detected an error, such as an invalid value in a field. An optional message passed by the exit appears on the message line at the bottom of the SQL*Forms screen and on the Display Error screen. SQL*Forms responds as it does to a SQL statement that affects no rows.
fatal error
The user exit detected a condition that makes further processing impossible, such as an execution error in a SQL statement. An optional error message passed by the exit appears on the SQL*Forms Display Error screen. SQL*Forms responds as it does to a fatal SQL error.
If a user exit changes the value of a field, then returns a failure or fatal error code, SQL*Forms does not discard the change. Nor does SQL*Forms discard changes when the Reverse Return Code switch is set and a success code is returned.
The syntax of the SQLIEM function call is
SQLIEM (error_message, message_length);
where error_message and message_length are character and integer variables, respectively. The Oracle Precompilers generate the appropriate external function declaration for you. You pass both parameters by reference; that is, you pass their addresses, not their values. SQLIEM is a SQL*Forms function; it cannot be called from other Oracle tools.
-- subroutine MYEXIT
EXEC SQL BEGIN DECLARE SECTION;
field1 CHARACTER(20);
field2 CHARACTER(20);
value1 CHARACTER(20);
value2 CHARACTER(20);
result_val CHARACTER(20);
EXEC SQL END DECLARE SECTION;
errmsg CHARACTER(80);
errlen INTEGER;
EXEC SQL INCLUDE SQLCA;
EXEC SQL WHENEVER SQLERROR GOTO sqlerror;
-- get field values from form
EXEC IAF GET :field1, :field2 INTO :value1, :value2;
-- manipulate values to obtain result_val
-- put result_val into form field
EXEC IAF PUT result VALUES (:result_val);
return(IAPSUCC); -- trigger step succeeded
sqlerror:
set errmsg = CONCAT('MYEXIT: ', sqlca.sqlerrm.sqlerrmc);
set errlen = LENGTH(errmsg);
sqliem(errmsg, errlen); -- pass error message to SQL*Forms
return(IAPFAIL); -- trigger step failed
For a complete host-language example, see your host -language supplement.
For instructions on compiling a user exit, see your system-specific Oracle manuals.
IAPXTB is derived from a database table, also named IAPXTB. You can modify the database table by running the GENXTB form on the operating system command line, as follows:
RUNFORM GENXTB username/password
A form is displayed that allows you to enter the following information for each user exit you define:
GENXTB username/password outfile
where outfile is the name you give the Assembler or source program that GENXTB creates.
To produce a new executable copy of IAP, link your user exit object module, the standard IAP modules, the IAPXIT module, and any modules needed from the Oracle and host-language link libraries. The details of linking are system-dependent, so check your system-specific Oracle manuals.
SQL*Forms converts the name of a user exit to upper case before searching for the exit. Therefore, the exit name must be in upper case in your source code if your host language is case-sensitive.
The name of the user exit entry point in the source code becomes the name of the user exit itself. The exit name must be a valid file name for your host language and operating system.
Besides EXEC SQL, EXEC ORACLE, and host language statements, you can use the following EXEC TOOLS statements to write an Oracle Forms user exit:
Note: COBOL and FORTRAN do not have a pointer datatype, so you cannot use the SET CONTEXT and GET CONTEXT statements in a Pro*COBOL or Pro*FORTRAN program.
To code the EXEC TOOLS SET statement, you use the syntax
EXEC TOOLS SET form_variable[, ...]
VALUES ({:host_variable[:indicator] | constant}[, ...]);
where form_variable is an Oracle Forms field, parameter, system variable, or global variable, or a host variable (prefixed with a colon) containing the name of one of the foregoing items.
In the following Pro*C example, your user exit passes an employee name (with optional indicator) to Oracle Forms:
EXEC SQL BEGIN DECLARE SECTION;
...
char ename[20];
short ename_ind;
EXEC SQL END DECLARE SECTION;
...
strcpy(ename, "MILLER");
ename_ind = 0;
EXEC TOOLS SET emp.ename VALUES (:ename:ename_ind);
In this example, emp.ename is an Oracle Forms block.field.
To code the EXEC TOOLS GET statement, you use the syntax
EXEC TOOLS GET form_variable[, ...]
INTO :host_variable[:indicator][, ...];
where form_variable is an Oracle Forms field, parameter, system variable, or global variable, or a host variable containing the name of one of the foregoing items.
In the following example, Oracle Forms passes an employee name from the block.field emp.ename to your user exit:
EXEC SQL BEGIN DECLARE SECTION;
...
char ename[20];
EXEC SQL END DECLARE SECTION;
...
EXEC TOOLS GET emp.ename INTO :ename;
To code the EXEC TOOLS SET CONTEXT statement, use the syntax
EXEC TOOLS SET CONTEXT :host_pointer_variable
[IDENTIFIED] BY context_name;
where the optional keyword IDENTIFIED can be used to improve readability and context_name is an undeclared identifier or a character host variable that names the context area.
In the following example, your user exit saves context information for later use:
EXEC SQL BEGIN DECLARE SECTION;
...
char context1[30];
EXEC SQL END DECLARE SECTION;
...
strcpy(context1, "This is context1");
EXEC TOOLS SET CONTEXT :context1 BY my_app1;
In this example, the context name my_app1 is an undeclared identifier. Note that in C, when a char array is used as an argument, the array name is synonymous with a pointer to that array.
To code the EXEC TOOLS GET CONTEXT statement, use the syntax
EXEC TOOLS GET CONTEXT context_name INTO :host_pointer_variable;
where context_name is an undeclared identifier or a character host variable that names the context area.
In the following Pro*C example, your user exit retrieves a pointer to context information saved earlier:
EXEC SQL BEGIN DECLARE SECTION;
...
char *ctx_ptr;
EXEC SQL END DECLARE SECTION;
...
EXEC TOOLS GET CONTEXT my_app1 INTO :ctx_ptr;
In this example, the context name my_app1 is an undeclared identifier.
To code the EXEC TOOLS MESSAGE statement, you use the syntax
EXEC TOOLS MESSAGE message_text [severity_code];
where message_text is a quoted string or a character host variable, and the optional severity_code is an integer constant or host variable. The MESSAGE statement does not accept indicator variables.
In the following Pro*C example, your user exit passes an error message and severity code to Oracle Forms:
EXEC TOOLS MESSAGE 'Bad field name! Please reenter.' 15;
Prev Next |
Copyright © 1996 Oracle Corporation. All Rights Reserved. |
Library |
Product |
Contents |
Index |