Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  Components in Classes and Interfaces →  Methods →  METHODS 

METHODS - RETURNING

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


METHODS meth [ABSTRACT|FINAL] 
            |[DEFAULT IGNORE|FAIL]

  [IMPORTING parameters [PREFERRED PARAMETER p]]
  [EXPORTING parameters]
  [CHANGING  parameters]
  RETURNING VALUE(r) typing
  [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
  |{EXCEPTIONS exc1 exc2 ...}].

Addition

... RETURNING VALUE(r) typing

Effect

This statement declares a functional instance method meth. The same applies to the additions ABSTRACT, FINAL, DEFAULT, IMPORTING, EXPORTING, CHANGING, RAISING, and EXCEPTIONS as to general instance methods.

A functional method can be called as a function in a suitable reading position.

Addition

... RETURNING VALUE(r) typing

Effect

Alongside any other formal parameters, a functional method has precisely one return value r declared using the addition RETURNING.The return value must be passed by value using VALUE and be fully typed using typing. In the typing check, special rules apply, depending on whether an explicit actual parameter is bound using RECEIVING or the functional method is used in an operand position.


Notes

  • In the methods of a class, one method of the class obscures a built-in function with the same name. The same applies in functional method calls. Functional method calls and specified built-in functions have similar syntax, which means it is important that a functional method is not given the same name as a built-in function.
  • Functional methods are allowed as actual parameters of methods, which enables the option of nesting method calls in an operand position.
  • The return value of a functional method is always passed by value, which means it is passed only if the functional method exits without error.

Example

Declaration of a functional method with input parameter and return value. The method is called as an actual parameter for the input parameter of another method.

CLASS cls DEFINITION. 
  PUBLIC SECTION. 
    METHODS 
      meth 
        IMPORTING 
          name          TYPE string 
        RETURNING 
          VALUE(result) TYPE string. 
ENDCLASS. 

CLASS cls IMPLEMENTATION. 
  METHOD meth. 
    result = |Hello { name }!|. 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  cl_demo_output=>display( 
    NEW cls( )->meth( CONV #( sy-uname ) ) ).