Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## METHOD statement

> Defines a method in a class, or declares a method prototype in an interface.

> Note: This statement is applicable only when used in a class definition (`.cls`) file.

> #### Syntax

>     METHOD { method-modifiers } { VOID | return-type } method-name
>       ( [ parameter [, parameter ] ... ] ):
>       method-body

> ``method-modifiers``

> A set of options that specify method modifiers for this method. Method modifiers define the behavioral characteristics of the method. You can specify method modifiers in any order using the following syntax:

>     { PRIVATE | PROTECTED | PUBLIC } [ OVERRIDE ] [ FINAL ]

> `{ PRIVATE | PROTECTED | PUBLIC }`

> Specifies the access mode for this method.

> PRIVATE methods can be accessed only by the defining class. PROTECTED methods can be accessed by the defining class and any of its inheriting classes. PUBLIC methods can be accessed by the defining class, any of its inheriting classes, and any class or procedure that instantiates that class (that is, through an object reference).

> When declaring a method prototype in an interface, the access mode for this method must be PUBLIC.

> `OVERRIDE`

> Indicates this method overrides the behavior of a method defined in an inherited super class. The method that overrides the definition of a method in an inherited super class must match with respect to the name, return type, and access mode of the method, and with respect to the number, type, and mode of the parameters.

> This modifier is not valid when declaring a method prototype in an interface.

> Note: To expose a method defined as PROTECTED in a super class, you can override the method by defining a method in a subclass with a PUBLIC access modifier.

> For more information about overriding methods, see OpenEdge Getting Started: Object-oriented Programming .

> `FINAL`

> Indicates this method cannot be overridden by a method defined in an inheriting subclass.

> This modifier is not valid when declaring a method prototype in an interface.

> `VOID`

> Indicates this method does not return a value.

> ``return-type``

> The data type of the value this method returns. Progress provides the following return value data types: CHARACTER, CLASS, COM-HANDLE, DATE, DATETIME, DATETIME-TZ, DECIMAL, HANDLE, INTEGER, LOGICAL, LONGCHAR, MEMPTR, RAW, RECID, ROWID and WIDGET-HANDLE.

> To specify a class or interface object reference as a return value for a method, use the following syntax:

>     [ CLASS ] { type-name }

> Progress passes the object reference associated with the class or interface (by value), not the class or interface itself.

> ``type-name``

> A character string that specifies the type name of the class or interface. Specify a type name using the `package`.`class-name` syntax as described in the Type-name syntax reference entry in this book.

> If the specified class or interface type name conflicts with an abbreviation of a built-in Progress data type name, such as INT for INTEGER, you must specify the CLASS keyword.

> ``method-name``

> The method name. The method name must be unique within the defining class and any class in its inherited class hierarchy, unless this method overrides a method in a super class (in which case, the name must be the same as the overridden method in the super class and you must specify the OVERRIDE method modifier).

> `( `parameter` [, `parameter` ] ... )`

> Defines one or more parameters of the method.

> For the parameter definition syntax, see the Parameter definition syntax reference entry in this book.

> ``method-body``

> The body of the method definition. Define the method body using the following syntax:

>            .
>            .
>            .
>     method-logic
>            .
>            .
>            .
>     END [ METHOD ].

> ``method-logic``

> The logic of the method, which can contain any Progress 4GL statements currently allowed within a PROCEDURE block including class-related statements, but excluding the RETURN ERROR statement. If the method returns a value, the method’s logic must not reference, either directly or indirectly, statements that block I/O (namely, the CHOOSE, INSERT, PROMPT-FOR, READKEY, SET, UPDATE, and WAIT-FOR statements).

> `END [ METHOD ]`

> Specifies the end of the method body definition. You must end the method body definition with the END statement.

> Note: When declaring a method prototype in an interface, you do not specify the method’s logic or the END statement. For more information about declaring method prototypes in an interface, see the INTERFACE statement reference entry in this book.

> Example

> The following example shows the definition of a method in a class (which might implement a method prototype declared in an interface, as depicted in the second example):

>     METHOD PUBLIC CHARACTER GetCustomerName(INPUT inCustNum AS INTEGER):
>       FIND ttCust WHERE ttCust.CustNum = inCustNum NO-ERROR.
>       IF AVAILABLE ttCust THEN
>         RETURN ttCust.CustName.
>       ELSE
>         RETURN ?.
>     END METHOD.

> The following example shows the definition of a method prototype declaration in an interface (which might be implemented by a method definition in a class, as depicted in the first example):

>     INTERFACE acme.myObjs.Interfaces.ICustObj:
>       METHOD PUBLIC CHARACTER GetCustomerName(INPUT inCustNum AS INTEGER).
>     END INTERFACE.

> #### Notes

> - You can terminate a METHOD statement with either a period (.) or a colon (:).

> - A complete method definition must begin with the METHOD statement and end with the END statement.

> - A method can access any data members in its defining class including PROTECTED and PUBLIC data members defined anywhere in its inherited class hierarchy.

> - A method in a class can run another method in a class, as well as an internal or external procedure or a user-defined function in a persistent procedure.

> - Local variables defined within a method scope to the end of the method definition. The value of local variables do not persist across method invocations; they are re-initialized each time you invoke the method. However, if you define a local variable within a method using the same name as a data member within the class hierarchy, the local variable takes precedence over the data member for the duration of the method.

> - You cannot specify the PUBLIC, PRIVATE, or PROTECTED access modes in variable definitions in a method.

> - You cannot define shared objects, work tables, temporary tables, or ProDataSet objects within the body of a method.

> - Progress implements scalar and array parameters of methods as NO-UNDO variables.

> - If the method results in an error, consider using an output parameter to return the error condition to the calling procedure. For more information, see OpenEdge Getting Started: Object-oriented Programming .

> #### See also

> CLASS statement, FUNCTION statement, INTERFACE statement

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095