PreviousNextIndex

DEFINE WORK-TABLE statement

Defines a work table (a temp-table stored in memory) for use in one or more procedures, or within a single class.

This statement is supported only for backward compatibility. Use the DEFINE TEMP-TABLE statement, instead.

Syntax

DEFINE { [ [ NEW ] SHARED ] | [ PRIVATE ] } 
  { WORK-TABLE | WORKFILE } work-table-name [ NO-UNDO ] 
  [ LIKE tablename [ VALIDATE ] ] 
  [ FIELD field-name { AS data-type | LIKE field } 
    [ field-options ] ] ... 

NEW SHARED { WORK-TABLE | WORKFILE } work-table-name
SHARED { WORK-TABLE | WORKFILE } work-table-name
[ PRIVATE ] { WORK-TABLE | WORKFILE } work-table-name
{ WORK-TABLE | WORKFILE } work-table-name
NO-UNDO
LIKE table-name
VALIDATE
FIELD field-name
AS data-type
LIKE field
field-options
Example

The 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.SalesRegion, Customer.State, and Customer.Balance fields, respectively.

The first FOR EACH loop in 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.

r-wrkfil.p
DEFINE WORK-TABLE showsales 
  FIELD region    LIKE SaleRrep.Region LABEL "Region" 
  FIELD state     LIKE Customer.State LABEL "St" 
  FIELD tot-sales LIKE Customer.Balance COLUMN-LABEL "Total!Sales". 
FOR EACH Customer, SalesRep OF Customer BREAK BY Customer.State: 
  ACCUMULATE Customer.Balance (TOTAL BY Customer.State). 
  IF LAST-OF(Customer.State) THEN DO: 
    CREATE showsales. 
    showsales.state = Customer.State. 
    showsales.tot-sales = ACCUM TOTAL BY Customer.State Customer.Balance. 
    showsales.region = SalesRep.Region. 
  END. 
END. 
FOR EACH showsales BREAK BY showsales.region BY showsales.state: 
  IF FIRST-OF(showsales.region) THEN 
    DISPLAY showsales.region. 
  DISPLAY showsales.state tot-sales (TOTAL BY showsales.region). 
END. 

Notes
See also

{ } Argument reference, { } Include file reference, Class-based data member access, CREATE statement, DEFINE BUFFER statement, DEFINE TEMP-TABLE statement, FIND statement, Format phrase, RUN statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex