PreviousNextIndex

DEFINE BUFFER statement

ABL provides you with one default buffer for each table or temp-table that you use in a procedure or class. ABL uses that buffer to store one record at a time from the table as the records are needed during the procedure or class. If you need more than one record or buffer at a time for a table, you can use this statement to define alternate buffers that are created at compile time for use in one or more procedures, or within a single class or class hierarchy.

Syntax

DEFINE { [ [ NEW ] SHARED ] | [ PRIVATE | PROTECTED ] [ STATIC ] } 
  BUFFER buffer-name  
  FOR [ TEMP-TABLE ] table-name  
  [ PRESELECT ] [ LABEL label-name ] 
  [ NAMESPACE-URI namespace ] [ NAMESPACE-PREFIX prefix ] 
  [ XML-NODE-NAME node-name ] 

NEW SHARED BUFFER buffer-name
SHARED BUFFER buffer-name
[ PRIVATE | PROTECTED ] [ STATIC ] BUFFER buffer-name
BUFFER buffer-name
FOR [ TEMP-TABLE ] table-name
PRESELECT
LABEL label-name
NAMESPACE-URI namespace
NAMESPACE-PREFIX prefix
XML-NODE-NAME node-name
Examples

This procedure allows the user to create a new Customer record. Initially, the City, State, and Country fields are not shown. After the user enters a PostalCode value, the procedure searches for an existing Customer with the same postal code. If such a Customer is found, the City, State, and Country values from that record are displayed in the fields for the new record. The user can then update those fields.

r-defb.p
DEFINE BUFFER other-cust FOR Customer. 
FORM Customer WITH FRAME cre-cust. 
ON LEAVE OF Customer.PostalCode DO: 
  FIND FIRST other-cust  
    WHERE other-cust.PostalCode = Customer.PostalCode:SCREEN-VALUE  
    AND other-cust.CustNum <> Customer.CustNum NO-ERROR. 
  IF AVAILABLE other-cust THEN 
    DISPLAY other-cust.City @ Customer.City 
      other-cust.State @ Customer.State  
      other-cust.Country @ Customer.Country 
      WITH FRAME cre-cust.  
  ENABLE Customer.City Customer.State Customer.Country WITH FRAME cre-cust. 
END. 
CREATE Customer. 
UPDATE Customer EXCEPT Customer.City Customer.State Customer.Country 
   WITH FRAME cre-cust. 

The following gather a group of records so that the user can enter any table name and any set of record selection criteria and then look at the records in the table that meet those criteria:

r-defb2.p
DEFINE VARIABLE fname      AS CHARACTER NO-UNDO 
  FORMAT "x(12)" LABEL "Table name". 
DEFINE VARIABLE conditions AS CHARACTER NO-UNDO 
  FORMAT "x(60)" LABEL "Conditions". 
REPEAT: 
  /* Get the name of a table and, optionally, some record selection criteria */ 
  UPDATE fname COLON 12 conditions COLON 12 
    WITH SIDE-LABELS 1 DOWN. 
  HIDE ALL. 
  IF conditions <> "" THEN 
    /* Pass the table name and the record selection criteria as parameters */ 
    RUN r-defb3.p fname "WHERE" conditions. 
  ELSE  
    RUN r-defb3.p fname. 
END. 

The r-defb2.p procedure gets the name of a table (such as Customer) and a condition (such as CreditLimit > 4000) and passes them as arguments to the r-defb3.p procedure:

r-defb3.p
DEFINE NEW SHARED BUFFER rec FOR {1} PRESELECT. 
DEFINE VARIABLE flist AS CHARACTER NO-UNDO EXTENT 12. 
DEFINE VARIABLE ix    AS INTEGER   NO-UNDO. 
/* Look in _File for the table named in the fname variable */ 
FIND _File "{1}". 
/* Store the table’s field names in the first array */ 
FOR EACH _Field OF _File USE-INDEX _Field-Posit: 
  IF i >= 12 THEN LEAVE. 
  i = i + 1. 
  flist[i] = _Field._Field-Name. 
END. 
/* Preselect records */ 
DO PRESELECT EACH rec {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}: 
  /* Pass the filenames and all field names to r-defb4.p */ 
  RUN r-defb4.p "{1}" flist[1] flist[2] flist[3] flist[4] flist[5] flist[6]  
    flist[7] flist[8] flist[9] flist[10] flist[11] flist[12]. 
END. 

The r-defb3.p procedure:

The r-defb4.p procedure has access to the rec buffer (and through it to the set of preselected records). This connection is made by using PRESELECT on the DEFINE SHARED BUFFER statement. The r-defb4.p procedure displays those records.

r-defb4.p
DEFINE SHARED BUFFER rec FOR {1} PRESELECT. 
REPEAT: 
  FIND NEXT rec. 
  DISPLAY {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13}  
    WITH 1 COLUMN 1 DOWN. 
END. 

Because r-defb3.p and r-defb4.p use run-time argument passing, they cannot be precompiled. Having separate versions of r-defb4.p for each table and running the appropriate one in r-defb3.p, should improve response time. This approach is worthwhile if there are many lines of code in r-defb4.p a procedure.

If you define a NEW SHARED BUFFER in a procedure, then call a subprocedure that puts a record into that buffer, and display the buffer in the main procedure, the AVM displays this message:

Missing FOR, FIND or CREATE for Customer. 

This message is displayed when the FIND statement is not in the main procedure:

/* Main procedure */ 
DEFINE NEW SHARED BUFFER x FOR Customer. 
RUN proc2.p. 
DISPLAY x. 

/* proc2.p */ 
DEFINE SHARED BUFFER x FOR Customer. 
FIND FIRST x. 

To avoid this, explicitly scope the Customer record to the main procedure block. For example:

/* Main procedure */ 
DEFINE NEW SHARED BUFFER x FOR Customer. 
RUN proc2.p. 
DO FOR x: 
  DISPLAY x. 
END. 

For examples of instance and static buffer data member definitions, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.

Notes
See also

Class-based data member access, CREATE BUFFER statement, DEFINE PARAMETER statement, RUN statement, RUN STORED-PROCEDURE statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex