Local symbol definition

Symbols defined inside a function body are only visible to the function.

Inside the body of a function, you can define language elements that will only be visible for the function code:
  • local constants with the CONSTANT instruction,
  • local user-defined types with the TYPE instruction,
  • local variables with the DEFINE instruction.
FUNCTION check_customer( cust_id INTEGER )
  CONSTANT c_max = 1000 -- local constant
  TYPE t_cust RECORD LIKE customer.* -- local type
  DEFINE found BOOLEAN -- local variable
  ...
END FUNCTION
Function arguments and local symbols must use different names, it is not possible to define a local variable with the same name as a function parameter:
FUNCTION func_a(x INTEGER)
   DEFINE x INTEGER
| The symbol 'x' has been defined more than once.
| See error number -4319.
   LET x = 1
END FUNCTION

FUNCTION func_b(x)
   DEFINE x INTEGER
   DEFINE x INTEGER
| The symbol 'x' has been defined more than once.
| See error number -4319.
   LET x = 1
END FUNCTION
Local function symbols are not visible in other program blocks. Global or module variable can use the same name as a local variable: The global or module variable is not visible within the function scope of the local variable.
DEFINE x INTEGER   -- Declares a module variable

FUNCTION func_a()
  DEFINE x INTEGER -- Declares a local variable
  LET x = 123      -- Assigns local variable
END FUNCTION

FUNCTION func_b()
  LET x = 123     -- Changes the module variable
END FUNCTION

However, for better code readability, it is recommended that you consider using different names for global, module and local function symbols.