Writing exits for EGL access of DB2

You can write exit code that runs as your application writes data to or retrieves data from a DB2 database.

The purpose of each exit is to format or change the value of the CHAR-type values that correspond to Date, Time, and Timestamp columns. The exits are particularly useful if you cannot fulfill your intent by using another mechanism such as JBDC driver properties or DB2 precompiler options.

Six exits are available:

On input to the database, the content of the host variable is unaffected; only the value sent to the database column is changed. On output, the content of the host variable is changed, but the column value is unaffected.

You write the exit code for use with data-access code that is generated to COBOL or Java:

The exits that are delivered are templates that have no effect.

Enabling the user exit by including a sqlDataCode value

At run time, exit code is invoked only for a host variable that is declared with a specific value for the sqlDataCode property. Here is an example Record part that includes the property in several fields:
Record TstabN type SQLRecord
   {tableNames = [["ME.MYTABLE"]], fieldsMatchColumns = yes}
   10 TS2 char(26)  	{column="TS2", isSqlNullable=yes, sqlDataCode=392};
   10 TS1 char(26)  	{column="TS1", isSqlNullable=yes, sqlDataCode=392};
   10 DATE1 char(10)	{column="DATE1", isSqlNullable=yes, sqlDataCode=384};
   10 TIME1 char(8) 	{column="TIME1", isSqlNullable=yes, sqlDataCode=388};
end
Fields outside of an SQL record also might be used as host variables, as suggested in the following example:
dataitem tstype char(26) {sqlDataCode=392} end
dataitem datetype char(10) {sqlDataCode=384} end
dataitem timetype char(8) {sqlDataCode=388} end

Any of the following sqlDataCode values causes an exit invocation:

sqlDataCode values Nullable SQL column type
384

385

YES

NO

DATE
388

389

YES

NO

TIME
392

393

YES

NO

TIMESTAMP

You can set a preference so that use of the EGL SQL retrieve feature automatically places the sqlDataCode values in a Record part that is created for you. For details, see "Setting preferences for SQL retrieve."

The exit for a specific field is not invoked during database input when the field is null, or during database output when the column is null.


Feedback