Progress
Language Reference
DEFINE WORK-TABLE Statement
Defines a work table (a temporary table stored in memory) for use within a procedure or within several procedures.
SYNTAX
NEW SHARED { WORK-TABLE | WORKFILE } work-table-name
Defines a work table to be shared by a procedure called directly or indirectly by the current procedure. The called procedure must name the same work table in a DEFINE SHARED WORK-TABLE statement. The WORKFILE keyword is allowed for backward compatibility only; using WORK-TABLE or WORKFILE has the same effect.
SHARED { WORK-TABLE | WORKFILE } work-table-name
Defines a work table that was defined by another procedure that used the DEFINE NEW SHARED WORK-TABLE statement. The WORKFILE keyword is allowed for backward compatibility only; using WORK-TABLE or WORKFILE has the same effect.
{ WORK-TABLE | WORKFILE }
Defines a work table whose records are available only within the current procedure. The WORKFILE keyword is allowed for backward compatibility only; using WORK-TABLE or WORKFILE has the same effect.
NO-UNDO
Specifies that Progress should not restore the record to its prior condition when a work table record is changed during a transaction and the transaction is undone. If you do not want the work table record undone even if it has changed during a transaction, use the NO-UNDO option with the DEFINE WORK-TABLE statement. NO-UNDO work tables are efficient; use them whenever possible.
LIKE table-name
Indicates the name of a table whose characteristics you want to use for the work table you are defining. All of the fields in this base table are also in the work table. If you reference a database table with the LIKE option, the database containing that table must be connected at compile time. It need not be connected at run time.
If more than one connected database contains a table named table-name, you must qualify the table name with the database name. See the Record Phrase description for more information.
HELP options are inherited from the table-name. Validate options are inherited only if the VALIDATE keyword is used.
VALIDATE
The work table fields inherit, from the dictionary, validation expressions and validation messages from the database table, table-name.
FIELD field-name
Identifies the name of a field in the work table.
AS datatype
Indicates the data type of the field or variable you are defining. The data types are CHARACTER, COM-HANDLE, DATE, DECIMAL, HANDLE, INTEGER, LOGICAL, RAW, RECID, ROWID, and WIDGET-HANDLE.
LIKE field
Indicates the name of the variable, database field, temporary table field, or work table field whose characteristics you want to use for the work table field you are defining. If you name a variable with this option, you must have defined that variable earlier in the procedure. The work table field inherits the data type, extents, format, initial value, label, and column label of the field. You can override specific values by using the FORMAT, LABEL, INITIAL, DECIMALS, and EXTENT options. If you do not use these options, the field or variable takes on the characteristics of the variable or database field you name.
If you reference a database field in the LIKE option, the database containing that field must be connected at both compile time and run time. Therefore, use the LIKE option with caution.
field-options
Specifies options for the temporary table field. Any options you specify override any options inherited through the LIKE option. This is the syntax for field-options.
For a description of each option, see the DEFINE VARIABLE Statement.
EXAMPLEThe
r-wrkfil.p
procedure accumulates all balances by state and stores that information for display later. The procedure uses a work table to accomplish this task.The
r-wrkfil.
p procedure defines the work table showsales. The work table contains the three fields named region, state, and tot-sales. These fields have all the same characteristics (except labels) as the customer.sales-region, customer.state, and customer.balance fields, respectively.The first FOR EACH loop in the the
r-wrkfil.p
procedure sorts customers by state. Then it accumulates the balances for each customer by state. When the procedure finds the last customer in a state, it creates a showsales record for that state. The procedure assigns information to the fields in the showsales record. After looking at each customer, the procedure continues to the next FOR EACH statement.The second FOR EACH statement in the
r-wrkfil.p
procedure uses the information stored in the showsales table. Because you treat a work table within a procedure the same way you treat a database table, you can perform the same work with the showsales table that you can with a database table.
NOTES
- You cannot perform a unique find on a work table. When finding records in a work table, you must use FIRST, LAST, NEXT, or PREV with the FIND statement, unless you are finding a record using its ROWID.
- You cannot define a field in a work table with the MEMPTR data type, but you can define a work table field as ROWID or RAW.
- You cannot define shared objects, work tables, or temporary tables within an internal procedure or user-defined function.
- Progress disregards the following when used in conjunction with a work table:
- When you use the AMBIGUOUS function in conjunction with a work table, the function always returns a value of FALSE.
- Complete work table definitions must be included in a DEFINE SHARED WORK-TABLE statement and shared work tables must be defined identically.
- These are the differences between work tables and regular database tables:
- Progress does not use the Progress database manager (and server for multi-user systems) when working with work tables.
- If you do not explicitly delete the records in a work table, Progress discards those records, and the work table, at the end of the procedure that initially defined the work table.
- Users do not have access to each other’s work tables.
- Because you cannot index a work table, Progress uses the following rules for storing records in a work table:
- If you create a series of work table records without doing any other record operations, Progress orders the newly created records in the order they were entered.
- If you use the FIND PREV statement at the beginning of a work table and then create a work table record, Progress stores that record at the beginning of the work table.
- When you use the FIND statement to find a work table record and then use the CREATE statement to create a new work table record, Progress stores that new record after the record you just found.
- Data handling statements that cause Progress to automatically start a transaction for a regular table will not cause Progress to automatically start a transaction for a work table. To start a transaction for operations involving a work table, Use the TRANSACTION keyword.
- Work tables are private:
- Even if two users define work tables with the same name, the work tables are private; one user cannot see records the other user has created.
- If two procedures run by the same user define work tables with the same name, Progress treats those work tables as two separate tables unless the SHARED option is included in both procedures.
- DEFINE SHARED WORK-TABLE does not automatically provide a shared buffer. If you want to use a shared buffer with a shared work table, you must define that buffer.
- Work table records are built in 64-byte sections. Approximately the first 60 bytes of each record are taken up by record specification information (or a record header). That is, if a record is 14 bytes long, it will be stored in two 64-byte sections, using the first 60 bytes as a record header. If the record is 80 bytes long, it will fit into three 64-byte sections. The first part contains 60 bytes of header information plus the first 4 bytes of the record. The second section contains 64 bytes of the record. And the last section contains the remaining record bytes.
- The NO-UNDO option in a work table definition overrides a transaction UNDO for CREATE, UPDATE, DELETE, and RELEASE statements accessing the work table, regardless of whether these statements are executed before or during the transaction block that is undone.
- A transaction UNDO overrides a FIND statement accessing a work table defined with the NO-UNDO option, regardless of whether the find is executed before or during the transaction that is undone.
- You should use the CASE-SENSITIVE option only when it is important to distinguish between uppercase and lowercase values entered for a character field. For example, use CASE SENSITIVE to define a field for a part number that contains mixed upper case and lowercase characters.
- A SHARED work table remains in scope for an instance of a persistent procedure until the instance is deleted. This is true even if the original procedure that defined the work table as NEW SHARED goes out of scope while the procedure instance remains persistent.
If a trigger or internal procedure of a persistent procedure executes an external subprocedure that defines a SHARED work table, Progress includes the persistent procedure in the resolution of the corresponding NEW SHARED work table as though the procedure were on the procedure call stack.
- You can specify a join between a temporary table or work table and any appropriate table using the OF keyword. The two tables must contain a commonly named field that participates in a unique index for at least one of the tables. For more information on table joins see the Record Phrase reference entry.
- See the Progress Programming Handbook for information on work tables and temporary tables.
SEE ALSO
{ } Argument Reference, { } Include File Reference, CREATE Statement, DEFINE BUFFER Statement, DEFINE TEMP-TABLE Statement, FIND Statement, Format Phrase, RUN Statement
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |