AMT Help Files

ROUTINE...BEGIN_ROUTINE...END_ROUTINE

For Routines as part of a Class see Class ROUTINE.


Syntax

Command
Mandatory parameter
Optional parameter
Mandatory keyword
Optional keyword

ROUTINE <Routine> [INTERRUPT | [(<Parameter list>)][ : <Resulttype>]]

        [CONST
                <Definitions>]

        [VAR
                <Definitions>]

        [BOOLEANS
                <Definitions>]
BEGIN_ROUTINE

        <Code lines>

END_ROUTINE

Description

Defines a routine.

Diagram

Returned value type

Depends on the <result type> definition

Parameters

Parameter Description
<Routine> Name of the routine. This cannot be a name that is already used for a Form, Report or Global Routine.
INTERRUPT

Allows the end user to interrupt other routines within the same Report.
This option can only be added to one routine with the exclusion of the MAIN routine. This routine may not have any parameters <Parameter list> or <Result type> specified.

In the Control Center, the interrupt can be invoked and its value (0 - 99) can be set, which will be stored in the system item SI-REPORTRESULT at the time that the "interrupting routine" is executed.

Note: a Report will only be interrupted when the code of the Report itself is being executed, not when the code of a global routine called within the Report is currently being executed.

<Parameter list>









List of declarations. Unless for constant declarations, the parameters (fields) that are specified in this list can be invoked directly through a Routine-Call. To each specified parameter a type and a length have to be assigned. If multiple variables have the same type and length, you may declare these variables together instantly. You may also specify the options VAR or CONST, which are comparable with these specifications for definitions inside the routine. The syntax for specifying the declarations is the following:
[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 specifications for the type, length and decimals of the calling variable must be exactly the same.
  • 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 execution of the procedure, the variables will have the value as changed in the called procedure. 
CONST Declares that the specified fields are constants. When using this option, fields are treated as readonly and therefore cannot be changed through the calling routine.
<No type definition>  When no type definition is given, the parameter will be available as variable inside the procedure, but changes to its value will only effect the local variable.  
<Field specification> Specification of one or more field names.

When declaring multiple fields at once, you have to use the comma (,) as a separator. This way, these fields will instantly be defined with the same characteristics. It is possible to use DCT  in variable declarations in the routine header, e.g.: 

routine new_travelnr (sa-travelnr dct travelnr)
<Type> The type of the variable(s), which may be ALPHA, NUMERIC, BOOLEAN, STRING, INTEGER, SIGNED, FINANCIAL, PRINTER (for text reports) or PRINTERGRAPHICAL (for graphical reports).
<Length> The maximal length of the specified variable(s). This parameter only has to be specified if the type is ALPHA or NUMERIC. The number of decimals are supplied after a dot.
OPTIONAL
When specified this parameter can be omitted in the call to the routine. This can only be used for the last (consecutive) parameters in the parameter list.
<Resulttype> Type that is returned after the routine has ended. Also the DCT  can be used.

routine new_travelnr (sa-travelnr alpha 19) : dct travelnr

routine new_travelnr (sa-travelnr dct travelnr) : dct travelnr
CONST Declares that the next <Definitions> defines constants that can only be used locally inside the routine.
BOOLEANS  Declares that the next <Definitions> defines a boolean function 
VAR Declares that the next <Definitions> defines variables that can only be used locally inside the routine.
<Definitions> Definitions for constants or variables that are used in the program. To make it possible to call multiple variables at once locally, variables can be defined within a structure.  
<Code lines> Code lines that are executed within the routine.

Remarks

Parameters for the routine are defined in the <Parameter list>.

Optionally, you may specify a <Result type>. The value of the variable result will then be returned as return value.

After the routine definition header the definitions of the constants (CONST part) are specified, followed by the variable definitions (VAR part).

The instructions that must be executed when the routine is called, are specified between the keywords BEGIN_ROUTINE and END_ROUTINE.

There are some routines that are automatically added to an object, which are:

A routine that is defined within a form or report may only be called locally. Global routines may also be called from other objects in the same application. If the routine is part of a dll file, it may be called from an external program by using the CALL instruction.

Example


routine printlay_05 (printable boolean) : boolean
begin_routine
    if printable
        print (lay_05)
        result := true
    else
        result := false
    endif
end_routine

 

Return to

Commands