Ansicht
Dokumentation
ABAPCALL_OOMETHOD - CALL OOMETHOD
ABAP Short Reference Fill RESBD Structure from EBP Component StructureThis documentation is copyright by SAP AG.
CALL METHOD - Calling a method of an ABAP Object
Syntax
CALL METHOD meth.
Additions
1. ... EXPORTING p1 = f1 ... pn = fn 2. ... IMPORTING
p1 = f1 ... pn = fn
3. ... CHANGING p1 = f1 ... pn = fn
4. ... RECEIVING p = f
5. ... EXCEPTIONS except1 = rc1 ... exceptn = rcn
Effect
Calls a method meth in ABAP Objects, the object-oriented extension of ABAP.
You must have defined the method meth in the definition part of a class or interface using the METHODS statement and in the implementation part of a class using the METHOD - ENDMETHOD statements. You can call methods from within a class or from outside, using the normal way of addressing class components.
You define the interface of a method fully when you declare the method using the METHODS
statement. The additions to the CALL METHOD statement listed below pass or receive actual parameters to and from this interface.
Addition 1
... EXPORTING p1 = f1 ... pn = fn
Effect
The caller must use the EXPORTING addition to pass any actual parameters f1 ... fn to
the IMPORTING parameters p1 ... pn in the method that are not declared as optional. The types of f1 ... fn and p1 ... pn must be compatible.
Example
CLASS C_TEST1 DEFINITION.
PUBLIC SECTION.
METHODS M_TEST1 IMPORTING PAR1 TYPE I DEFAULT 5
PAR2 TYPE C OPTIONAL
PAR3 TYPE D.
ENDCLASS.
DATA: F TYPE D,
O_TEST1 TYPE REF TO C_TEST1.
CREATE OBJECT O_TEST1.
CALL METHOD O_TEST1->M_TEST1 EXPORTING PAR3 = F.
CLASS C_TEST1 IMPLEMENTATION.
METHOD M_TEST1.
...
ENDMETHOD.
ENDCLASS.
Addition 2
... IMPORTING p1 = f1 ... pn = fn
Effect
The optional IMPORTING addition allows the caller to import the EXPORTING parameters p1
... pn from the method as the actual parameters f1 ... fn. p1 ... pn and f1 ... fn must have compatible types.
Example
CLASS C_TEST1 DEFINITION.
PUBLIC SECTION.
METHODS M_TEST1 IMPORTING PAR1 TYPE I DEFAULT 5
PAR2 TYPE C OPTIONAL
PAR3 TYPE D.
ENDCLASS.
DATA: F TYPE D,
O_TEST1 TYPE REF TO C_TEST1.
CREATE OBJECT O_TEST1.
CALL METHOD O_TEST1->M_TEST1 EXPORTING PAR3 = F.
CLASS C_TEST1 IMPLEMENTATION.
METHOD M_TEST1.
...
ENDMETHOD.
ENDCLASS.
Addition 3
... CHANGING p1 = f1 ... pn = fn
Effect
The caller must use the CHANGING addition to pass any actual parameters f1 ... fn to the
CHANGING parameter p1 ... pn of the method that are not declared as optional. Once the
method is complete, the caller automatically receives the CHANGING parameters of the method as actual parameters.
Example
CLASS C_TEST1 DEFINITION.
PUBLIC SECTION.
METHODS M_TEST1 CHANGING PAR1 TYPE I OPTIONAL
PAR2 TYPE C
PAR3 TYPE D DEFAULT SY-DATUM.
ENDCLASS.
DATA: F TYPE C,
O_TEST1 TYPE REF TO C_TEST1.
CREATE OBJECT O_TEST1.
CALL METHOD O_TEST1->M_TEST1 CHANGING PAR2 = F.
CLASS C_TEST1 IMPLEMENTATION.
METHOD M_TEST1.
...
ENDMETHOD.
ENDCLASS.
Addition 4
... RECEIVING p = f
Effect
The optional RECEIVING addition allows the caller to receive the return value p of method meth in an actual parameter f. f must have a compatible type.
Example
CLASS C_TEST1 DEFINITION.
PUBLIC SECTION.
METHODS M_TEST1 RETURNING R TYPE I.
ENDCLASS.
DATA: F TYPE I,
O_TEST1 TYPE REF TO C_TEST1.
CREATE OBJECT O_TEST1.
CALL METHOD O_TEST1->M_TEST1 RECEIVING R = F.
CLASS C_TEST1 IMPLEMENTATION.
METHOD M_TEST1.
...
ENDMETHOD.
ENDCLASS.
Addition 5
... EXCEPTIONS except1 = rc1 ... exceptn = rcn
Effect
The optional EXCEPTIONS addition allows the callerto handle exceptions in the method meth. You trigger exceptions using the RAISE except and MESSAGE RAISING statements.
The caller handles an exception except by listing it under the EXCEPTIONS addition and
assigning it a return code rc. If the exception is triggered, the system stops processing the
method, returns control to the caller, and places the return code rc in the system variable SY-SUBRC.
All of the EXPORTING, CHANGING and RETURNING parameters that pass their values
by reference (default setting) pass their values to the corresponding actual parameters when an exception
occurs. Actual parameters for output that are passed by value retain the values that they had before the method was called.
If the caller does not handle an exception raised by RAISE except, the program is terminated.
If the caller does not handle and exception triggered by MESSAGE
RAISING, the message is displayed, and the system continues processing according to the message type.
Example
CLASS C_TEST1 DEFINITION.
PUBLIC SECTION.
METHODS M_TEST1 EXCEPTIONS EXC1
EXC2.
ENDCLASS.
DATA O_TEST1 TYPE REF TO C_TEST1.
CREATE OBJECT O_TEST1.
CALL METHOD O_TEST1->M_TEST1 EXCEPTIONS EXC1 = 10
EXC2 = 20.
CASE SY-SUBRC.
WHEN 10.
...
WHEN 20.
...
ENDCASE.
CLASS C_TEST1 IMPLEMENTATION.
METHOD M_TEST1.
...
RAISE EXC1.
...
MESSAGE E012(AT) RAISING EXC2.
...
ENDMETHOD.
ENDCLASS.
Related
CLASS
PUBLIC
PROTECTED
PRIVATE
ENDCLASS
CLASS-DATA
CLASS-METHODS
CLASS-EVENTS
METHODS
EVENTS
INTERFACES
METHOD
ENDMETHOD
INTERFACE
ENDINTERFACE
CREATE
RAISE
SET HANDLER
ROGBILLS - Synchronize billing plans Vendor Master (General Section)
This documentation is copyright by SAP AG.
Length: 11164 Date: 20240420 Time: 172638 sap01-206 ( 112 ms )