Using Pre - and Post-Session SQL Commands
Using Pre - and Post-Session SQL Commands
By PenchalaRaju.Yanamala
For information about configuring SAP Filters in the session properties, see the
PowerExchange for SAP NetWeaver User Guide.
For information about entering MQ filter conditions, see the PowerExchange for
IBM WebSphere MQ User Guide.
For more information about overriding SQL defined in the mapping, see
Overriding the SQL Query.
You can specify pre- and post-session SQL in the Source Qualifier
transformation and the target instance when you create a mapping. When you
create a Session task in the Workflow Manager you can override the SQL
commands on the Mapping tab. You might want to use these commands to drop
indexes on the target before the session runs, and then recreate them when the
session completes.
The Integration Service runs pre-session SQL commands before it reads the
source. It runs post-session SQL commands after it writes to the target.
You can use parameters and variables in SQL executed against the source and
target. Use any parameter or variable type that you can define in the parameter
file. You can enter a parameter or variable within the SQL statement, or you can
use a parameter or variable as the command. For example, you can use a
session parameter, $ParamMyPreSQL, as the source pre-session SQL
command, and set $ParamMyPreSQL to the SQL statement in the parameter
file.
Use any command that is valid for the database type. However, the Integration
Service does not allow nested comments, even though the database might.
Use a semicolon (;) to separate multiple statements. The Integration Service
issues a commit after each statement.
The Integration Service ignores semicolons within /* ...*/.
If you need to use a semicolon outside of comments, you can escape it with a
backslash (\).
The Workflow Manager does not validate the SQL.
Error Handling
You can configure error handling on the Config Object tab. You can choose to
stop or continue the session if the Integration Service encounters an error issuing
the pre- or post- session SQL command.
Using Pre- and Post-Session Shell Commands
The Integration Service can perform shell commands at the beginning of the
session or at the end of the session. Shell commands are operating system
commands. Use pre- or post-session shell commands, for example, to delete a
reject file or session log, or to archive target files before the session begins.
The Workflow Manager provides the following types of shell commands for each
Session task:
Use any valid UNIX command or shell script for UNIX nodes, or any valid DOS
or batch file for Windows nodes.
Configure the session to run the pre- or post-session shell commands.
The Workflow Manager provides a task called the Command task that lets you
configure shell commands anywhere in the workflow. You can choose a reusable
Command task for the pre- or post-session shell command. Or, you can create
non-reusable shell commands for the pre- or post-session shell commands.
If you create a non-reusable pre- or post-session shell command, you can make
it into a reusable Command task.
The Workflow Manager lets you choose from the following options when you
configure shell commands:
Configure pre- and post-session shell commands in the Components tab of the
session properties.
Related Topics:
Working with the Command Task
You can use parameters and variables in pre- and post-session commands. Use
any parameter or variable type that you can define in the parameter file. You can
enter a parameter or variable within the command, or you can use a parameter
or variable as the command. For example, you can include service process
variable $PMTargetFileDir in the command text in pre- and post-session
commands. When you use a service process variable instead of entering a
specific directory, you can run the same workflow on different Integration
Services without changing session properties. You can also use a session
parameter, $ParamMyCommand, as the pre- or post-session shell command,
and set $ParamMyCommand to the command in a parameter file.
Related Topics:
Where to Use Parameters and Variables
In the Components tab of the session properties, select Non-reusable for pre-
1.or post-session shell command.
Click the Edit button in the Value field to open the Edit Pre- or Post-Session
2.Command dialog box.
3.Enter a name for the command in the General tab.
If you want the Integration Service to perform the next command only if the
previous command completed successfully, select Fail Task if Any Command
4.Fails in the Properties tab.
5.In the Commands tab, click the Add button to add shell commands.
Enter one command for each line.
6.Click OK.
If you create non-reusable pre- or post-session shell commands, you can make
them into a reusable Command task. After you make the pre- or post-session
shell commands into a reusable Command task, you cannot revert back.
After you select the Make Reusable check box and click OK, a new Command
task appears in the Tasks folder in the Navigator window. Use this Command
task in other workflows, just as you do with any other reusable workflow tasks.
Use the following procedure to call an existing reusable Command task as the
pre- or post-session shell command for the Session task.
1.In the Components tab of the session properties, click Reusable for the pre- or
post-session shell command.
2.Click the Edit button in the Value field to open the Task Browser dialog box.
Select the Command task you want to run as the pre- or post-session shell
3.command.
Click the Override button in the Task Browser dialog box if you want to change
the order of the commands, or if you want to specify whether to run the next
4.command when the previous command fails.
Changes you make to the Command task from the session properties only apply
to the session. In the session properties, you cannot edit the commands in the
Command task.
Click OK to select the Command task for the pre- or post-session shell
5.command.
The name of the Command task you select appears in the Value field for the
shell command.
You can configure the session to stop or continue if a pre-session shell command
fails. If you select stop, the Integration Service stops the session, but continues
with the rest of the workflow. If you select Continue, the Integration Service
ignores the errors and continues the session. By default the Integration Service
stops the session upon shell command errors.
Validating a Session
The Workflow Manager validates a Session task when you save it. You can also
manually validate Session tasks and session instances. Validate reusable
Session tasks in the Task Developer. Validate non-reusable sessions and
reusable session instances in the Workflow Designer.
Edit the mapping in a way that might invalidate the session. You can edit the
mapping used by a session at any time. When you edit and save a mapping, the
repository might invalidate sessions that already use the mapping. The
Integration Service does not run invalid sessions.
You must reconnect to the folder to see the effect of mapping changes on
Session tasks.
When you edit a session based on an invalid mapping, the Workflow Manager
displays a warning message:
If you delete a shortcut to a source or target from the mapping, the Workflow
Manager does not mark the session invalid.
The Workflow Manager does not validate SQL overrides or filter conditions
entered in the session properties when you validate a session. You must validate
SQL override and filter conditions in the SQL Editor.
To validate a session, select the session in the workspace and click Tasks >
Validate. Or, right-click the session instance in the workspace and choose
Validate.
You can validate multiple sessions without fetching them into the workspace. You
must select and validate the sessions from a query results view or a view
dependencies list. You can save and optionally check in sessions that change
from invalid to valid status.
Note: If you use the Repository Manager, you can select and validate multiple
sessions from the Navigator.