AMT Help Files

Class ROUTINE

Syntax Color Legend
Command
Mandatory parameter
Optional parameter
Mandatory keyword
Optional keyword

Syntax

{PRIVATE|PUBLIC} ROUTINE <Class>.<Routine> [(<Parameterlist>)][ : <Resulttype>]
  [CONST
    <Definitions>]
  [VAR
    <Definitions>]
  [BOOLEANS
    <Definitions>]
BEGIN_ROUTINE
  <Code lines>
END_ROUTINE

Description

Defines a class routine that can be defined in forms, reports, global performable routines, locally defined classes, and global class definitions.

Diagram

Returned value type

Depends on the <Result type> definition.

Parameters

Parameter Description
PRIVATE | PUBLIC The access modifier of the class routine. Private class routines can be accessed only from inside a public class routine of the same class. Public class routines defined in a global class can be accessed from any routine in a form, report, or global performable routine. Public class routines from a locally defined class can be accessed from any routine in the object where the class is defined. Although an access modifier keyword is not mandatory and the default is private, we recommend that you always specify it for clarity.
<Class>.<Routine> Name of the class routine.
<Parameterlist> List of declarations. Unless they are constant declarations, the parameters (fields) specified in this list can be invoked directly through a class routine call. Each specified parameter must have a type and length. If multiple variables have the same type and length, you can declare them together. You can also specify the options VAR or CONST, which are comparable to the specifications for definitions inside the routine. The syntax for declaring the parameters is:
[VAR | CONST] <Field specification> [:] <Type> <Length> [OPTIONAL]
VAR Declares that the specified fields are variables to be called by reference. When using this option, the following rules apply:
  • The type, length, and decimals of the calling variable must match exactly.
  • The calling variable may not be one of the following:
    • Array item
    • Structure (sub) item
    • Redefine or redefined item
    • Database item
    • Report layout control
  • The specified <Type> may not be Printer or XMLNode.
After the procedure is executed, the variables have the values as changed in the called procedure.
CONST Declares that the specified fields are constants. When using this option, fields are treated as read-only and therefore cannot be changed through the calling routine.
<No type definition> When no type definition is provided, the parameter is available as a variable inside the procedure, but changes to its value affect only the local variable.
<Field specification> Specification of one or more field names.

When you declare multiple fields at once, use a comma (,) as the separator so the fields are defined with the same characteristics. It is possible to use DCT in variable declarations in the routine header, for example:

routine Local_Class.new_travelnr (lc-travelnr dct travelnr)
<Type> The type of the variable or variables, which may be ALPHA, NUMERIC, BOOLEAN, STRING, INTEGER, SIGNED, FINANCIAL, PRINTER (for text reports), or PRINTERGRAPHICAL (for graphical reports).
<Length> The maximum length of the specified variable or variables. This parameter is required only if the type is ALPHA or NUMERIC. The number of decimals is supplied after a dot.
OPTIONAL When specified, this parameter can be omitted in the routine call. This can be used only for the last consecutive parameters in the parameter list.
<Resulttype> Type returned after the routine ends. You can also use DCT.
routine Local_Class.new_travelnr (sa-travelnr alpha 19) : dct travelnr
routine Local_Class.new_travelnr (sa-travelnr dct travelnr) : dct travelnr
CONST Declares that the next <Definitions> section defines constants that can be used only locally inside the routine.
BOOLEANS Declares that the next <Definitions> section defines a Boolean function that can be used only locally inside the routine.
VAR Declares that the next <Definitions> section defines variables that can be used only locally inside the routine.
<Definitions> Definitions for constants or variables used in the program. To call multiple variables at once locally, you can define variables within a structure.
<Code lines> Code lines that are executed within the routine. Only class members of the same class, global items, and system items are accessible inside a class routine. Other locally defined items, such as variables, routines, and screen objects, are outside the scope of a class routine.

Remarks

Parameters for the routine are defined in the <Parameter list>. Optionally, you can specify a <Result type>. The value of the resulting variable is then returned as the return value. After the routine definition header, the definitions of the constants (CONST section) are specified, followed by the variable definitions (VAR section). The instructions that must be executed when the routine is called are specified between the keywords BEGIN_ROUTINE and END_ROUTINE.

Inside class routines, it is only possible to access other class members (both class variables and class routines) of the same class, global items (global variables and global routines), and system items. Variables, routines, and screen items defined in a form or report cannot be accessed inside a class routine because they are outside the scope of a class routine.

Example

public routine Local_Class.setColour (colour_code : dct dct_colour_code)

begin_routine
  this.carColour  := colour_code
  this.carClrDate := today.yymmdd
  this.emailUpdates()
end_routine

Relevant pages:

Routine Call
Type Class

Contents