User exit—%USER
Use this function to call a user exit program from an expression. This function provides flexibility when complex logic that cannot be expressed using the provided column functions is required. You can use this function to call a user exit program with input parameters.
Note: The CDC Replication Engine for Microsoft SQL Server does
not support this function. If you are using a replication engine other
than CDC Replication Engine for Db2® for
z/OS®,
you cannot use this function to call a stored procedure.
Syntax
%USER('program_name', parm1, parm2, ..., parmnParameters
- program_name
- Specifies the name of the user exit program. You must enclose values of this parameter in single quotation marks. You can write the user exit program in any high-level language. You must place an executable object for the user exit program in the CDC Replication installation directory prior to starting refresh or mirroring.
- parm1, parm2, ..., parmn
- Specify columns or literals that are passed as parameters to the user exit program (maximum 20).
Result data type
The data type of the result returned by the user exit program.
Examples
%USER(‘USERSEL1',
BRANCH) This function calls the COBOL program USERSEL1,
passing the BRANCH column as a parameter. USERSEL1 checks whether
or not BRANCH is set to '11'. If it is, then the user exit program
returns a one-byte character value of Y. Otherwise, it returns a character
value of N.
Note: The following user exit program is provided for
illustration purposes only and should be tested for all production
environments.
IDENTIFICATION DIVISION.
PROGRAM-ID. USERSEL1.
AUTHOR. IBM CORP.
INSTALLATION. IBM CORP.
DATE-COMPILED.
*******************************************************************
* Program : USERSEL1.
* ----------------
* Version: 1.0
* ----------------
* Description: SAMPLE COBOL USER ENTRY POINT PROGRAM
* ----------------
*
******************************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-AS400.
OBJECT-COMPUTER. IBM-AS400.
******************************************************************
* D A T A D I V I S I O N
******************************************************************
DATA DIVISION.
******************************************************************
* W O R K I N G S T O R A G E S E C T I O N
******************************************************************
WORKING-STORAGE SECTION.
*
01 DATATYPES COMP-4.
03 TYP-CHAR PIC S9(4) VALUE 1.
03 TYP-DATE PIC S9(4) VALUE 2.
03 TYP-FLOAT PIC S9(4) VALUE 3.
03 TYP-INTEGER PIC S9(4) VALUE 4.
03 TYP-PACKED PIC S9(4) VALUE 5.
03 TYP-TIME PIC S9(4) VALUE 6.
03 TYP-ZONED PIC S9(4) VALUE 7.
******************************************************************
* L I N K A G E S E C T I O N
******************************************************************
LINKAGE SECTION.
01 RETURN-VALUE.
03 RV-DATATYPE PIC S9(4) COMP-4.
03 RV-LENGTH PIC S9(4) COMP-4.
03 RV-DIGITS PIC S9(4) COMP-4.
03 RV-DECPLC PIC S9(4) COMP-4.
03 RV-NULLIND PIC S9(4) COMP-4.
03 RV-DTMFMT PIC X(4).
03 RV-SELECT PIC X(1).
01 PARM-1.
03 P1-DATATYPE PIC S9(4) COMP-4.
03 P1-LENGTH PIC S9(4) COMP-4.
03 P1-DIGITS PIC S9(4) COMP-4.
03 P1-DECPLC PIC S9(4) COMP-4.
03 P1-NULLIND PIC S9(4) COMP-4.
03 P1-DTMFMT PIC X(4).
03 P1-BRANCH PIC X(2).
******************************************************************
* P R O C E D U R E D I V I S I O N
******************************************************************
PROCEDURE DIVISION USING RETURN-VALUE
PARM-1.
ML-0010.
*
* This example program checks parm 1 for a value of ‘11' and if found,
* returns ‘Y', else returns ‘N'.
*
* Define the Returned Value as a 1-byte character field.
*
MOVE TYP-CHAR TO RV-DATATYPE.
MOVE 1 TO RV-LENGTH.
MOVE ZERO TO RV-DIGITS.
MOVE ZERO TO RV-DECPLC.
MOVE ZERO TO RV-NULLIND.
MOVE SPACES TO RV-DTMFMT.
*
* Test for a value of ‘11' in the first parameter.
*
IF P1-BRANCH IS EQUAL TO ‘11'
MOVE ‘Y' TO RV-SELECT
ELSE
MOVE ‘N' TO RV-SELECT.
EXIT PROGRAM.