Setting and working with context

The context defines the Access Server, source and target datastores, subscription and table mapping that are currently active in the script.

The context is similar to selection in Management Console. For example, in order to view or modify column mappings in Management Console, you must select a table mapping in the current subscription. In scripting, you must set the context to a table mapping. Setting a table mapping context requires a subscription to be the current context, and the subscription context requires a source and target datastore context.

To view the current context, execute the show context command.

CONTEXT            CURRENT OBJECT
------------------ ---------------------------------- 
Access Server      localhost@10101                    
Source Datastore   DS1
Target Datastore   DS2
Subscription       SUB1                               
Table Mapping      CDC.TABLE_1 - CDC.TABLE_1

Setting the Access Server context

When you connect to Access Server, the context is automatically set. Disconnecting from Access Server clears all context settings.

Setting the datastore context

When you connect to a datastore, the context is automatically set to the source and target, depending on the capabilities of the datastore. For example, connecting to a DB2® datastore sets the source and target context to that datastore, because the Db2 datastore can be used as a source and target in subscriptions. Connecting to an IBM® DataStage® datastore sets the target context, because the IBM DataStage datastore can only be used as a target.

Specifying or changing the context can be performed during connection or afterwards. You do not have to disconnect and reconnect to change the context, and you can change the context as often as you need.

To connect to a DB2 datastore and set it to source and target context, execute the connect datastore command:

connect datastore name DB2DS;

If you now execute the add subscription command, the subscription will be created with DS2DS datastore as the source and target datastores for the subscription. If you want to create a subscription between two different datastores, you can either connect to those datastores and identify your intention using the following commands:

connect datastore DB2DS1 context source;
connect datastore DB2DS2 context target;

or you can connect to both datastores and specify the context after:

connect datastore DB2DS1;
connect datastore DB2DS2;
select datastore DB2DS1 context source;
select datastore DB2DS2 context target;

You can also execute the following, where the first connect statement will set the context for the source and target to DB2DS1, and the second connect will override the target context to DB2DS2:

connect datastore DB2DS1;
connect datastore DB2DS2 context target;

When you specify the context during connection, the context will only be set if the connection succeeds. If you need to change the context after you have connected, use the select datastore command. If the context is invalid for the datastore, an error will be reported, but the datastore connection will not be closed. For example, if you execute connect to an IBM DataStage datastore with source context, the connection will succeed, but the context switch to source will fail.

When you disconnect from a datastore, the source and target context (as applicable) is cleared if that datastore was currently specified as the context.

Setting the subscription context

When you add a new subscription, its source and target datastores are controlled by the current context and the new subscription is automatically set as the current context. The subscription context can be changed at any time by executing the select subscription command:
select subscription name SUB1;

When you delete a subscription, the subscription context is cleared.

Setting the table mapping context

When you add a new table mapping, the table mapping is added to the subscription that is the current context and the new table mapping is automatically set as the current context. The table mapping context can be changed at any time by executing the command:
select table mapping…

The select table mapping command has various optional parameters to identify which table mapping to select. You do not need to specify all parameters. The command will succeed if a unique table mapping is identified, otherwise the command will report an error. For example, to select a table mapping based on the name of a source table, execute the following command:

select table mapping sourcetable TABLE1;

When you delete a table mapping, the table mapping context is cleared.