AMT Help Files

PUBLIC ROUTINE

This page is for the PUBLIC ROUTINE command in Global Routines, for the ROUTINE command in classes see Class ROUTINE.

 

Syntax

Command
Mandatory parameter
Optional parameter
Mandatory keyword
Optional keyword

PUBLIC ROUTINE <Routine> [(<Parameterlist>)][ : <Resulttype>]

        [CONST
                <Definitions>]

        [VAR
                <Definitions>]

        [BOOLEANS
                <Definitions>]

BEGIN_ROUTINE

        <Code lines>

END_ROUTINE

Description

Defines a public routine which can only be used in global performable routines and global DLL routines, which can be called directly from reports or forms.

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.
<Parameterlist>









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 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.

Example


public routine findcountry (code : dct dct_country_code ) : dct dct_country
begin_routine
    
gtq_countries.index ( idx_cntr_code )
    gtq_countries.equal ( code )
    gtq_countries.getfirst ()

    if
resok
        result
:= gtq_countries.name
    else
        sme
('Error: no country found!')
        result
:= ''
    endif
end_routine

 

Relevant page

Public Routine Call

 

Return to

Commands