Archive Actions

Archive provides a facility that allows you to define actions to be executed at one or more predefined points (action events) during an Archive, Delete, or Restore Process. Each action event can have only one SQL statement associated with it, although action events can share an SQL statement association.

Note: Any Restore Actions in the Access Definition can be overridden, disarmed, or augmented in the Table Map for the Restore Process. For details, see Archive Actions .

Action SQL statements are different from and should not be considered interchangeable with SQL WHERE clauses created to select data for processing. (See SQL WHERE Clause Specifications for information about this feature.)

ACTIONS Primary Command

To define an Archive Action, invoke the Select an Action to Be Defined panel from the Select Tables/Views for AD panel using the ACTIONS primary command with the desired table name as an operand. You can also enter the ACTIONS primary command and position the cursor on the desired table name in the Table List before pressing ENTER.

ACT Line Command

Alternatively, use the ACT line command to display the scrollable Select an Action to Be Defined panel.

Figure: Select an Action To Be Defined

-- Select Tables/Views for AD: GRP.FOPDEMO.AD ---------------------------------
Command ===>                                                  Scroll ===> PAGE

 Pr +--------- Select an Action To Be Defined for FOPDEMO.CUSTOMERS -----+ UBS
    ¦                                                                    ¦
    ¦                                                            1 of 12 ¦
Def ¦ Cmd              Action Description            Active  Shr         ¦ E>>
Sta ¦ --- ------------------------------------------ ------  ---         ¦  >>
Sta ¦ *** ************************ TOP *************************         ¦  >>
    ¦ ___ Before Extract of the First Row From a Table  N     N          ¦
Cmd ¦ ___ Before Extract of a Row From a Table          N     N          ¦
--- ¦ ___ After Extract of a Row From a Table           N     N          ¦
*** ¦ ___ After Extract of Last Row From a Table        N     N          ¦
ACT ¦ ___ Before Delete of the First Row From a Table   N     N          ¦
___ ¦ ___ Before Delete of a Row From a Table           N     N          ¦
___ ¦ ___ After Delete of a Row From a Table            N     N          ¦
___ ¦ ___ After Delete of the Last Row From a Table     N     N          ¦
*** ¦ ___ Before Restore of the First Row To a Table    N     N          ¦
    ¦                                                                    ¦
    ¦ Line Commands: (S)elect, (INF)ormation, (CLR)Clear                 ¦
    ¦                                                                    ¦
    +--------------------------------------------------------------------+

Panel

The Select an Action To Be Defined panel includes:

Cmd
The line command entry area. Valid commands are:
S
Select the action event.
INF
Display a list of action events that share the action statement.
CLR
Clear the action statement association for the action event.
Action Description
Event for the action. Select:
  • Before Extract of the First Row From a Table
  • Before Extract of a Row From a Table
  • After Extract of a Row From a Table
  • After Extract of Last Row From a Table
  • Before Delete of the First Row From a Table
  • Before Delete of a Row From a Table
  • After Delete of a Row From a Table
  • After Delete of the Last Row From a Table
  • Before Restore of the First Row To a Table
  • Before Restore of a Row To a Table
  • After Restore of a Row To a Table
  • After Restore of the Last Row To a Table
Active
Indicator for association with action statement.
N
No action statement is associated with the event.
Y
An action statement is associated with the event.
Shr
Indicator for shared status of an action statement.
N
No associated action statement or action statement is not shared.
Y
Associated action statement is shared with another action.
Y*
Associated action statement is defined for this action and shared with another action.

Shared SQL Statements

When an action statement is shared by action events, an asterisk after the Y under Shr indicates the primary action event, or the event that owns the shared action statement. Use the INF line command, as shown in the figure, to list action events that share the statement associated with the primary action.

Figure: Shared Actions List at INF Command

 +--------- Select an Action To Be Defined for FOPDEMO.CUSTOMERS -----+
 ¦                                                                    ¦
 ¦                                                            1 of 12 ¦
 ¦ Cmd              Action Description            Active  Shr         ¦
 ¦ --- -----                                                          ¦
 ¦ *** ***** +-----Before Extract of the First Row From a Table-----+ ¦
 ¦ INF Befor ¦                SQL Shared With                1 OF 2 ¦ ¦
 ¦ ___ Befor ¦ ---------------------------------------------        ¦ ¦
 ¦ ___ After ¦ ******************** TOP ********************        ¦ ¦
 ¦ ___ After ¦ After Extract of a Row From a Table                  ¦ ¦
 ¦ ___ Befor ¦ Before Delete of the First Row From a Table          ¦ ¦
 ¦ ___ Befor ¦ ****************** BOTTOM *******************        ¦ ¦
 ¦ ___ After +------------------------------------------------------+ ¦
 ¦ ___ After                                                          ¦
 ¦ ___ Before Restore of the First Row To a Table    N     N          ¦
 ¦ ___ Before Restore of a Row To a Table            N     N          ¦
 ¦ ___ After Restore of the First Row To a Table     N     N          ¦
 ¦ ___ After Restore of a Row To a Table             N     N          ¦
 ¦                                                                    ¦
 ¦ Line Commands: (S)elect, (INF)ormation, (CLR)Clear                 ¦
 ¦                                                                    ¦
 +--------------------------------------------------------------------+

Define the Action

Use the S or SEL line command to select one or more action events. Archive displays the Enter an SQL Statement panel for each selection, in sequence.

Figure: SQL Statement

------- Enter an SQL Statement to be used by the Action Being Defined ---------
Command ===>                                                  Scroll ===> PAGE

              Before Extract of the First Row From a Table
Cmd                                                                   1 of 5
--- ------------------------------------------------------------------------
*** ********************************* TOP **********************************
___
___
___
___
___
*** ******************************* BOTTOM *********************************

Line Commands: (I)nsert, (D)elete, (R)epeat, (M)ove, (C)opy
Use the LIST COLUMNS command to add column names, if needed
Use the LIST VARIABLES command to add Action Variables, if needed
Use the SQLEdit command to invoke the ISPF editor with all of its facilities
Use the SHARESQL command to select an Action whose SQL you wish to use
Use the COPYSQL command to select an Action whose SQL you wish to copy 

Use this panel to enter the complete action statement or call to a stored procedure that is executed when the action event occurs during processing. For example, you might use an action statement to record deletions by inserting the primary key value into a table before deleting the row. As another example, you can place an indicator in a row that has been restored so that it will not be archived a second time or can be deleted in normal database maintenance procedures.

Type the desired SQL in the panel. The scrollable area displays the SQL in segments of 8 lines of 72 positions each. A maximum of 425 lines is available for the SQL and documenting comments. Notation next to it indicates the number of lines and the relative position of the first visible line.

Standard DB2 conventions apply to comments; each line must begin with two hyphens (--).

Note: You must leave a space after a comma that precedes a numeric value if the DB2 setup specifies a comma as the decimal point value.

Line Commands

You can perform several editing functions using line commands. The functions and corresponding line commands are:

Copy
Cn, CC
Insert
In
Repeat
Rn, RR
Delete
Dn, DD
Move
Mn, MM

Use A (After) or B (Before) to indicate the destination for a Copy or Move line command.

Column Variables

A column variable can be used in the statement for any action event except one executed before processing the first row or after processing the last row. The column variable must be preceded by a colon (:) in the statement.

Substitution Variables

You can use a substitution variable that has been defined on the Substitution Variable Display panel. The name of the substitution variable must be preceded by a colon (:). (For more information, see Substitution Variables.)

Note: If you created a Substitution Variable with the same name as a Column Variable (e.g., :ZIP), you may want to edit the substitution variable name if you want to use it in an SQL Statement because Optim will assume the variable is a Column Variable, not a Substitution Variable, as intended.

Action Variables

Action Variables are built-in functions that can be used to return information about the specific Archive, Delete, or Restore Action. An Action Variable must be preceded by a colon (:) in the statement.

For users of action variables with releases of Optim prior to 7.2: Optim 7.2 increased processing limits and changed the precision for some action variables. In Optim 6.1 and earlier, precision was integer for the following variables. With Optim 7.2 and later, precision for the listed variables is bigint. Depending on the way in which you use these variables, you may need to make changes to accommodate the difference in data type. For example, if a variable inserts a value into a DB2 table, ensure that the destination column is defined to allow a bigint value.

The following General Variables are available to all action statements.

FOP_ACTION
A code that identifies the event for the action. Return Value Type: integer
FOP_ACTION_TEXT
A text string that identifies the event for the action. Return Value Type: char (20)
FOP_ARCHIVE_FILE_NAME
Name of the Archive File being processed. Return Value Type: char (44)
FOP_INDEX_FILE_NAME
Name of any index file for the Archive File. Return Value Type: char (44)
FOP_GROUP_NAME
Group name, if any, for the Archive File. Return Value Type: char (8)
FOP_USER_ID
TSO ID for the user that created the Archive File. Return Value Type: char (8)
FOP_SERVER_NAME
DB2 subsystem on which the operation is being executed. Return Value Type: char (4)
FOP_ARCHIVE_DESC
Description, if any, for the Archive File. Return Value Type: char (40)
FOP_START_DATETIME
Date and time the current operation began. Return Value Type: timestamp
FOP_CURRENT_DATETIME
Current date and time. Return Value Type: timestamp
FOP_START_TABLE_ID
Creator ID of the Start Table. Return Value Type: char (128)
FOP_START_TABLE_NAME
Name of the Start Table. Return Value Type: char (128)
FOP_ACCESS_DEF_NAME
Three-part name of the Access Definition, separated by periods. Return Value Type: char (30)
FOP_BATCH_ONLINE_FLAG
B for batch execution; O for online execution. Return Value Type: char (1)
FOP_BATCH_JOBNAME
Job name if batch execution; TSO User ID if online execution. Return Value Type: char (8)
FOP_PROCESS_TYPE
A if Archive operation; B if Archive operation with delete (whether or not deferred); R if Restore operation; D if Delete operation. Return Value Type: char (1)
FOP_RETURN_CODE
For CALL statements only. Return code supplied by the called stored procedure. Return Value Type: integer
FOP_RETURN_MESSAGE
For CALL statements only. Optional text message supplied by the called stored procedure if FOP_RETURN_CODE is 2. Return Value Type: char (80)

FOP_ACTION and FOP_ACTION_TEXT return the following values:

FOP_ACTION 0
FOP_ACTION_TEXT BefExtFirstRow
FOP_ACTION 2
FOP_ACTION_TEXT BefExtRow
FOP_ACTION 3
FOP_ACTION_TEXT AftExtRow
FOP_ACTION 4
FOP_ACTION_TEXT AftExtLastRow
FOP_ACTION 5
FOP_ACTION_TEXT BefDelFirstRow
FOP_ACTION 7
FOP_ACTION_TEXT BefDelRow
FOP_ACTION 8
FOP_ACTION_TEXT AftDelRow
FOP_ACTION 9
FOP_ACTION_TEXT AftDelLastRow
FOP_ACTION 11
FOP_ACTION_TEXT BefRestFirstRow
FOP_ACTION 13
FOP_ACTION_TEXT BefRestRow
FOP_ACTION 14
FOP_ACTION_TEXT AftRestRow
FOP_ACTION 15
FOP_ACTION_TEXT AftRestLastRow

The following Extract Variables are available to Extract action statements.

FOP_TOTAL_ROWS_EXTRACTED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of rows processed at this point. (See Note.) Return Value Type: bigint
FOP_ARCHIVE_CRITERIA
First 220 bytes of criteria used in the Archive operation. If no criteria were specified, returns a zero-length string. Return Value Type: varchar (220)
FOP_SRCTBL_CREATOR_ID
Creator ID for the source table being processed. Return Value Type: char (128)
FOP_SRCTBL_NAME
Name of the source table being processed. Return Value Type: char (128)
FOP_TBL_ROWS_EXTRACTED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of rows from the table being processed. (See Note.) Return Value Type: bigint
FOP_REFERENCE_TABLE
Y if table is a reference table, N if not. Return Value Type: char (1)
FOP_ARCHIVE_DELETE_DATA
Y if delete after archive was specified for the table, N if not. Return Value Type: char (1)

The following Restore/Delete Variables are available to Restore and Delete action statements.

FOP_ARCHIVE_ID
A unique and arbitrary number of no logical significance that is assigned to the Archive File being processed. Since this value is unique for each Archive File, it can serve as a DB2 index, if needed. Return Value Type: integer
FOP_TOTAL_ROWS_PROCESSED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of all rows processed. (See Note.) Return Value Type: bigint
FOP_TOTAL_ROWS_REMAINING_TO_BE_PROCESSED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of all rows remaining to be processed. (See Note.) Return Value Type: bigint
FOP_TOTAL_ROWS_IN_ERROR
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of all rows in error. Return Value Type: bigint
FOP_SRCTBL_CREATOR_ID
Creator ID of the source table being processed. Return Value Type: char (128)
FOP_SRCTBL_NAME
Name of the source table being processed. Return Value Type: char (128)
FOP_DSTTBL_CREATOR_ID
(For Restore only.) Creator ID for the destination table being processed. Return Value Type: char (128)
FOP_DSTTBL_NAME
(For Restore only.) Name of the destination table being processed. Return Value Type: char (128)
FOP_TBL_ROWS_PROCESSED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of rows from the table that are processed. (See Note.) Return Value Type: bigint
FOP_TBL_ROWS_REMAINING_TO_BE_PROCESSED
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of rows from the table that remain to be processed. (See Note.) Return Value Type: bigint
FOP_TBL_ROWS_IN_ERROR
Note: Prior to Optim 7.2, the return value type for this variable was integer.
Count of rows from the table that are in error at this point. Return Value Type: bigint
FOP_AFTER_ROW_STATUS
Status code returned by DB2 after processing a row. Return Value Type: integer
Note: Any row count value (e.g., FOP_TBL_ROWS_PROCESSED) that is returned does not include the current row for Before Row events, but does include the current row for After Row events. For example, FOP_TBL_ROWS_PROCESSED for the first row of a table returns 0 for Before Row actions, and 1 for After Row actions.

An example of Action Variable usage is shown in the following figure:

Figure: SQL Statement Using Action Variable

------- Enter an SQL Statement to be used by the Action Being Defined ---------
Command ===>                                                  Scroll ===> PAGE

              Before Extract of the First Row From a Table
Cmd                                                                   1 of 3
--- ------------------------------------------------------------------------
*** ********************************* TOP **********************************
___ INSERT INTO FOPDEMO.ARCHIVE_ACTION
___ (ARCHIVE_CUSTID, ARCHIVE_FILE)
___ VALUES (CUST_ID, :FOP_ARCHIVE_FILE_NAME);
*** ******************************* BOTTOM *********************************

Line Commands: (I)nsert, (D)elete, (R)epeat, (M)ove, (C)opy
Use the LIST COLUMNS command to add column names, if needed
Use the LIST VARIABLES command to add Action Variables, if needed
Use the SQLEdit command to invoke the ISPF editor with all of its facilities
Use the SHARESQL command to select an Action whose SQL you wish to use
Use the COPYSQL command to select an Action whose SQL you wish to copy 

Before each row is extracted, this action statement inserts CUST_ID and ARCHIVE_FILE name values (using the Action Variable FOP_ARCHIVE_FILE_NAME) into table FOPDEMO.ARCHIVE_ACTION.

Calls to Stored Procedures

An Action statement can call a stored procedure using one or both parts of the name (i.e., userid.procname). If one part is used, the current User ID is assumed as the prefix.

Parameters passed with the CALL statement must be enclosed in parentheses. The number of parameters must be the same as the number in the procedure and must be passed in the same order. If the stored procedure does not require parameters, the CALL statement can pass an empty parameter list ( ) or omit the parentheses.

The CALL statement parameter list may include column variables, substitution variables, Action Variables, and constants.

LIST COLUMNS

Use the LIST COLUMNS primary command to display a list of column variables for the table. You can scroll this list and use the S line command to select a column variable from it. The selected column variable is added to the end of the action statement.

LIST SUBS

Use the LIST SUBS primary command to display a list of substitution variables. You can scroll this list and use the S line command to select a substitution variable from it. The selected substitution variable is added to the end of the action statement.

LIST VARIABLES

Use the LIST VARIABLES command to display a list of Action Variables when formulating an action statement. Use the S line command to select a variable from the list. The selected variable is added at the end of the action statement.

SQLEDIT

Use the SQLEDIT command to invoke an ISPF edit session for the displayed action statement. All standard ISPF facilities are available. Use the ISPF COPY command to insert data from a file and edit as desired.

Use END to terminate the ISPF session and redisplay the Enter an SQL Statement panel. The edited data is inserted into the panel.

SHARESQL

Use the SHARESQL command to select an action event that owns the action statement you wish to associate with the current action. A list of available action events is displayed. You can scroll this list and use the S line command to select a desired event. The statement associated with the selected event is inserted into the action statement, overwriting anything already entered. You can edit the shared statement. If so, it is changed for all actions for which it is active.

COPYSQL

Use the COPYSQL command to select an event that owns the action statement you wish to copy to the current event. A list of available events is displayed. You can scroll this list and use the S line command to select a desired event. The action statement for the selected event is inserted at the end of your entry. Editing the action statement does not affect the statement from which it is copied.

Specification Complete

Use END to save the contents of the SQL Editor and return to the Select an Action To Be Defined panel. Use END again to return to the Select Tables/Views for AD panel. When the Select Tables/Views for AD panel is redisplayed, Status contains ACT to indicate that an Archive Action has been specified for the selected table.