PreviousNextIndex

DEFINE PARAMETER statement

Defines a run-time parameter in an ABL procedure (internal or external), Windows dynamic link library (DLL) routine, UNIX shared library routine, or ActiveX control event procedure.

Note: To define run-time parameters of a user-defined function, or a method within a class (including constructors), see the Parameter definition syntax reference entry.

Each parameter requires its own DEFINE statement. The parameters must be specified in the RUN statement in the same order they are defined with DEFINE statements. In addition, the parameter types (INPUT, OUTPUT, INPUT-OUTPUT, RETURN, TABLE, TABLE-HANDLE, DATASET, DATASET-HANDLE, and BUFFER) specified in the DEFINE and RUN statements must agree. The corresponding data types and run-time values must also be compatible enough to allow the AVM to perform any necessary conversions.

Syntax

DEFINE { INPUT | OUTPUT | INPUT-OUTPUT | RETURN } PARAMETER parameter 
  { {   AS [ HANDLE TO ] primitive-type-name  
       | AS [ CLASS ] { object-type-name } 
       | LIKE field       } [ EXTENT [ constant ] ] }  
  [ [ NOT ] CASE-SENSITIVE ] 
  [ FORMAT string ] 
  [ DECIMALS n ] 
  [ INITIAL 
      { constant | { [ constant [ , constant ] ... ] } } ] 
  [ COLUMN-LABEL label ] 
  [ LABEL string ] 
  [ NO-UNDO ] 

DEFINE PARAMETER BUFFER buffer-name FOR [ TEMP-TABLE ] table-name 
  [ PRESELECT ] 

DEFINE { INPUT | OUTPUT | INPUT-OUTPUT } PARAMETER 
  {   TABLE FOR temp-table-name [ APPEND ] [ BIND ] [ BY-VALUE ] 
    | TABLE-HANDLE temp-table-handle [ BIND ] [ BY-VALUE ] 
    | DATASET FOR dataset-name [ APPEND ] [ BIND ] [ BY-VALUE ] 
    | DATASET-HANDLE dataset-handle [ BIND ] [ BY-VALUE ] 
  } 

INPUT PARAMETER
OUTPUT PARAMETER
INPUT-OUTPUT PARAMETER
RETURN PARAMETER
parameter
AS [ HANDLE TO ] primitive-type-name
AS [ CLASS ] { object-type-name }
object-type-name
CLASS
LIKE, CASE SENSITIVE, FORMAT, DECIMALS, INITIAL, COLUMN-LABEL, LABEL, NO-UNDO
EXTENT [ constant ]
PARAMETER BUFFER buffer-name FOR [ TEMP-TABLE ] table-name [ PRESELECT ]
TABLE FOR temp-table-name
TABLE-HANDLE temp-table-handle
DATASET dataset-name
DATASET-HANDLE dataset-handle
APPEND
BIND
BY-VALUE
Examples

In the following examples, the r-runpar.p procedure runs a subprocedure called r-param.p and passes the subprocedure an INPUT parameter. The subprocedure r-param.p displays the INPUT parameter.

r-runpar.p
RUN r-param.p (INPUT 10). 

r-param.p
DEFINE INPUT PARAMETER int-param AS INTEGER NO-UNDO. 
DISPLAY int-param LABEL "Integer input param" 
  WITH SIDE-LABELS. 

In the following example, the r-runpr1.p procedure runs a subprocedure called r-param1.p. This example illustrates the use of multiple parameters and shows that the parameters must be passed in the proper order and must be of the same data type. Note that if you do not specify a parameter type in the RUN statement, the AVM assumes it is an input parameter.

r-runpr1.p
DEFINE VARIABLE new-param AS CHARACTER NO-UNDO FORMAT "x(20)". 
DEFINE VARIABLE out-param AS DECIMAL   NO-UNDO. 
DEFINE VARIABLE in-param  AS INTEGER   NO-UNDO INITIAL 20. 
RUN r-param1.p (OUTPUT out-param, 10, OUTPUT new-param, in-param). 
DISPLAY out-param LABEL "Updated YTD Sales" SKIP new-param LABEL "Status"  
  WITH SIDE-LABELS. 

r-param1.p
DEFINE OUTPUT PARAMETER xout-param AS DECIMAL   NO-UNDO. 
DEFINE INPUT  PARAMETER newin      AS INTEGER   NO-UNDO. 
DEFINE OUTPUT PARAMETER xnew-param AS CHARACTER NO-UNDO. 
DEFINE INPUT  PARAMETER xin-param  AS INTEGER   NO-UNDO. 
FOR EACH Customer NO-LOCK: 
  xout-param = xout-param + Customer.Balance. 
END. 
DISPLAY xout-param LABEL "Balance" WITH SIDE-LABELS. 
ASSIGN 
  xout-param = xout-param + newin + xin-param 
  xnew-param = "Example Complete". 

In the following example, the r-runpr2.p procedure displays information from a database table and assigns the value of a database field to a variable called io-param. The variable is passed as an INPUT-OUTPUT parameter to a subprocedure called r-param2.p. The subprocedure r-param2.p performs a calculation on the INPUT-OUTPUT parameter, then passes it back to the main procedure. The r-runpr2.p assigns the value io-param to a database field, then displays io-param.

r-runpr2.p
DEFINE VARIABLE io-param AS INTEGER NO-UNDO. 
FOR EACH Item: 
  DISPLAY Item.ItemName Item.OnHand WITH 1 DOWN. 
  io-param = Item.OnHand. 
  RUN r-param2.p (INPUT-OUTPUT io-param). 
  Item.OnHand = io-param. 
  DISPLAY io-param LABEL "New Quantity On-hand". 
END. 

r-param2.p
DEFINE INPUT-OUTPUT PARAMETER io-param AS INTEGER NO-UNDO. 
DEFINE VARIABLE inp-qty AS INTEGER NO-UNDO. 
PROMPT-FOR inp-qty LABEL "Quantity Received?". 
ASSIGN inp-qty. 
io-param = io-param + inp-qty. 

The following example uses a buffer parameter. The procedure r-bufp.p passes the Customer buffer to the getCustomer internal procedure, which attempts to find a record using that buffer.

r-bufp.p
DEFINE BUTTON btnFind LABEL "Find Customer". 
DO WITH FRAME frCustomer WITH SIDE-LABELS: 
  ENABLE Customer.CustNum btnFind. 
  ON CHOOSE OF btnFind DO: 
    RUN getCustomer (Customer.CustNum:HANDLE, BUFFER Customer). 
    IF NOT ERROR-STATUS:ERROR THEN 
      DISPLAY Customer EXCEPT Customer.Comments WITH SIDE-LABELS. 
  END. 
  ON ENTRY OF Customer.CustNum 
    HIDE MESSAGE. 
END. 
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 
PROCEDURE getCustomer: 
  DEFINE INPUT PARAMETER  hWidget     AS HANDLE NO-UNDO. 
  DEFINE PARAMETER BUFFER bufCustomer FOR Customer. 
  FIND bufCustomer WHERE bufCustomer.CustNum =  
    INTEGER(hWidget:SCREEN-VALUE) NO-LOCK NO-ERROR. 
  IF NOT AVAILABLE bufCustomer THEN DO: 
    MESSAGE "Customer record not found." VIEW-AS ALERT-BOX. 
    RETURN ERROR. 
  END.  
END. 

The following example defines parameters for the DLL routine, MessageBox, which displays a message on the screen:

r-dllex1.p
DEFINE VARIABLE result AS INTEGER NO-UNDO. 
MESSAGE "  It’s a whole new world!" 
  VIEW-AS ALERT-BOX MESSAGE BUTTONS OK TITLE "ABL Message". 
RUN MessageBoxA (0, "  It’s a whole new world, again!!",  
  "ABL DLL access", 0, OUTPUT result). 
PROCEDURE MessageBoxA EXTERNAL "user32.dll": 
  DEFINE INPUT PARAMETER hwnd    AS LONG. 
  DEFINE INPUT PARAMETER mbtext  AS CHARACTER. 
  DEFINE INPUT PARAMETER mbtitle AS CHARACTER. 
  DEFINE INPUT PARAMETER style   AS LONG. 
  DEFINE RETURN PARAMETER result AS LONG. 
END. 

Notes
See also

DEFINE BUFFER statement, DEFINE VARIABLE statement, DELETE PROCEDURE statement, Parameter passing syntax, RUN statement, Type-name syntax, USING statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex