Creating a Static Procedure for DB2 for VM

Creating a static TABLE request requires the data adapter SQL COMPILE facility; its sole function is to create static SQL code for TABLE requests. Creating a static MODIFY is an extension to the usual FOCUS procedure for compiling a FOCEXEC. Invoke the static creation process after you complete the FOCEXEC or MODIFY procedure.

In this section:

Write the FOCEXEC

Issue the SET STATIC Command for MODIFY Procedures

Compile the FOCEXEC

Exit FOCUS

Execute the GENUSQL EXEC

Authorize Users to Run the FOCEXEC

Run-time Requirements

Processing and Security Overview

DB2 for VM Static TABLE Example

DB2 for VM Static MODIFY Example

To begin the static TABLE creation process, execute the data adapter SQL COMPILE command (described in Using the SQL COMPILE and SQL RUN Facilities). You begin the static MODIFY creation process by issuing the data adapter SET STATIC command and executing the FOCUS COMPILE command.

In response, the data adapter automatically creates an Assembler program with the embedded SQL required by the procedure. Complete the process by exiting FOCUS and running an Information Builders-supplied EXEC that preprocesses, assembles, and links the program and creates a package in the DB2 for VM database.

This section outlines the steps required to create a static procedure, and provides a description of FOCUS processing for each step. DB2 for VM Static TABLE Example and DB2 for VM Static MODIFY Example provide annotated examples.

Creating a static procedure for DB2 for VM consists of the following steps:

  1. Write the procedure.

  1. For MODIFY, issue the SET STATIC command.

  2. Compile the FOCEXEC.

  3. Exit FOCUS.

  4. Execute the GENUSQL EXEC.

  5. Authorize users to run the FOCEXEC.

Note: Execute all steps in this procedure after logging on to a user ID authorized to connect to DB2 for VM and after meeting the run-time requirements documented in Invoking Relational Data Adapters.


Top of page

Write the FOCEXEC

You can create a static procedure from virtually any TABLE or MATCH FILE request. The default isolation level is CS and cannot be changed.

A MODIFY procedure must be compilable. Consult Static SQL Requirements and your FOCUS documentation on maintaining databases for more information on compiled MODIFY requirements. The default isolation level is Cursor Stability (CS). If the MODIFY procedure updates any tables, include the SQL SET ISOLATION RR command in the MODIFY itself, immediately following the MODIFY FILE command.


Top of page

Issue the SET STATIC Command for MODIFY Procedures

To create a static MODIFY procedure, you may need to issue the SET STATIC command. Omit this step to create a static TABLE procedure.

The syntax for the static SET command for DB2 for VM is

SQL [SQLDS] SET STATIC {OFF|ON}

where:

OFF
Reverses ON setting. OFF is the default setting.

ON
Invokes static processing.

Omit the SQLDS target database qualifier if you previously issued the SET SQLENGINE command for DB2 for VM.


Top of page

Compile the FOCEXEC

To compile a TABLE request, use the data adapter SQL COMPILE facility; you must then use the data adapter SQL RUN facility to run it. To compile a MODIFY procedure, use the FOCUS COMPILE facility.


Top of page

Reference: The SQL COMPILE and SQL RUN Commands for TABLE

The data adapter provides facilities for creating and running static TABLE procedures. Refer to Using the SQL COMPILE and SQL RUN Facilities for a complete description of the SQL COMPILE command, the SQL RUN command, SQL COMPILE and SQL RUN processing, host variable length considerations, and host variable placement.

FOCEXECs compiled with the Static SQL facility do not support the use of the LOAD command; to execute them, you must use the SQL RUN command.


Top of page

Syntax: How to Compile a Static MODIFY Procedure on VM

Before compiling the request, issue FILEDEF commands for all input and output files, such as transaction files or log files, that the MODIFY will use at run time. Any COMBINE structures must be in effect both before compiling the MODIFY and at run time.

Issue the COMPILE command

COMPILE focexec

where:

focexec
Is the name of the MODIFY procedure to compile.

You do not have to recompile or rebind FOCUS applications for different releases of a FOCUS Version. This saves time and effort.

For example, a FOCUS static MODIFY procedure compiled and bound in Version 7.0 Release 8, does not have to be recompiled or rebound for FOCUS Version 7.0 Release 9, or vice versa. However, the procedure must be recompiled and rebound for a different FOCUS Version (for example, FOCUS Version 7.2).

FOCEXECs compiled with the Static SQL facility do not support the use of the LOAD command; to execute them you must use the RUN command.

Note: The 'AS module' extension to the COMPILE command is not supported for static SQL procedures. The module name must be identical to the FOCEXEC name.


Top of page

Exit FOCUS

Issue the FIN command to exit from FOCUS before running the GENUSQL EXEC.


Top of page

Execute the GENUSQL EXEC

The GENUSQL EXEC preprocesses, assembles, links, and creates an application package for your static procedure. GENUSQL requires input parameters for execution; they acquire default values within the EXEC. To change the defaults at run time, provide overriding values on the command line in the form PARM=value. Use blanks as delimiters between parameter values; do not insert spaces on either side of the assignment symbol (=)

EX GENUSQL program [(parm=value parm=value] [DBLIST (db1 db2...dbn)]

where:

program
Is the name of the program to be prepared. It will have the same name as the MODIFY or TABLE FOCEXEC.

parm
Is one of the following:

SQLUID is the DB2 for VM user ID to be the creator of the package. Your VM logon ID is the default.

SQLPSWD is the DB2 for VM password associated with SQLUID. This is not the VM logon password. No password is required for the VM user ID default.

COLLID is the collection-ID, used as the qualifier for the DB2 for VM application package produced by the SQLPREP EXEC. If omitted from the parameter list, it defaults to the SQLUID (if specified), or to the current VM user ID (if SQLUID is not specified in the parameter list).

GRANT automatically grants run privilege on the package to PUBLIC. Possible values are YES or NO (the default).

EXPLAIN causes the DB2 for VM optimizer to update the user's EXPLAIN tables with access path information. Possible values are NO, the default, or YES, to update the EXPLAIN tables.

INDVAR removes null indicator variables in SQL predicates in the ASMSQL program used as input to GENUSQL. The existence of these variables may degrade performance in applications involving large DB2 for VM tables. Possible values are YES, the default, or NO (to remove the variables).

Note:

If you specify NO for INDVAR, no column referenced by a KEYS parameter or in a KEYFLD/IXFLD pair can allow nulls. Violation of this condition may cause unpredictable results. In addition, a setting of NO for INDVAR affects the total number of host variables to be applied towards the DB2 for VM limit of 512 (DB2 for VM Version 3 Release 3 and below).

db1...dbn
Is a list of databases. You can specify multiple databases as targets for storage of the application package. The default is the database specified in the most recently issued SQLINIT command.

Note:


Top of page

Authorize Users to Run the FOCEXEC

If you ran GENUSQL with GRANT=NO (the default), issue the SQL GRANT RUN command to authorize users to execute the packages created with the previous steps. The following example shows how to issue the command from within a FOCUS session:

SQL SQLDS GRANT RUN ON PLAN FEX1 TO USER1, USER2

For more information on GRANT, consult the IBM DB2 for VM SQL Reference.


Top of page

Run-time Requirements

In addition to the usual run-time requirements for the FOCUS DB2 for VM Data Adapter outlined in Invoking Relational Data Adapters, make sure that the FOCCOMP files for any compiled MODIFY procedures are on a minidisk that you accessed prior to invoking FOCUS.

The STUBLIB LOADLIB containing the run-time modules must reside on a minidisk that you accessed prior to invoking FOCUS. It is not necessary to GLOBAL the STUBLIB LOADLIB, as the FOCUS EXEC automatically does this. However, you must access the minidisk before invoking FOCUS.


Top of page

Processing and Security Overview

When you run a compiled FOCEXEC procedure, FOCUS searches for a module of the same name in the STUBLIB LOADLIB file.

When you run a compiled MODIFY procedure, FOCUS searches for a FOCCOMP file on one of the minidisks you accessed prior to invoking FOCUS. If the flag in the FOCCOMP file indicates that it is a static procedure, FOCUS searches the STUBLIB LOADLIB for a module of the same name. The data adapter compares consistency tokens in the FOCCOMP and STUBLIB files.

FOCUS then invokes the static FOCEXEC or MODIFY procedure, connects to DB2 for VM, and loads the package (which always has the same name as the FOCEXEC). DB2 for VM verifies that the STUBLIB load module for the program and the DB2 for VM package have the same owner, program name, and consistency token.

This process verifies that the compiled MODIFY (FOCCOMP file), the program load module (STUBLIB LOADLIB member), and the DB2 for VM application package are valid and that no substitutions have been made.

Note: There is no equivalent in DB2 for VM for the plan management techniques available for DB2. There must be a separate package for every static procedure, and one for the dynamic DB2 for VM Data Adapter. DB2 for VM switches packages automatically in response to program execution.


Top of page

DB2 for VM Static TABLE Example

The following annotated example illustrates the creation of a static FOCEXEC procedure named FEX1. This example uses a multi-table Master and Access File, EMPLOYEE, that relates two tables, PAYROLL and COURSES. DB2 Static TABLE Example provides the Master and Access Files.

The FEX1 FOCEXEC follows:

SQL SQLDS SET OPTIMIZATION ON
TABLE FILE EMPLOYEE
PRINT EMP_ID SALARY POINTS
WHERE SALARY GE &SALARY
END

The numbers 1 through 9 refer to the explanatory notes that follow the example. Also included for your information are the options FOCUS uses for each step (for example, assembler options). Please refer to the appropriate IBM manual for an explanation of these options and their possible settings.

1.  SQL SQLDS COMPILE FEX1 SALARY=50000
END

2. (FOC1472) STATIC SQL PROGRAM CREATED SUCCESSFULLY
3. FIN
Ready;

4. genusql fex1 (sqluid=user1 sqlpswd=myword grant=yes
Following installation parameters assumed:
Pgm = FEX1
Sqluid = USER1
Sqlpswd = MYWORD
Grant = YES
Indvar = YES
Collid =
5. ARI0717I START SQLPREP EXEC: 11/07/94 15:22:25 EST
ARI0320I THE DEFAULT DATABASE NAME IS SQLDBA.
ARI0663I FILEDEFS IN EFFECT ARE:
SYSIN DISK FEX1 ASMSQL *
SYSPRINT DISK FEX1 LISTPREP A1
SYSPUNCH DISK FEX1 ASSEMBLE A1
ARISQLLD DISK ARISQLLD LOADLIB G1
ARI0713I PREPROCESSOR ARIPRPA CALLED WITH THE FOLLOWING PARAMETERS:
........PREP=FEX1,USER=USER1/********,ISOL(USER),BLK,NOPR,DATE(ISO)
ARI0708I ALL SQLPREP EXEC PROCESSING COMPLETED SUCCESSFULLY.
ARI0796I END SQLPREP EXEC: 11/07/94 15:22:28 EST
6. Assembling of FEX1 completed successfully.

7. ARI0717I START SQLDBSU EXEC: 11/07/94 16:21:00 EST
ARI0659I LINE-EDIT SYMBOLS RESET:
LINEND=# LINEDEL=OFF CHARDEL=OFF ESCAPE=OFF TABCHAR=OFF
ARI0656I MESSAGE FILE (SYSPRINT): TERMINAL
ARI0655I INPUT FILE (SYSIN): TERMINAL
ARI0320I THE DEFAULT DATABASE NAME IS SQLDBA.
ARI0663I FILEDEFS IN EFFECT ARE:
ARISQLLD DISK ARISQLLD LOADLIB G1
SYSIN TERMINAL
SYSPRINT TERMINAL
ARI0801I DBS Utility started: 11/07/94 16:21:05.
AUTOCOMMIT = OFF ERRORMODE = OFF
ISOLATION LEVEL = REPEATABLE READ
ARI0828I ...LINEWIDTH reset to 80.
ARI0827I ...Begin command execution: ERRORMODE = CONTINUE
ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------>
------> CONNECT "USER1 " IDENTIFIED BY ********;
ARI8004I User USER1 connected to server SQLDBA.
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> GRANT RUN ON USER1.FEX1 TO PUBLIC;
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> COMMIT WORK;
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> EXIT
ARI8997I ...Begin COMMIT processing.
ARI0811I ...COMMIT of any database changes successful.
ARI0809I ...No errors occurred during command processing.
ARI0808I DBS processing completed: 11/07/94 16:23:39.
ARI0660I LINE-EDIT SYMBOLS RESTORED:
LINEND=# LINEDEL=¢ CHARDEL=@ ESCAPE=" TABCHAR=ON
ARI0796I END SQLDBSU EXEC: 11/07/94 16:23:39 EST
8. DMSCPY721I Copy ARIRVSTC TEXT G1 APPEND FEX1 TEXT A1 (old file)
IEW0000 INCLUDE OBJ
IEW0000 ENTRY ADDRESS
9. IEW0000 NAME FEX1(R)

Ready;

The steps in the process are:

  1. Issue the SQL COMPILE command.

  1. Create the Assembler program.

  1. Exit FOCUS.

  1. Invoke the GENUSQL EXEC.

  1. Prepare the Assembler program.

  1. Assemble the program.

  1. Grant the RUN privilege on the package.

  1. Add the Resource Manager stub.

  1. Link-edit the program.


Top of page

DB2 for VM Static MODIFY Example

The following annotated example illustrates the creation of a static MODIFY procedure named MOD1. The numbers 1 through 10 refer to the explanatory notes that follow the example.

Also included for your information are the options FOCUS uses for each step (for example, assembler options). Please refer to the appropriate IBM manual for an explanation of these options and their possible settings.

    >
sql sqlds set static on
>
1. compile mod1
>

SAMPLE SQLDS ON 07/30/91 AT 12.23.48
2. (FOC1472) STATIC SQL PROGRAM CREATED SUCCESSFULLY
3. COMPILED...
>
4. fin
Ready; T=0.16/0.27 12:23:54
5.  genusql mod1 (sqluid=admin sqlpswd=minnie grant=yes
Following installation parameters assumed:
Pgm = MOD1
Sqluid = ADMIN
Sqlpswd = MINNIE
Grant = YES
Indvar = YES
Collid =
6. ARI0717I START SQLPREP EXEC: 07/30/91 12:24:40 EDT
ARI0320I THE DEFAULT DATABASE NAME IS SQLDBA.
ARI0663I FILEDEFS IN EFFECT ARE:
OFFLINE PRINTER
SYSIN DISK MOD1 ASMSQL *
SYSPRINT DISK MOD1 LISTPREP A1
SYSPUNCH DISK MOD1 ASSEMBLE A1
ARISQLLD DISK ARISQLLD LOADLIB W1
ARI0713I PREPROCESSOR ARIPRPA CALLED WITH THE FOLLOWING PARAMETERS:
.. PREP=MOD1,USER=ADMIN/********,ISOL(USER),BLK,NOPR,DATE(ISO)
ARI0708I ALL SQLPREP EXEC PROCESSING COMPLETED SUCCESSFULLY.
ARI0796I END SQLPREP EXEC: 07/30/91 12:24:45 EDT

7. Assembling of MOD1 completed successfully.
8. ARI0717I START SQLDBSU EXEC: 07/30/91 12:24:52 EDT
ARI0659I LINE-EDIT SYMBOLS RESET:
LINEND=# LINEDEL=OFF CHARDEL=OFF ESCAPE=OFF TABCHAR=OFF
ARI0656I MESSAGE FILE (SYSPRINT): TERMINAL
ARI0655I INPUT FILE (SYSIN): TERMINAL
ARI0320I THE DEFAULT DATABASE NAME IS SQLDBA.
ARI0663I FILEDEFS IN EFFECT ARE:
ARISQLLD DISK ARISQLLD LOADLIB G1
SYSIN TERMINAL
SYSPRINT TERMINAL
ARI0801I DBS Utility started: 11/07/94 16:21:05.
AUTOCOMMIT = OFF ERRORMODE = OFF
ISOLATION LEVEL = REPEATABLE READ
ARI0828I ...LINEWIDTH reset to 80.
ARI0827I ...Begin command execution: ERRORMODE = CONTINUE
ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------>
------> CONNECT "ADMIN " IDENTIFIED BY ********;
ARI8004I User ADMIN connected to server SQLDBA.
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> GRANT RUN ON ADMIN.MOD1 TO PUBLIC;
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> COMMIT WORK;
ARI0500I SQL processing was successful.
ARI0505I SQLCODE = 0 SQLSTATE = 00000 ROWCOUNT = 0

ARI0870I Enter the command terminated by semicolon or enter
EXIT to end.
------> EXIT
ARI8997I ...Begin COMMIT processing.
ARI0811I ...COMMIT of any database changes successful.
ARI0809I ...No errors occurred during command processing.
ARI0808I DBS processing completed: 07/30/91 12:24:56.
ARI0660I LINE-EDIT SYMBOLS RESTORED:
LINEND=# LINEDEL=¢ CHARDEL=@ ESCAPE=" TABCHAR=ON
ARI0796I END SQLDBSU EXEC: 07/30/91 12:24:56 EDT
9. DMSCPY721I Copy ARIRVSTC TEXT W1 APPEND MOD1 TEXT A1 (old file)
IEW0000 INCLUDE OBJ
IEW0000 ENTRY STATICSQ
10. IEW0000 NAME MOD1(R)

Ready; T=0.70/0.93 12:25:05

The steps in the process are:

  1. Issue the FOCUS COMPILE command.

  1. Create the ASSEMBLER program.

  1. Create the compiled MODIFY.

  1. Exit FOCUS.

  1. Invoke the GENUSQL EXEC.

  1. Prepare the ASSEMBLER program.

  1. Assemble the program.

  1. Grant the RUN privilege on the package.

  1. Add the Resource Manager stub.

  1. Link-edit the program.


Information Builders