Routines are pieces of code or programs that you can call to perform
operations.
Stored procedures
A procedure (often called a stored procedure) is a program
that can be called to perform operations that can include both host language
statements and SQL statements. Procedures in SQL provide the same benefits
as procedures in a host language.
Use user-defined functions (UDFs)
In writing SQL applications, you can implement some actions or operations as a UDF or as a subroutine in your application: Although it may appear easier to implement new operations as subroutines in your application, you might want to consider the advantages of using a UDF instead.
Triggers
A trigger is a set of actions that are run automatically
when a specified change operation is performed on a specified table or view.
The change operation can be an SQL INSERT, UPDATE, or DELETE statement, or
an insert, update, or delete high-level language statement in an application
program. Triggers are useful for tasks such as enforcing business rules, validating
input data, and keeping an audit trail.
Debug an SQL routine
By specifying SET OPTION DBGVIEW = *SOURCE in your Create SQL Procedure, Create SQL Function, or Create Trigger statement, you can debug the generated program or module at the SQL statement level.
Improve performance of procedures and functions
When creating stored procedures and user-defined functions (UDFs),
the SQL procedural language processor on the iSeries™ does not always generate the
most efficient code. However, you can do some changes to reduce the number
of database engine calls needed and improve performance.