CREATE QSUB command (unidirectional replication)

Use the CREATE QSUB command to create a Q subscription that maps a source table to a target table. For Classic replication, a Q subscription maps a source table or view in the Classic metadata catalog to a target table.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CREATE QSUB--+-------------+--+-------------------------+---->
                '-SUBTYPE-- U '  '-USING REPLQMAP--mapname-'   

   .-,---------------------------------------------------------------------.   
   V                                                                       |   
>----(--+-------------------------+--| src-clause |--+----------------+--)-+-><
        '-| subname-qmap-clause |-'                  '-| trg-clause |-'        

subname-qmap-clause

|--+------------------+--+---------------------+--+-------------------+--|
   '-SUBNAME -subname-'  '-DESC--"description"-'  '-REPLQMAP -mapname-'   

src-clause

|--+-+---------------+--source_name------------------------------------+-->
   | '-source_owner.-'                                                 |   
   +-+-SRC OWNER LIKE--"predicate1"--+-----------------------------+-+-+   
   | |                               '-SRC NAME LIKE--"predicate2"-' | |   
   | '-SRC NAME LIKE--"predicate"------------------------------------' |   
   '-SRC ALL-----------------------------------------------------------'   

>--+-------------------------+----------------------------------|
   '-OPTIONS--| opt-clause |-'   

opt-clause

|--+--------------------------------------+--------------------->
   '-SEARCH CONDITION--"search_condition"-'   

>--+--------------------------+--+-----------------------+------>
   |                   .- N-. |  |                 .-I-. |   
   '-ALL CHANGED ROWS--+-Y--+-'  '-HAS LOAD PHASE--+-E-+-'   
                                                   '-N-'     

>--+---------------------+--+----------------------+------------>
   |               .-W-. |  '-SPILL_MODELQ--"name"-'   
   '-CAPTURE_LOAD--+-R-+-'                             

>--+-------------------------+---------------------------------->
   |                   .-N-. |   
   '-SUPPRESS DELETES--+-Y-+-'   

>--+-----------------------------+------------------------------>
   |                       .-Y-. |   
   '-REPLICATE ADD COLUMN--+-N-+-'   

>--+--------------------------------------+--------------------->
   '-CHANGE CONDITION--"change_condition"-'   

>--+------------------------------+----------------------------->
   |                      .-YES-. |   
   '-START AUTOMATICALLY--+-NO--+-'   

>--+---------------------------------------------------------+--|
   '-IGNORE--+----------+--+-----------------+--+----------+-'   
             '-TRIGGERS-'  '-CASCADE DELETES-'  '-SET NULL-'     

trg-clause

|--+--------------------------------------------+--------------->
   '-+-| new-target-options-clause |----------+-'   
     '-EXIST--+-| target-options-clause |---+-'     
              '-| nickname-options-clause |-'       

>--+---------------------------------------------------------------------------+-->
   '-TYPE--+-+-+-USERTABLE-+--+----------------+-+--| targetcolumns-clause |-+-'   
           | | '-NICKNAME--'  '-WITH LOGMARKER-' |                           |     
           | '-STOREDPROC------------------------'                           |     
           '-CCD--+----------------+--+-------------------------------+------'     
                  '-| ccd-clause |-'  '-MANAGE TARGET CCD--| action |-'            

>--+--------------------------------------------------------------+-->
   |                                      .-,---------------.     |   
   |                                      V                 |     |   
   '-KEYS--+-----------------------+-- (----keyname--+----+-+-- )-'   
           +-indexowner.indexname--+                 +- + +           
           '-NAMING PREFIX--prefix-'                 '- - '           

>--+---------------------------------------+-------------------->
   '-ZOS INDEX CREATE USING PROFILE--pname-'   

>--+-----------------------------------------------------------------+-->
   +-NICKNAME--+-owner.nickname--------+-----------------------------+   
   |           '-NAMING PREFIX--prefix-'                             |   
   '-NEW NICKNAME RMT SERVERNAME--srvname--+-owner.nickname--------+-'   
                                           '-NAMING PREFIX--prefix-'     

>--+----------------------+--+------------------------+--------->
   |                .-K-. |  |                  .-I-. |   
   '-CONFLICT RULE--+-C-+-'  '-CONFLICT ACTION--+-F-+-'   
                    '-A-'                       +-D-+     
                                                +-S-+     
                                                '-Q-'     

>--+---------------------+--+--------------------------+-------->
   |               .-Q-. |  '-OKSQLSTATES--"sqlstates"-'   
   '-ERROR ACTION--+-S-+-'                                 
                   +-D-+                                   
                   '-B-'                                   

>--+-----------------------------------------------+------------>
   '-LOAD TYPE--+-0-+--+-------------------------+-'   
                +-1-+  |             .-REPLACE-. |     
                +-2-+  '-EXIST DATA--+-APPEND--+-'     
                +-3-+                                  
                +-4-+                                  
                '-5-'                                  

>--+-------------------+----------------------------------------|
   '-| period-clause |-'   

new-target-options-clause

|--| target-options-clause |--+--------------------------------+--|
                              '-| table-space-options-clause |-'   

target-options-clause

|----TARGET--+---------------------------------+---------------->
             +-NAME--+----------+--target_name-+     
             |       '-owner--.-'              |     
             '-NAMING PREFIX--prefix-----------'     

>--+---------------------------------------+-------------------->
   '-TABLE OWNER-+-target_owner----------+-'   
                 +-NAMING PREFIX--prefix-+     
                 +-SAME AS SOURCE--------+     
                 '-SAME AS USERID--------'     

>--+---------------------------------------+-------------------->
   '-TABLE NAME--+-target_name-----------+-'   
                 +-NAMING PREFIX--prefix-+     
                 '-SAME AS SOURCE--------'     

>--+---------------------------+--------------------------------|
   '-FEDERATED--| fed-clause |-'   

table-space-options-clause

|--+------------------------------------------------------------------+--|
   '-IN--+----------+--+-tsname----------------+--+-----------------+-'   
         '-DB--name-'  '-NAMING PREFIX--prefix-'  '-| prof-clause |-'     

nickname-options-clause

|--NICKNAME--| fed-clause |-------------------------------------|

fed-clause

|--+------------------------+--nickname target name-------------|
   '-nickname target owner.-'                         

ccd-clause

|--+--------------------+--+-------------------+---------------->
   '-CONDENSED--+-ON--+-'  '-COMPLETE--+-ON--+-'   
                '-OFF-'                '-OFF-'     

>--+--------------------------------------+--------------------->
   '-WITH UOW COLS--+-ALL---------------+-'   
                    |    .-,-------.    |     
                    |    V         |    |     
                    '-(----colname-+--)-'     

>--+--------------------------+--+-----------------------+------|
   '-| targetcolumns-clause |-'  '-| ccdoptions-clause |-'   

prof-clause

|--+----------------------------------+-------------------------|
   '-CREATE--+----------------------+-'   
             '-USING PROFILE--pname-'     

targetcolumns-clause

|--TRGCOLS--+-ALL---------------------------------------------+-->
            |              .-,--------------------------.     |   
            |              V                            |     |   
            +-INCLUDE-- (----trgcolname--+------------+-+-- )-+   
            |                            '-srccolname-'       |   
            |              .-,----------.                     |   
            |              V            |                     |   
            '-EXCLUDE-- (----trgcolname-+-- )-----------------'   

>--+--------------------------------------------------------------------------+--|
   |                .-,--------------------------------.                      |   
   |                V                                  |     .-VALIDATE YES-. |   
   '-EXPRESSION--(----"expression"--TARGET--trgcolname-+--)--+--------------+-'   
                                                             '-VALIDATE NO--'     

ccdoptions-clause

|--BEFORE IMAGE COLUMNS--+-------------+------------------------>
                         '-PREFIX--"X"-'   

   .-ALL--+-------------------------------------------------+-------.   
   |      |          .-,-------------------------------.    |       |   
   |      |          V                                 |    |       |   
   |      '-COLS--(----AFTER--aftcols--BEFORE--befcols-+--)-'       |   
   |             .-,-------------------------------------------.    |   
   |             V                                             |    |   
>--+-INCLUDE--(----AFTER--aftincludes--+---------------------+-+--)-+--|
   |                                   '-BEFORE--befincludes-'      |   
   '-FOR KEY COLS ONLY----------------------------------------------'   

period-clause

|--PERIOD--+-ALL-------------------------+--| history-table-clause |--|
           |    .-,-----------------.    |                             
           |    V                   |    |                             
           '-(----+-SYSTEM_TIME---+-+--)-'                             
                  '-BUSINESS_TIME-'                                    

history-table-clause

                    .-EXIST------------------------------------.   
|--INCLUDE HISTORY--+-+--------------------------------------+-+--|
                      '-| new-history-table-options-clause |-'     

new-history-table-options-clause

|--HIST_TARGET NAME--hist_target_name--| table-space-options-clause |--|

action-clause

|--+------------------------------------------+-----------------|
   +-CREATE SQL REGISTRATION------------------+   
   '-ALTER SQL REGISTRATION FOR Q REPLICATION-'   

Parameters

SUBTYPE U
Specifies unidirectional replication.
USING REPLQMAP mapname
Specifies the name of the replication queue map that is used by all of the Q subscriptions in this command. This is the replication queue map that will be used by all of the Q subscriptions in a mass scenario, or if replication queue maps are not specified with the parenthesis for each Q subscription.

subname-qmap-clause:

SUBNAME subname
Specifies the name of the Q subscription.
DESC "description"
Specifies a description of the Q subscription.
REPLQMAP mapname
Specifies the name of the replication queue map for the Q subscription.

src-clause:

source_owner.source_name
Specifies the source table's schema and name.
SRC OWNER LIKE "predicate1"
Specify to choose all tables with a schema that matches the expression in the LIKE statement. The following example shows a LIKE statement:
CREATE QSUB USING REPLQMAP ABCDPUBQMAP 
(SRC OWNER LIKE "ASN%");

CREATE QSUB USING REPLQMAP ABCDPUBQMAP 
(SRC OWNER LIKE "JDOE" SRC NAME LIKE "%TAB%"); 
SRC NAME LIKE
Specify to choose all tables with a name that matches the expression in the LIKE statement. The following example shows a LIKE statement:
CREATE QSUB USING REPLQMAP ABCDPUBQMAP 
(SRC OWNER LIKE "ASN%");

CREATE QSUB USING REPLQMAP ABCDPUBQMAP 
(SRC OWNER LIKE "JDOE" SRC NAME LIKE "%TAB%"); 
SRC ALL
Specify to choose all tables that exist on the source server. For DB2® sources, this excludes catalog views.

opt-clause:

SEARCH CONDITION "search_condition"
Specifies a search condition for filtering changes to replicate or publish. You cannot use this parameter with Classic replication. The change is not sent if the predicate is false. "search_condition" is an annotated select WHERE clause that must contain a colon before the column names of the table to be replicated. The following example shows a WHERE clause:
CREATE QSUB USING REPLQMAP ASNMAP
(SUBNAME mysubname ALLTYPE1 OPTIONS SEARCH CONDITION
"WHERE :MYKEY > 1000")
ALL CHANGED ROWS
Specifies the data sending option.
N (default)
Send a row only if a subscribed column in the source table changes.
Y
Send a row when any column in the source table changes.
HAS LOAD PHASE
Specifies whether the target table for the Q subscription will be loaded with data from the source.
I (default)
Specifies an automatic load. The Q Apply program loads the target. The load method depends on the LOAD TYPE keyword. This parameter is not valid for Q subscriptions that specify stored procedures as targets.
E
Specifies a manual load. An application other than the Q Apply program loads the target. In this case, you use the LOADDONE command to indicate that the load is done.
N
No load phase at the target.
CAPTURE_LOAD
Specifies the action that the Q Capture program takes when the recovery log shows that a load operation that uses the DB2 LOAD utility occurred at the source table.
W (default)
Q Capture issues a warning message after the load completes.
R
Q Capture stops and starts the Q subscription for the source table, prompting a load of the target table if one is specified for the Q subscription.
SPILL_MODELQ "name"
Specifies the name of the model queue that is used as a spill queue for this Q subscription. On z/OS®, you might want to create separate spill queues for Q subscriptions if the page set for the model queue is not large enough to handle transactions from multiple Q subscriptions during a load. The queue name must be enclosed in double quotation marks.
SUPPRESS DELETES
Specifies whether to send rows that were deleted from the source table. This parameter is not valid for Classic replication.
N (default)
Send deleted rows.
Y
Do not send deleted rows.
REPLICATE ADD COLUMN
Specifies whether new columns that are added to the source table should automatically be added to the Q subscription, and to the target table if they do not already exist.
Y (default)
New source table columns are automatically added to the Q subscription.
N
New source table columns are not automatically added to the Q subscription.
CHANGE CONDITION "change_condition"
Specifies a predicate that uses log record variables for filtering changes to replicate. You cannot use this parameter with Classic replication.

You can use the following log record variables:

$OPERATION The DML operation. Valid values are I (insert), U (update), and D (delete).
$AUTHID The authorization ID of a transaction.
$AUTHTOKEN z/OS: The authorization token (job name) of a transaction.
$PLANNAME z/OS: The plan name of a transaction.

For example, the following predicate specifies that Q Capture only replicate log records that were not committed by the user ASN:

"$AUTHID <> 'ASN'"
If a different predicate is specified by using the SEARCH CONDITION keyword, that predicate is combined with the CHANGE CONDITION predicate into a single predicate by using the AND operator. For more details on the format for CHANGE CONDITION, see Log record variables to filter rows.
START AUTOMATICALLY
Specifies how to start the Q subscription, which is represented by the State column in the IBMQREP_SUBS table. The State column controls whether the subscription is automatically started after starting or reinitializing the Q Capture program (subscription state N), or that the subscription must be started manually by inserting a command in the IBMQREP_SIGNAL table (subscription state I).
YES
The Q subscription is started automatically (subscription state value of N). This is the default.
NO
The Q subscription must be started manually (subscription state value of I).
IGNORE TRIGGERS
Specifies that any rows that are generated by AFTER triggers at the source database will not be replicated. Use this option to avoid duplicate rows when matching triggers are already being used at the target table. If you use this option for the Q subscription, triggered changes will be ignored even if the Q Capture instance-level igntrig parameter is set to N.
IGNORE CASCADE DELETES
Specifies that when rows are deleted from child tables because of the ON DELETE CASCADE rule, the DELETE operation is not replicated. Use this option to avoid duplicate DELETE operations when ON DELETE CASCADE is already being used at the target database. If you use this option for the Q subscription, cascaded DELETE operations will be ignored even if the Q Capture instance-level igncasdel parameter is set to N.
IGNORE SET NULL
Specifies that when the foreign key in a child table is set to NULL because of the ON DELETE SET NULL rule, the UPDATE operation is not replicated. Use this option to avoid duplicate UPDATE operations when ON DELETE SET NULL is already being used at the target database. If you use this option for the Q subscription, ON DELETE SET NULL operations will be ignored even if the Q Capture instance-level ignsetnull parameter is set to N.

z/OS: This option is not supported on z/OS. The UPDATE operations resulting from ON DELETE SET NULL are still replicated if you specify this option on z/OS.

trg-clause:

EXIST
Specifies that the target table exists.
  • If you specify EXIST but do not provide a target table name, the ASNCLP program will look for the default table TGT-SOURCE TABLE NAME.
  • If you specify EXIST and a single TARGET NAME, and you use SOURCE ALL or SOURCE NAME LIKE, then all of the source tables will be mapped to that single specified existing target table.
  • If you do not specify EXIST, and you use SOURCE ALL or SOURCE NAME LIKE, then the source tables will be paired with target tables that use the default name TGT-SOURCE TABLE NAME.
TYPE
USERTABLE
Specifies a table as the target.
NICKNAME
Specifies a nickname as the target.
WITH LOGMARKER
Use these keywords with the USERTABLE or NICKNAME keywords to specify a point-in-time target table or nickname. The target table or nickname must contain the column IBMSNAP_LOGMARKER (TIMESTAMP; nullable with default of NULL). If the ASNCLP creates the target table or nickname, this column is included. The WITH LOGMARKER keywords are only supported when the Q Apply program is at Version 9.7 Fix Pack 4 or later on Linux, UNIX, and Windows or Version 10.1 on z/OS (ARCH_LEVEL 100Z) with the PTF that corresponds to Fix Pack 4.
Note: You cannot use the WITH LOGMARKER keywords if the source table has an IBMSNAP_LOGMARKER column. To create a three-tier configuration in which each table contains the IBMSNAP_LOGMARKER column, use the WITH LOGMARKER keywords when you create the Q subscription from Tier 1 to Tier 2. For the Q subscription from Tier 2 to Tier 3, use a regular column mapping to map the IBMSNAP_LOGMARKER column at Tier 2 to the matching column at Tier 3. This method ensures that the timestamp of when the row was changed at the source table at Tier 1 will be correctly propagated from Tier 2 to Tier 3.

The WITH LOGMARKER option is not supported for bitemporal tables.

STOREDPROC
Specifies a stored procedure as the target.
CCD
Specifies a consistent-change data (CCD) table as the target.
Note: You cannot use the TYPE CCD keywords if the source table has the IBMSNAP_COMMITSEQ, IBMSNAP_INTENTSEQ, IBMSNAP_LOGMARKER, or IBMSNAP_OPERATION columns that are used in CCD tables. To create a three-tier configuration in which each table contains these columns, use the TYPE CCD keywords when you create the Q subscription from Tier 1 to Tier 2. For the Q subscription from Tier 2 to Tier 3, use a regular column mapping to map the IBMSNAP_% columns at Tier 2 to the matching columns at Tier 3. This method ensures that the values from the Tier 1 source recovery log that are used to populate the CCD table at Tier 2 will be correctly propagated to Tier 3.
CREATE SQL REGISTRATION
Registers the target CCD table for the Q subscription as a source for SQL replication.
ALTER SQL REGISTRATION FOR Q REPLICATION
Modifies an existing registration for SQL replication by updating the CD_OWNER field in the IBMSNAP_REGISTER table with the Q Apply schema and the CD_TABLE field with the name of the receive queue for the Q subscription. You can also use this action to change an existing SQL registration to a Q subscription that uses a different receive queue.
KEYS
Specifies one or more key columns that replication uses to determine the uniqueness of a row. If no key is specified, replication tries to determine its own key by looking first for a primary key within the set of replicated columns, then for a unique constraint, and then for a unique index. If none of these exists, replication will use all subscribed, valid columns as key columns for replication. (Some subscribed columns, such as LOB columns, cannot be used as keys.)
indexowner.indexname
Specifies the index owner and name.
NAMING PREFIX prefix
Specifies the prefix to use to name the index.
keyname
Specifies the name of the columns that are included in the index.
+
Ascending order.
-
Descending order.
ZOS INDEX CREATE USING PROFILE pname
Specifies the name of the index profile for customizing a z/OS index.
NICKNAME
Specifies the nickname for the Q Apply program to use to load rows into the target table with the LOAD from CURSOR utility. Use this keyword only to specify a nickname for loading. The nickname that is specified with this keyword is not used to reference a target table in a non-DB2 relational database.
For Version 9.7 Fix Pack 4 or newer: If the Q Apply program is at Version 9.7 Fix Pack 4 or newer, and the source table does not include XML columns, you do not need to specify the NICKNAME keyword for loading the target with LOAD from CURSOR. In this case, the Q Apply program invokes LOAD from CURSOR by using a cataloged DB2 alias rather than a nickname.
owner.nickname
Specifies the source owner and nickname.
NAMING PREFIX prefix
Specifies the prefix to use to name the nickname.
NEW NICKNAME RMT SERVERNAME srvname
Specifies the name of the remote server if the ASNCLP program creates the nickname for loading.
CONFLICT RULE
Specifies how the Q Apply program checks for conflicts between replicated rows and existing rows in the target table.
K (default)
Check only key values.
C
Check changed nonkey values and key values.
A
Check all values for updates.
CONFLICT ACTION
Specifies what action to take if a conflict occurs.
I (default)
Ignore
F
Force: This action requires the send option CHANGED COLS ONLY =N.
D
Disable the Q subscription.
S
Stop Q Apply.
Q
Stop reading from queue.
ERROR ACTION
Specifies what action to take if an error occurs.
S
The Q Apply program does not apply the conflicting row but applies other rows in the transaction. Then it disables the Q subscription, stops applying transactions to the target, and sends an error report to the Q Capture program on the administration queue.
D
Disable the Q subscription and notify the Q Capture program or the Classic capture components.
Q
Stop reading from the receive queue.
B
When an error occurs, spill change messages for the Q subscription to a temporary spill queue until you use the resumesub parameter of the MODIFY or asnqacmd command to prompt Q Apply to begin applying the messages.
OKSQLSTATES "sqlstates"
Specifies a list of SQL statements within double quotation marks that are not to be considered as errors when applying changes to this table.
LOAD TYPE
Specifies a method of loading the target table with data from the source.
Note: By default, for all of the following load types the load utilities are invoked with an option to delete all existing data in the target table before replacing it with data from the source (this is called the replace option). You can use the EXIST DATA APPEND keywords to specify that the chosen load utility is invoked with an option to append source data to the target table without deleting target table contents.
0
Choose the best type automatically. Not valid for Classic sources.
1
Use LOAD from CURSOR only. Specify this option if the source and target servers are on z/OS. Not valid for Classic sources or federated targets.
Note: If the Q Apply program is at Version 9.7 Fix Pack 4 or newer, you do not need to provide nickname information for this load option unless the Q subscription includes XML columns. Q Apply calls LOAD from CURSOR by specifying a cataloged DB2 alias for the source database instead of by using a nickname. You must include the DB2 alias in a password file that is created by the asnpwd utility.
2
Use the EXPORT and IMPORT utilities. Not valid for Classic or Oracle sources.
3
Use the EXPORT and LOAD utilities. Not valid for Classic or Oracle sources or for federated targets.
4
Select from a replication source and use the DB2 LOAD utility, or for Oracle targets use the SQL*Loader utility.
Oracle targets: To use SQL*Loader, you must create a password file by using the asnpwd command in the directory that is specified by the apply_path parameter or the directory from which Q Apply is invoked with the following values for these keywords:
  • alias: The Oracle tnsnames.ora entry that refers to the Oracle server (the same name that is used for the NODE option of the CREATE SERVER command for setting up federation).
  • id: The remote user ID for connecting to Oracle.
  • password: The password for connecting to Oracle.
The file must have the default name asnpwd.aut. Before starting the Q subscription, you should test connectivity with this command: $> sqlplus id/password@alias.
5
Linux, UNIX, and Windows targets: Select from a replication source and use the DB2 IMPORT utility. The replace option is used by default. Use this load option when the source code page differs from the target code page. The DB2 IMPORT utility converts code pages when it is invoked with this option.
EXIST DATA
Specifies whether existing data in the target table is replaced or appended to during the loading process:
REPLACE (default)
The load utility is invoked with the option to delete all data in the target table before replacing it with data from the source.
APPEND
The load utility is invoked with the option to append source data to the target table without deleting target table contents.
TARGET
Specifies options for the target table owner and name.
NAME target_owner.target_name
Specifies the target table name and optionally the table schema.
NAMING PREFIX
Specifies the prefix to use to name the target table. The default is TGT. You can specify any other prefix, for example, if you specify CLP as a prefix and the source table is T1, the target table would be called CLPT1.
TABLE OWNER
Specifies options for the target table owner.
target_owner
Specifies to use the schema of the target table.
NAMING PREFIX
Specifies the prefix to use to name the target table owner. The default is TGT. You can specify any other prefix, for example, if you specify CLP as a prefix and the source table is T1, the target table would be called CLPT1.
SAME AS SOURCE
Specifies to use the same owner as the corresponding source table.
SAME AS USERID
Specifies to use the current user ID.
TABLE NAME
Specifies options for the target table name.
target_name
Specifies the name that you want to use for the target table.
NAMING PREFIX
Specifies the prefix to use to name the target table. For example, if you specify CLP as a prefix and the source table is T1, the target table would be called CLPT1.
SAME AS SOURCE
Specifies to name the target table the same as the corresponding source table.
FEDERATED
Specifies that the target table is in a non-DB2 relational database and you want replication to create a new nickname that references the target table. Use the fed-clause to specify a name and owner for the new nickname.
Note: Do not use this keyword if you are using an existing nickname to reference the target table. Instead, use the nickname-options clause.
IN
DB name
Specifies the name of the logical database for the table space (required for z/OS).
tsname
Specifies the name of the table space for the target table.
Federated targets:
Specifies an existing table space (Oracle), segment (Sybase), dbspace (Informix®), or file group (Microsoft SQL Server). This parameter is not applicable for Teradata targets.
NAMING PREFIX prefix
Specifies the prefix to use to name the table space.

nickname-options-clause:

NICKNAME
Specifies an existing nickname that references a target table in a non-DB2 relational target database. Use the nickname-options clause only to specify existing nicknames. Do not use both the nickname-options clause and the FEDERATED keyword; they are mutually exclusive. Use the FEDERATED keyword when you want replication to create the nickname.

If you use an existing nickname, make sure that the nickname data types are compatible with the source table according to Q Replication requirements. See Nickname data types required for federated Q Replication for more details.

Note: Do not use this NICKNAME keyword to specify a nickname for loading the target table with the LOAD from CURSOR utility.

fed-clause:

nickname target owner
Specifies the owner for a new nickname that replication creates to reference a federated target, or the owner of an existing nickname.
nickname target name
Specifies the name of a new nickname that replication creates to reference a federated target, or the owner of an existing nickname.

ccd-clause:

CONDENSED
Specify one of the following values:
ON
Specifies that the CCD table is condensed. A condensed CCD table contains one row for every key value in the source table and contains only the latest value for the row.
OFF
Specifies that the CCD table is noncondensed. A noncondensed CCD table contains multiple rows with the same key value, one row for every change that occurs to the source table.
COMPLETE
Specify one of the following values:
ON
Specifies that the CCD table is complete. A complete CCD table contains every row of interest from the source table and is initialized with a full set of source data.
OFF
Specifies that the CCD table is noncomplete. A noncomplete CCD table contains only changes to the source table and starts with no data.
WITH UOW COLS
Specify one of the following values:
ALL
Specifies that the CCD table contains all four unit-of-work (UOW) columns: IBMSNAP_AUTHID, IBMSNAP_AUTHTKN, IBMSNAP_PLANID, IBMSNAP_UOWID.
colname
Specify one or more unit-of-work (UOW) columns for the CCD table.

targetcolumns-clause:

TRGCOLS
ALL
Specify to replicate all columns from the source table.
INCLUDE
Specifies the replicated columns in the target table. If the target table does not exist, specifies the column definitions in the target table.
trgcolname
Specify to define a target table column that uses the provided name and the properties of a source column with the same name. In the following example, both the source and target table have the columns one, two, and three.
CREATE QSUB SUBTYPE U USING REPLQMAP replqmap9
(SUBNAME sub9 dpropr64.srctable 
EXIST TARGET NAME dpropr64.trgtable
TRGCOLS INCLUDE (one, two))
srccolname
Specify to define a target table column that uses the properties of the specified source column, but when the target column has a different name than the source column. In the following example, the target table defines two columns target_one and target_two based on the properties of corresponding columns one and two in the source table:
CREATE QSUB SUBTYPE U USING REPLQMAP replqmap9 
(SUBNAME sub9 dpropr64.srctable
 EXIST TARGET NAME dpropr64.trgtable 
TRGCOLS INCLUDE (target_one one, target_two two))
EXCLUDE (trgcolnames)
This keyword behaves differently depending on whether the target table exists or you are creating a new target table with the Q subscription. In the examples, the source table columns are C1, C2, and C3:
New target table
Specify to exclude the source column from the target table definition and the Q subscription. For example, in the following command column C3 is excluded from the new target table and the Q subscription:
CREATE QSUB USING REPLQMAP replqmap10
(SUBNAME sub10 dpropr64.srctable TARGET NAME
dpropr64.tgttable TRGCOLS EXCLUDE(C3));
You cannot use this keyword when you are creating a new target table with a Classic replication source.
Existing target table
Specify to exclude target columns from the Q subscription. This keyword can be used only when the source and target tables have the same column names. The target table already exists and has columns C1, C2, and C4. Column C4 will be excluded from the Q subscription:
CREATE QSUB USING REPLQMAP replqmap10 
(SUBNAME sub10 dpropr64.srctable EXIST TARGET NAME 
dpropr64.tgttable TRGCOLS EXCLUDE(C4));
EXPRESSION exp
Specifies a DB2-supported expression to which the target column is mapped.
TARGET trgcolname
Specifies the name of the target column that will be populated by the expression.

Note about TRGCOLS and EXPRESSION usage

The syntax for using the TRGCOLS and EXPRESSION keywords in the same command differs depending on whether the target table exists or you are creating a new target table with the Q subscription. Follow these guidelines when you use TRGCOLS ALL and EXPRESSION, TRGCOLS INCLUDE and EXPRESSION, and TRGCOLS EXCLUDE and EXPRESSION. In the examples, the source table has the columns C1, C2, and C3:

New target table
These notes apply to the use of TRGCOLS and EXPRESSION when you are creating a new target table:
TRGCOLS ALL and EXPRESSION
The new target table and the Q subscription will include all columns from the source table and the columns that are specified in the EXPRESSION clause. In this example, the target table will be created with four columns: C1, C2, C3, and EXPC3:
CREATE QSUB USING REPLQMAP replqmap10
(SUBNAME sub10 dpropr64.srctable TARGET NAME
dpropr64.tgttable TRGCOLS ALL EXPRESSION
("CHAR(:C3)" TARGET EXPC3));
TRGCOLS INCLUDE and EXPRESSION
The new target table and the Q subscription will include the source columns that are specified in the INCLUDE clause and the columns that are specified in the EXPRESSION clause. In this example, the target table will be created with three columns: C1, C2, and EXPC3:
CREATE QSUB USING REPLQMAP replqmap10 
(SUBNAME sub10 dpropr64.srctable TARGET NAME
dpropr64.tgttable TRGCOLS INCLUDE (C1,C2) EXPRESSION
("CHAR(:C3)" TARGET EXPC3));
TRGCOLS EXCLUDE and EXPRESSION
Source columns that are specified in the EXCLUDE clause will be excluded from the target table and the Q subscription. The target table will include the columns that are specified in the EXPRESSION clause. In this example, the target table will be created with two columns: C1 and EXPC3:
CREATE QSUB USING REPLQMAP replqmap10 
(SUBNAME sub10 dpropr64.srctable TARGET NAME 
dpropr64.tgttable TRGCOLS EXCLUDE(C2,C3) EXPRESSION
("CHAR(:C3)" TARGET EXPC3));
Existing target table
These notes apply to the use of TRGCOLS and EXPRESSION when the target table exists:
TRGCOLS ALL and EXPRESSION
Not supported. TRGCOLS ALL means that all of the columns in the target table are mapped directly to the source table column names, so EXPRESSION cannot be used.
TRGCOLS INCLUDE and EXPRESSION
The target columns that are specified in the INCLUDE clause and any expressions that are specified in the EXPRESSION clause will be included in the Q subscription. Any columns that are specified in the INCLUDE clause should not be specified in the EXPRESSION clause. In this example, the target table has the columns C1, C2, EXPC3, and C4. The Q subscription will include the columns C1, C2, and EXPC3:
CREATE QSUB USING REPLQMAP replqmap10
(SUBNAME sub10 dpropr64.srctable EXIST TARGET NAME 
dpropr64.tgttable TRGCOLS INCLUDE (C1,C2) EXPRESSION
("CHAR(:C3)" TARGET EXPC3));
TRGCOLS EXCLUDE and EXPRESSION
The target columns that are specified in the EXCLUDE clause will be excluded from the Q subscription. Any expressions that are specified in the EXPRESSION clause will be included in the Q subscription. Columns that are specified in the EXPRESSION clause should be excluded using the EXCLUDE clause. In this example, the target table has the columns C1, C2, EXPC3, and C4. The Q subscription will include the columns C1, C2, and EXPC3:
CREATE QSUB USING REPLQMAP replqmap10 
(SUBNAME sub10 dpropr64.srctable EXIST TARGET NAME 
dpropr64.tgttable TRGCOLS EXCLUDE(C4,C3) EXPRESSION
("CHAR(:C3)" TARGET EXPC3));
VALIDATE YES
The ASNCLP program evaluates the expression against the target column to which it is mapped to ensure that the data is compatible. This is the default.
VALIDATE NO
The ASNCLP program does not validate the expression. If you use this option you must ensure that the expression is compatible with the mapped target column and that the data fits in the target column.

ccdoptions-clause

BEFORE IMAGE COLUMNS
Specifies that the before-image value of each added column will be replicated.
PREFIX "x"
Specifies the prefix for each before-image column. If you do not specify a prefix, the default value of is used. If this prefix generates invalid names, other letters will be used beginning with the letter Y until valid names are generated.
ALL
Specifies that all of the after-image columns have before-image columns. This option is the default. Depending on the prefix that you choose, the DB2 database either picks before-image columns for existing targets or generates new before-image columns for new targets.
COLS
Specifies custom before-image column names.
AFTER aftercols
Specifies the name of the after-image column in the target table.
BEFORE beforecols
Specifies the name of the before-image column in the target table. This parameter is required. The value of BEFORE takes precedence over the name that is generated by the prefix for this particular column.
INCLUDE
Specifies the columns that will be part of the before-image columns.
AFTER afterincludes
Specifies the name of the after-image column in the target table.
BEFORE beforeincludes
Specifies the name of the before-image column. This parameter is optional. The value of BEFORE takes precedence over the name that is generated by the prefix for this particular column.
FOR KEY COLS ONLY
Specifies that before-image columns are generated only for the replication key columns.

period-clause:

PERIOD
Specifies that the source table is a temporal table and you want to include some or all of the period columns in the Q subscription.
ALL
Specifies that you want to include all period columns.
SYSTEM_TIME
Specifies that you want to include the timestamp columns that are used with system-period temporal tables.
BUSINESS_TIME
Specifies that you want to include the timestamp or date columns that are used with application-period temporal tables.

history-table-clause:

INCLUDE HISTORY
Specifies that the source table is a temporal table with versioning and that you want to create a corresponding Q subscription for the history table.
EXIST
Specifies that you want to create a Q subscription for an existing history table. The ASNCLP program obtains the history table information from the base table name.

new-history-table-clause:

HIST_TARGET NAME
Specifies the name of a new target history table to be created by the ASNCLP program.

tbspace-clause:

IN
DB name
Specifies the name of the logical database for the table space (required for z/OS).
tsname
Specifies the name of the table space for the target history table. If you want to use an existing table space, the target history table must be the only table that uses the table space.
NAMING PREFIX prefix
Specifies the prefix to use to name the table space.

prof-clause:

CREATE
Specify to create a table space. If this keyword is not specified, the table space is treated as an existing one.
USING PROFILE pname
Specifies the name of the profile to use to create the table space.

Usage notes

  • The REPLQMAP keyword is mandatory. You can specify either CREATE QSUB USING REPLQMAP mapname or CREATE QSUB (SUBNAME subname REPLQMAP mapname).
  • If a target table is specified and SRC ALL or SRC NAME LIKE was specified, all the source tables will attempt to subscribe to target tables with the same name.
  • If the TABLE OWNER or TABLE NAME keywords are not specified, the default owner is the owner of the corresponding source table, and the default name is TGT-SOURCE TABLE NAME
  • The DB value for logical database is mandatory for target tables on z/OS products. It must be specified in the profile.
  • If a mass subscription is used (for example, if you use the SRC OWNER LIKE or SRC NAME LIKE clause), the specified target_owner.target_name clause is valid only if the target table exists. Only the default or a naming prefix are allowed for generated target tables.
  • The CREATE QSUB command performs an additional check when you create a Q subscription for a CCD target. If you configured Q Apply to manage an SQL Capture schema, and an SQL registration exists for the target CCD in this schema, the ASNCLP issues a message that Q Apply will manage the target CCD as an SQL replication source automatically.

Example: Basic Q subscription

This example shows the environmental commands that are needed to set up for creating a Q subscription, along with the command for creating the Q subscription. The CREATE QSUB command generates SQL to create a Q subscription named EMPLOYEE0001 that specifies the EMPLOYEE table as a source. By default the ASNCLP program generates SQL for creating a target table named TGTEMPLOYEE. The EMPNO column, which is the primary key for the EMPLOYEE table, is specified as the key for replication. The command also specifies that the Q Apply program load the target table (LOAD PHASE I) using the LOAD from CURSOR utility (LOAD TYPE 1).
ASNCLP SESSION SET TO Q REPLICATION;
SET SERVER CAPTURE TO DBALIAS SAMPLE ID db2admin PASSWORD "passw0rd";
SET SERVER TARGET TO DBALIAS TARGETDB ID db2admin PASSWORD "passw0rd";
SET RUN SCRIPT NOW STOP ON SQL ERROR ON;
CREATE QSUB USING REPLQMAP SAMPLE_ASN_TO_TARGETDB_ASN
(SUBNAME EMPLOYEE0001 db2admin.EMPLOYEE OPTIONS HAS LOAD PHASE I
KEYS (EMPNO) LOAD TYPE 1);

Example: Q subscription with automatic load and nickname

This example creates a Q subscription SUB_T1 that specifies an automatic load (LOAD TYPE 1) and creates a new nickname REPLDBA.NICK_T1 at the Q Apply server for the LOAD from CURSOR utility. RMTSAMPLE is the remote server definition on TESTDB that points to the SAMPLE database, which is the data source for the nickname.
ASNCLP SESSION SET TO Q REPLICATION;
SET OUTPUT CAPTURE SCRIPT "REPLCAP.SQL" TARGET SCRIPT "REPLAPP.SQL";
SET LOG "QSUB.LOG";
SET SERVER CAPTURE TO DB SAMPLE;
SET SERVER TARGET TO DB TESTDB;
SET APPLY SCHEMA ASN;
SET CAPTURE SCHEMA SOURCE ASN;
CREATE QSUB (SUBNAME "SUB_T1" REPLQMAP SAMPLE_ASN_TO_TESTDB_ASN REPLDBA.T_TEMP
OPTIONS HAS LOAD PHASE I TARGET NAME REPLDBA.T_TEMPNEWNEW TYPE USERTABLE
NEW NICKNAME RMT SERVERNAME RMTSAMPLE REPLDBA.NICK_T1 LOAD TYPE 1);

Example: Using an existing nickname for LOAD from CURSOR

This examples creates the SUB_T2 Q subscription and specifies that the Q Apply program use an existing nickname, REPLDBA.NICK_T2, for the LOAD from CURSOR utility.
ASNCLP SESSION SET TO Q REPLICATION;
SET OUTPUT CAPTURE SCRIPT "REPLCAP.SQL" TARGET SCRIPT "REPLAPP.SQL";
SET LOG "QSUB.LOG";
SET SERVER CAPTURE TO DB SAMPLE;
SET SERVER TARGET TO DB TESTDB;
SET APPLY SCHEMA ASN;
SET CAPTURE SCHEMA SOURCE ASN;
CREATE QSUB (SUBNAME "SUB_T2" REPLQMAP SAMPLE_ASN_TO_TESTDB_ASN REPLDBA.T_TEMP
OPTIONS HAS LOAD PHASE I TARGET NAME REPLDBA.T_TEMPNEWNEW TYPE USERTABLE
NICKNAME REPLDBA.NICK_T2 LOAD TYPE 1);

Example: Naming prefix for target table

This example demonstrates the use of a naming prefix for the target table (XNEW) and table space for the target table (Y). The example also shows the use of "like" statements to specify the source table for the Q subscription.
CREATE QSUB USING REPLQMAP QDECODERQM (SRC OWNER LIKE "DSN8710%" SRC NAME LIKE
"%EMP%" TARGET TABLE NAME NAMING PREFIX XNEW IN DB D1CDG01 NAMING PREFIX Y);

Example: Q subscription with table space profile

This example shows how to use a table space profile (USING PROFILE UTRGTS) for the target table space when the target tables do not exist.
CREATE QSUB USING REPLQMAP QDECODERQM (SRC OWNER LIKE "DSN8710%" SRC NAME LIKE
"%EMP%" TARGET TABLE NAME NAMING PREFIX XNEW2 IN DB D1CDG01 EMPTBSP2 CREATE USING
PROFILE UTRGTS);

Example: DB2 for z/OS with profiles

This example shows the commands that are needed to set the environment and profiles for a CREATE QSUB command for unidirectional replication from a DB2 source. In this example, both the Q Capture program and Q Apply program run in the same z/OS subsystem and share a queue manager.
ASNCLP SESSION SET TO Q REPLICATION;
SET SERVER CAPTURE to dbALIAS EC06V71A DBNAME stlec1 ID ADMF001  password "xx";
SET SERVER TARGET to dbALIAS EC06V71A DBNAME stlec1 ID ADMF001  password "xxx";
SET CAPTURE SCHEMA SOURCE QDECODER;
SET APPLY SCHEMA QDECODER;
SET QMANAGER "CSQ1" FOR CAPTURE SCHEMA;
SET QMANAGER "CSQ1" FOR APPLY SCHEMA;
SET PROFILE "UITRGTS" FOR OBJECT TARGET INDEX OPTIONS ZOS
		BUFFERPOOL BP1 	STOGROUP "DPROSTGQ"
		PRIQTY ABSOLUTE 100 SECQTY ABSOLUTE 50;
SET PROFILE "UTRGTS" FOR OBJECT TARGET TABLESPACE OPTIONS ZOS
 		DB "JUTRGDB"
		BUFFERPOOL BP4
 		ENCODING UNICODE
 		STOGROUP "DPROSTG"
 		PRIQTY ABSOLUTE 100  SECQTY ABSOLUTE 50;
SET OUTPUT CAPTURE SCRIPT "capfile6.sql" TARGET SCRIPT "tgtfile.sql";
SET RUN SCRIPT NOW STOP ON SQL ERROR ON;

Example: Existing target table

This example shows that no IN clause is required when the target table exists.
CREATE QSUB USING REPLQMAP QDECODERQM (SRC OWNER LIKE "DSN8710%" SRC NAME LIKE
"%EMP%" EXIST TARGET TABLE OWNER NAMING PREFIX X);

Example: Same source and target owner names

In this example the source and target owner names are the same. For the source and target owner names to be the same, the target must be in a different database or subsystem than the source.
CREATE QSUB USING REPLQMAP QDECODERQM (SRC OWNER LIKE "DSN8710%" SRC NAME LIKE
"%EMP%" TARGET TABLE OWNER SAME AS SOURCE TABLE NAME SAME AS SOURCE );

Example: Load with EXPORT and IMPORT

This example creates a Q subscription for unidirectional replication from a DB2 source that uses the replication queue map SAMPLE_ASN1_TO_TARGETDB_ASN1 and specifies that the Q Apply program loads the target tables with the EXPORT and IMPORT utilities. It also specifies that the column EMPNO be used as the key for replication.
CREATE QSUB USING REPLQMAP SAMPLE_ASN1_TO_TARGETDB_ASN1
(SUBNAME EMPLOYEE0001 EMPLOYEE OPTIONS HAS LOAD PHASE I
TARGET NAME TGTEMPLOYEE KEYS (EMPNO) LOAD TYPE 2);

Example: Target table on Sybase

This example creates a Q subscription from the DB2 table EMPLOYEE to the Sybase table TGT_EMPLOYEE. The table will be created in the existing Sybase segment SEG_EMPLOYEE by using the SAMPLE_ASN_TO_FEDDB_ASN replication queue map. The table will have the nickname of EMPNICKNAME.
CREATE QSUB USING REPLQMAP SAMPLE_ASN_TO_FEDDB_ASN (SUBNAME FEDQSUB
EMPLOYEE TARGET NAME TGTEMPLOYEE FEDERATED EMPNICKNAME);

Example: Target consistent-change-data (CCD) table

This example creates a Q subscription with new target CCD table. All of the columns in the source table take part in the Q subscription. The command also specifies before-image columns for the key columns and a before-image prefix of Y.
ASNCLP SESSION SET TO Q REPLICATION;
SET RUN SCRIPT NOW STOP ON SQL ERROR ON;
SET SERVER CAPTURE TO DB SAMPLW;
SET SERVER TARGET TO DB SAMPLE;
SET CAPTURE SCHEMA SOURCE ASNAPP1;
SET APPLY SCHEMA ASNAPP1;
CREATE QSUB USING REPLQMAP SAMPLE_ASNAPP1_TO_SAMPLE_ASNAPP1
	(SUBNAME TESTCCCDNEW DATA.EMPLOYEE TARGET NAME DATA.TGTEMPLOYEE
	TYPE CCD CONDENSED ON COMPLETE ON WITH UOW COLS ALL
	TRGCOLS ALL BEFORE IMAGE COLUMNS PREFIX "Y" FOR KEYS COLS ONLY);

Example: Target column expression

This example creates a Q subscription by using a target column expression that maps all of the columns that match the expression CONCAT(:C1,:C2) to the target column CEXP.
ASNCLP SESSION SET TO Q REPLICATION;
SET RUN SCRIPT NOW STOP ON SQL ERROR ON;
SET SERVER CAPTURE TO DB SAMPLE;
SET SERVER TARGET TO DB SAMPLE;
SET CAPTURE SCHEMA SOURCE ASNAPP1;
SET APPLY SCHEMA ASNAPP1;
CREATE QSUB USING REPLQMAP SAMPLE_ASNAPP1_TO_SAMPLE_ASNAPP1
(SUBNAME TESTEXPRESSTION DATA.EMPLOYEE TARGET NAME DATA.TGTEMPLOYEE
TRGCOLS ALL EXPRESSION ("CONCAT(:C1,:C2)" TARGET CEXP));

Example: Classic replication

This example creates a Q subscription called CLASSIC0001 for Classic replication. The CREATE QSUB command specifies a source table called CLASSICTABLE and specifies that the Q Apply program is to load a target table of the same name.
ASNCLP SESSION SET TO Q REPLICATION;
SET SERVER CAPTURE TO CONFIG SERVER classic1 FILE "asnservers.ini"
ID CLASSICADMIN PASSWORD "passw0rd";
SET SERVER TARGET TO DB TARGET ID DB2ADMIN PASSWORD "passw0rd";
SET RUN SCRIPT NOW STOP ON SQL ERROR ON;
SET APPLY SCHEMA ASN1;
CREATE QSUB USING REPLQMAP CLASSIC_ASN1_TO_TARGET_ASN1 (SUBNAME CLASSIC0001
CLASSICTABLE OPTIONS HAS LOAD PHASE I TARGET NAME CLASSICTABLE LOAD TYPE 4);

Example: Oracle target

This example creates a Q subscription for the Oracle target table HR.EMPLOYEE. The nickname that references the target table, HR.EMPNICK, already exists on the Q Apply server.

ASNCLP SESSION SET TO Q REPLICATION;
SET SERVER CAPTURE TO DB SAMPLE;
SET SERVER TARGET TO DB FEDORA NONIBM SERVER V10ORA;
CREATE QSUB USING REPLQMAP REPQMAP1
(SUBNAME SUB1 EMPLOYEE EXIST NICKNAME HR.EMPNICK TYPE NICKNAME);

Example: Temporal table with PERIOD ALL

The following commands set the environment and create a Q subscription for a temporal table (OEUSR01.SRC_TABLE1). The PERIOD ALL keywords specify that all the period columns (row-begin, row-end, and transaction-start-ID) should be included in the Q subscription. The INCLUDE HISTORY keywords specify that a separate Q subscription should be created for the source history table. Because the EXIST keyword is not specified, the ASNCLP program generates a script to create the target temporal table and its associated history table.
ASNCLP SESSION SET TO Q REPLICATION;
SET SERVER CAPTURE TO DB SRC;
SET SERVER TARGET TO DB TGT;
CREATE REPLQMAP QMAP1;
CREATE QSUB USING REPLQMAP QMAP1
 (SUBNAME EMPLOYEE001 OEUSR01.SRC_TABLE1
  OPTIONS ALL CHANGED ROWS N HAS LOAD PHASE I SUPPRESS DELETES N
  TARGET NAME OEUSR01.TGT_TABLE1 TYPE USERTABLE
  TRGCOLS ALL PERIOD ALL INCLUDE HISTORY);

Example: Stored procedure target

The following example creates the Q subscription DEPT001 to a stored procedure target. The source table is db2admin.DEPARTMENT, and four columns in the existing target table (DEPTNO, DEPTNAME, MGRNO, ADMRDEPT) will be populated by the stored procedure after it receives replicated source data.

CREATE QSUB SUBTYPE U (SUBNAME "DEPT001" REPLQMAP SOURCE_ASN_TO_TARGET_ASN
db2admin.DEPARTMENT OPTIONS HAS LOAD PHASE N EXIST TYPE STOREDPROC
TRGCOLS INCLUDE (DEPTNO, DEPTNAME, MGRNO, ADMRDEPT)
KEYS (DEPTNO, DEPTNAME, MGRNO)