You are on page 1of 7

Create Procedure Templates

A procedure template is an artifact containing a base script with predefined


placeholders for objects such as tables, views and columns. The procedure template
enables you to create procedures that contain the same script, but with different
values.

Procedure
1. Open the New File wizard.

After you have created your workspace and your project, go to the Project
Explorer view in the SAP HANA Development perspective, right-click on the file
name, choose New  File. The New File wizard appears.

2. Enter or select the parent folder and enter the file name using the following naming
convention <filename>.proceduretemplate.

3. Choose Finish.

The Template Script editor opens.

4. Define the template parameters.


Click the   icon from the toolbar in the Template Parameters table to add a
parameter to the table. You can rename the parameter and give it a meaningful
name. Add the parameters to the table and to the script where they are used as a
placeholder for the following objects:

 Schema name

 Table name and table column name

 View name and view column name

 Procedure name

The parameters can only be used in the procedure body, between the BEGIN
and END, and not as part of the procedure header. The parameters must
follow the SQL identifier semantics. Each parameter should be wrapped using
the less than (<) and greater than (>) symbols. For example:



SELECT <My_Column> FROM <My_Table>;

5. Commit and activate your procedure template.


Note:

To avoid errors during activation, you must make sure your procedure
template is consistent. For example:

 A parameter that is a placeholder for a table must be in a valid position


that is syntactically correct.

 A parameter name must be identical in the Template


Parameters table and the Template Script.

 You cannot add a parameter as a placeholder for other objects or


syntactic statements.

Create Procedure Template and


Instances
A procedure template instance is an artifact that is created from a procedure
template. It contains the same procedure script and uses specific values for the
predefined placeholders in the script. Procedure template instances are coupled with
the procedure template, which means any changes that are made to the template
are also applied to the template instances. During activation, a template instance is
generated as a procedure in the catalog.

Procedure
1. Open a New Procedure wizard.

a. Go to the Project Explorer view in the SAP HANA


Development perspective, right-click the file name, choose New  Other.
The New wizard appears.

b. Expand the Database Development folder and select Stored


Procedure. The New Procedure wizard appears.
2. Define the new procedure attributes.

Enter or select the parent folder, enter the file name, select XML (.procedure)
- Deprecated for the file format. Choose Advanced, select the Create from
procedure template checkbox , and choose Browse. Select the relevant
template, choose OK, and choose Finish.
3. In the Procedure Template Instance editor, add a value in the Value column
for each parameter, and choose Save.

4. Commit and activate your procedure template instance.

Note:

1. The value is the string that replaces the parameter in the template script.
During activation.

2. The procedure is created in the catalog using the values specified in the
instance with the active template in the repository.

3. A reference between the instance and its template is created to link them
together.
Update Procedure Templates and
Instances
The procedure template script and its parameters can be modified, which also
modifies the template instances that refer to it. Only the template parameter values
can be changed in the procedure template instances.

Procedure
1. To update a procedure template and its instances, double-click the relevant file in
the Project Explorer view. The file appears in the Template Script editor.

2. You can change the list of template parameters or the template script. Choose Save.

3. Commit and activate your procedure template and its instances.

Note:

1. If you change the list of template parameters, you should also update the instances
by choosing the   Refresh button to update the list of parameters and enter the
values.
2. During activation, the corresponding instances are reactivated and the changes are
applied accordingly.

Delete Procedure Templates and


Instances
A procedure template can be deleted if there are no instances linked to it. If there are
instances linked to the procedure template, they must be deleted before you can
delete the procedure template.

Procedure
1. To delete a procedure template or a procedure instance, right-click the relevant file in
the Project Explorer view, choose Delete, and choose OK.

2. Commit and activate the package.


Note:

1. If an error occurs during activation because there are instances linked to the
procedure template that you are trying to delete, then right-click the project name and
choose Team  Resolve.

You might also like