PreviousNextIndex

PROCEDURE statement

Defines an internal procedure as an ABL procedure or declares an internal procedure prototype for an external routine in a Windows dynamic link library (DLL) or UNIX shared library, or for an internal ABL procedure defined in an external procedure that is itself a super procedure of the declaration procedure. The following syntax boxes describe the syntax for each use of the statement, beginning with an internal procedure definition.

Syntax

PROCEDURE proc-name [ PRIVATE ] : 
  [ procedure-body ]  

This is the syntax to declare an internal procedure prototype for a routine in a Windows DLL or UNIX shared library, or for an internal ABL procedure defined in a super procedure:

Syntax
PROCEDURE proc-name  
  {   EXTERNAL "dllname" [ CDECL | PASCAL | STDCALL ] 
         [ ORDINAL n ] [ PERSISTENT ] 
    | IN SUPER } : 
  [ procedure-body ] 

proc-name
EXTERNAL "dllname"
CDECL
PASCAL
STDCALL
ORDINAL n
PERSISTENT
PRIVATE
IN SUPER
procedure-body
procedure-logic
catch-block
END [ PROCEDURE ]
Examples

The following example declares an ABL internal procedure that computes the factorial of an integer entered as an INPUT parameter. The result is returned as an OUTPUT parameter. Note that the following procedure calls itself recursively to obtain the result:

r-factrl.p
DEFINE VARIABLE FactorialResult AS INTEGER NO-UNDO FORMAT ">>>,>>>,>>9". 
DEFINE VARIABLE FactorialInput  AS INTEGER NO-UNDO . 
REPEAT: 
  SET FactorialInput VALIDATE(FactorialInput <= 12 AND FactorialInput >= 0, 
    "Value must be between 0 and 12."). 
  RUN Factorial (INPUT FactorialInput, OUTPUT FactorialResult). 
  DISPLAY FactorialResult.    
END. 
PROCEDURE Factorial: 
  DEFINE INPUT PARAMETER  PTerm           AS INTEGER NO-UNDO. 
  DEFINE OUTPUT PARAMETER FactorialResult AS INTEGER NO-UNDO. 
  DEFINE VARIABLE WorkingResult AS INTEGER NO-UNDO. 
    
  IF PTerm <= 1 THEN DO: 
    FactorialResult = 1. 
    RETURN. 
  END. 
  ELSE DO: 
    RUN Factorial (INPUT PTerm - 1, OUTPUT WorkingResult). 
    FactorialResult = PTerm * WorkingResult. 
  END. 
END PROCEDURE. 

The following example declares a DLL routine, MessageBox(), which displays a message:

r-dllex1.p
DEFINE VARIABLE iResult 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 iResult). 
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.  

The following code fragment declares a UNIX shared library routine:

PROCEDURE atoi EXTERNAL "/usr/lib/libc.so.1": 
... 

Notes
See also

Call object handle, COM-SELF system handle, DEFINE PARAMETER statement, END statement, RUN statement, TRIGGER PROCEDURE statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex