SEND [METHOD ]
operand1 TO [OBJECT ]
operand2
|
|||||||||||||
WITH
|
(AD= |
) | |||||||||||
operand3 | |||||||||||||
nX |
|||||||||||||
[RETURN
operand4]
|
|||||||||||||
[GIVING
operand5]
|
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statements: CREATE
OBJECT
| DEFINE
CLASS
| INTERFACE
|
METHOD
|
PROPERTY
Belongs to Function Group: Component Based Programming
The SEND METHOD
statement is used to invoke a
particular method of an object.
See the section NaturalX in the Programming Guide for information on component-based programming.
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
C | S | A | yes | no | |||||||||||||||
operand2
|
S | O | no | no | ||||||||||||||||
operand3
|
C | S | A | G | A | U | N | P | I | F | B | D | T | L | C | G | O | yes | no | |
operand4
|
S | A | A | U | N | P | I | F | B | D | T | L | C | G | O | yes | no | |||
operand5
|
S | N | I | yes | no |
The formats C and G can only be passed to methods of local classes.
Syntax Element Description:
Syntax Element | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
Method-Name:
Since the method names can be identical in different
interfaces of a class, the method name in
In the following example, the object * Specifying only the method name. SEND 'Start' TO #O3 * Qualifying the method name with the interface name. SEND 'Iterate.Start' TO #O3 If no interface name is specified, Natural searches the method name in all the interfaces of the class. If the method name is found in more than one interface, a runtime error occurs. |
||||||||||
operand2
|
Object Handle:
The handle of the object to which the method call is to be sent. To invoke a method of the current object inside a method,
use the system variable |
||||||||||
operand3
|
Parameter(s) Specific to the Method:
As In the following example, the object SEND 'PositionTo' TO #O3 WITH Pos Methods can have optional parameters. Optional parameters
need not to be specified when the method is called. To omit an optional
parameter, use the placeholder 1X. To omit
In the following example, the method
* Specifying all parameters. SEND 'SetAddress' TO #O4 WITH FirstName MiddleInitial LastName Street City * Omitting one optional parameter. SEND 'SetAddress' TO #O4 WITH FirstName 1X LastName Street City * Omitting all optional parameters. SEND 'SetAddress' TO #O4 WITH FirstName 1X LastName 2X Omitting a non-optional (mandatory) parameter results in a runtime error. |
||||||||||
AD= |
|
||||||||||
nX
|
Parameter(s) to be Skipped:
With the notation
For a method implemented in Natural, a parameter that is
to be skipped must be defined with the keyword |
||||||||||
RETURN
operand4
|
RETURN Clause:
If the If the Note: |
||||||||||
GIVING
operand5
|
GIVING Clause:
If the If the |
The following diagram gives an overview of the Natural objects that are used in this example. The corresponding source code and the program output are shown below. Links to the source code of an object are provided in the diagram.
** Example 'METH01': CREATE OBJECT and SEND METHOD ** using a class and several methods (see METH*) ************************************************************************ DEFINE DATA LOCAL USING METHA LOCAL 1 L-STUDENT HANDLE OF OBJECT 1 #NAME (A20) 1 #STREET (A20) 1 #CITY (A20) 1 #SUM (I4) 1 #MULTI (I4) END-DEFINE * CREATE OBJECT L-STUDENT OF CLASS 'STUDENTS' /* see METHCL for class * L-STUDENT.<> := 'John Smith' * SEND METHOD 'INIT' TO L-STUDENT /* see METHCL WITH #VAR1 #VAR2 #VAR3 #VAR4 * SEND METHOD 'SUMMATION' TO L-STUDENT /* see METHCL WITH #VAR1 #VAR2 #VAR3 #VAR4 * SEND METHOD 'MULTIPLICATION' TO L-STUDENT /* see METHCL WITH #VAR1 #VAR2 #VAR3 #VAR4 * #NAME := L-STUDENT.<> #SUM := L-STUDENT.<> #MULTI := L-STUDENT.<> * SEND METHOD 'ADDRESS' TO L-STUDENT /* see METHCL * #STREET := L-STUDENT.<> #CITY := L-STUDENT.<> * * WRITE 'Name :' #NAME WRITE 'Street:' #STREET WRITE 'City :' #CITY WRITE ' ' WRITE 'The summation of ' #VAR1 #VAR2 #VAR3 #VAR4 WRITE 'is' #SUM WRITE 'The multiplication of' #VAR1 #VAR2 #VAR3 #VAR4 WRITE 'is' #MULTI * END
** Example 'METHCL': DEFINE CLASS (used by METH01) ************************************************************************ * Defining class STUDENTS for METH01 * DEFINE CLASS STUDENTS OBJECT USING METHO /* Object data for class STUDENTS /* INTERFACE STUDENT-ARITHMETICS PROPERTY FULL-NAME IS NAME END-PROPERTY PROPERTY SUM END-PROPERTY PROPERTY MULTI END-PROPERTY * METHOD INIT IS METH02 PARAMETER USING METHA END-METHOD METHOD SUMMATION IS METH03 PARAMETER USING METHA END-METHOD METHOD MULTIPLICATION IS METH04 PARAMETER USING METHA END-METHOD END-INTERFACE * INTERFACE STUDENT-ADDRESS PROPERTY STUDENT-NAME IS NAME END-PROPERTY PROPERTY STREET END-PROPERTY PROPERTY CITY END-PROPERTY * METHOD ADDRESS IS METH05 END-METHOD END-INTERFACE END-CLASS END
Local METHO Library SYSEXSYN DBID 10 FNR 32 Command > + I T L Name F Length Miscellaneous All -- -------------------------------- - ---------- -------------------------> 1 NAME A 20 1 STREET A 30 1 CITY A 20 1 SUM I 4 1 MULTI I 4
Parameter METHA Library SYSEXSYN DBID 10 FNR 32 Command > + I T L Name F Length Miscellaneous All -- -------------------------------- - ---------- -------------------------> 1 #VAR1 I 4 1 #VAR2 I 4 1 #VAR3 I 4 1 #VAR4 I 4
** Example 'METH02': Method INIT (used by METH01) ************************************************************************ DEFINE DATA PARAMETER USING METHA OBJECT USING METHO END-DEFINE * * Method INIT of class STUDENTS * #VAR1 := 1 #VAR2 := 2 #VAR3 := 3 #VAR4 := 4 * END
** Example 'METH03': Method SUMMATION (used by METH01) ************************************************************************ DEFINE DATA PARAMETER USING METHA OBJECT USING METHO END-DEFINE * * Method SUMMATION of class STUDENTS * COMPUTE SUM = #VAR1 + #VAR2 + #VAR3 + #VAR4 END
** Example 'METH04': Method MULTIPLICATION (used by METH01) ************************************************************************ DEFINE DATA PARAMETER USING METHA OBJECT USING METHO END-DEFINE * * Method MULTIPLICATION of class STUDENTS * COMPUTE MULTI = #VAR1 * #VAR2 * #VAR3 * #VAR4 END
** Example 'METH05': Method ADDRESS (used by METH01) ************************************************************************ DEFINE DATA OBJECT USING METHO END-DEFINE * * Method ADDRESS of class STUDENTS * IF NAME = 'John Smith' STREET := 'Oxford street' CITY := 'London' END-IF END
Page 1 05-01-17 15:59:04 Name : John Smith Street: Oxford street City : London The summation of 1 2 3 4 is 10 The multiplication of 1 2 3 4 is 24