15-2
Objectives
• Create simple reusable procedures.• Add commands.• Provide options on your commands.• Run your procedures.• Use the procedure into a package
After completing this lesson, you will know how to:
15-3
What is a procedure?
Procedure – A sequence of commands executed by database engines, the operating system, or using ODI Tools. A procedure can define options that control its behavior.Procedures are reusable components that can be inserted into packages.
15-4
Procedure Examples
• Email Administrator procedure1. Uses the “SnpsSendMail” ODI tool to send an
administrative email to a user. The email address is an option.
• Clean Environment procedure1. Deletes the contents of the /temp directory using the
“SnpsFileDelete” tool.
2. Runs DELETE statements on these tables in order: CUSTOMER, CITY, REGION, COUNTRY.
15-5
Procedure Examples (cont.)
• Initialize Drive procedure1. Mount a network drive using an OS command (depending on an
option).
2. Create a /work directory on this drive.
• Identify Changes,then send an email procedure1. Wait for 10 rows to be inserted into the INCOMING table.
2. Transfer all the data from INCOMING to the OUTGOING table.
3. Dump the content of the OUTGOING table to a text file.
4. Email this text file to a user.
15-6
How to Create a New Procedure
1. Right-click the Procedures node under a project.
2. Select Insert Procedure3. Fill in the
• Name• Description
4. Optionally, define the default:• Source Technology• Target Technology
15-7
Creating a New Command
1. Select the procedure’s Details tab.2. Click the Add Command button3. Fill in the Name4. Set Ignore Errors as appropriate.5. For the Command on Target, select:
• Technology• Context• Logical Schema• Command code (using the
Expression Editor)6. Repeat step 5 for the
Command on Source (optional).7. Click OK.
15-8
Arranging Steps in Order
• The Details tab shows the steps of your procedure.
• Steps are executed top to bottom
• In this example, “Wait for data in INCOMING” is executed last.
• We need it to be executed first
• To rearrange steps, use the up and down buttons
• Now the procedure will wait for data before attempting the transfer.
• Make sure the order of your steps is correct.
15-9
Which Parameters Should Be Set?
• The following parameters should be set in the command:• Technology: If different from the one defined at technology level.• Logical Schema: For DBMS technologies (Jython, OS, ODI Tools
do not require a schema)• Context: If you want to ignore the execution context.• Ignore Errors: If the command must not stop the procedure. A
warning is issued only if the command fails.
15-10
Valid Types of Commands
Some examples of the types of commands that can be used in ODI procedures:
SQL statement
OS commands
ODI Tools
Jython programs
Executed on any DBMS technologyDELETE, INSERT, SELECT, … statements.
Executed on the Operating System technologyIn OS-specific syntax using shell commands or binary programs
Executed on the Sunopsis API technologyAny ODI tool command call.
Executed on the Jython technology.Jython code interpreted by the agent (Extensibility Framework).
15-11
More Elements
In addition, we have access to the following ODI-specific elements that can be used within the commands:
Variables
Sequences
User Functions
They may be specified either in substitution mode #<variable>, or in bind mode :<variable>
They may be specified either in substitution mode #<sequence>, or in bind mode :<sequence>
Used like DBMS functions. They are replaced at code generation time by their implementation.
15-12
Why Use a Source Command?
• The command sent to the source should return a result set which is manipulated by the default command.
• Example: Transferring data from a table to another.• Source Command: SELECT statement• Default Command: INSERT statement with source columns in
bind mode
15-13
Procedure Execution
• A procedure can be executed manually for testing.• Default option values are used.
• It is usually run from a package.• Add a procedure step by dragging and dropping.• Option values can be overridden at that time.
15-14
Using Operator to View the Results
• Procedure is executed as a session with one step
• One task for each command • Warning: error was ignored
• Tasks completed successfully
• Error that was not ignored
• Task waiting to be run.
15-15
Note – Procedure Steps Are References
A procedure used in
a package is
referenced by the
package, not
copied.
Changes to the
original procedure
also apply to the
package.
15-16
How to Create a Procedure Step
1. Under a project, select the procedure which you want to work with.
2. Drag and drop it into the package.
3. Set the step Name.There is only one type of procedure step.
4. Override any options on the Options tab.
15-17
Controlling Execution
• Each step may have two possible next steps:• Next step upon success • Next step upon failure
• If no next step is specified, the package stops.• Execution can branch:
• as the result of a step (success/failure)• because of an Evaluate Variable step
• Examples of control structures follow.
15-18
Error Handling
• Interfaces fail if a fatal error occurs or if the number of allowed errors is exceeded.
• Procedures and other steps fail if a fatal error occurs
• Try to take into account possible errors.
Simple error handling
15-19
How to Create a Loop
• Loops need a counter variable
1. Set the counter to an initial value2. Execute the step or steps to be repeated3. Increment the counter4. Evaluate counter value and loop to step 2 if the goal has been
reached
Package Loop 1. 2.
3.
4.
15-20
The Advanced Tab
• Each step’s Advanced tab allows you to specify the how the next step is determined.
• You can specify a number of automatic retries on failure.
How many times this step should be re-attempted if it fails
List of all possible package steps. Choose the one to be executed next if this one fails.
Where to go next if the step completes successfully
List of all possible package steps. Choose one to be executed next if this one succeeds.
Time interval (in seconds) between each attempt
Where to go next if this step fails
Specifies if step execution report is to be conserved in the Log.
Top Related