Mentor SAP

Instance Method Calls

This section explains the use of classes and their instances, from the static connections of various instances to their practical effects.

 

The example in the figure, shows the shorter syntax for method calls in which the CALL-METHOD prefix is omitted.

 

 

Syntax for Calling Instance Methods

CALL METHOD ref->method_name is the syntax used to call Instance methods. When calling an instance method from within another instance method, you can omit the instance name ref. The method is automatically executed for the current object.

 

A shorter syntax is also supported as of SAP NetWeaver Application Server (SAP NetWeaver AS) 6.10. In this version, omit CALL METHOD and list the parameters in parentheses. There must be no space before the parentheses, but there must be at least one space after the parentheses. When you call a method that has only one import parameter, you can specify the actual parameter in the parentheses without any other additions. When you call a method that only has import parameters, you can omit the EXPORTING addition.

 

 

Static Method Calls

Use CALL METHOD classname=>method_name to call static methods (also referred to as class methods).

Like static attributes, static methods are addressed with their class name, since they do not need instances.

As with instance methods, when you are calling a static method from within the class, you can omit the class name. Otherwise, the same rules apply here as for calling an instance method.

 

Functional Method Calls

Methods that have a RETURNING parameter are described as functional methods. The RETURNING parameter must always be passed by value - RETURNING VALUE(...) - and not by reference.

 

Prior to SAP NetWeaver 7.40, functional methods were only allowed IMPORTING parameters and exceptions, in addition to their RETURNING parameter. From SAP NetWeaver 7.40 onwards, they may have any number of EXPORTING and CHANGING parameters.

 

You can call functional methods directly within the following expressions:

 

Note: In SAP NetWeaver 7.02, the list of positions at which functional methods can be used was extended considerably.

 

Examples

In the first part of the example, two calls of functional instance methods represent the two addends of an addition.

 

The second example shows the call of a functional static method in short form. The GV_NUMBER data object is the actual parameter for the RETURNING parameter of the method. The detailed syntax is as follows:

 

DATA gv_number TYPE i.

CALL METHOD lcl_vehicle=>get_n_o_vehicles

RECEIVING rv_count = gv_number.

 

 

Access to Public Attributes

You access public attributes from outside the class in the same way as method calls. You can access static attributes using CLASSNAME=>STATIC_ATTRIBUTE. Access instance attributes with REF->INSTANCE_ATTRIBUTE.