Mentor SAP
2018-02-02 Submitted by:- Admin

We can call the method in different ways with the help of one import parameter. This strategy will be valid for more than one import parameter also. One of the parameters must be mandatory. In the following example we have a method m_test which contains an import parameter i_inp. Now we are calling that method in different three ways as follows.

REPORT  zsr_test NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*       CLASS cl_test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_test DEFINITION.
  PUBLIC SECTION.
    DATA output TYPE i.
    METHODS m_test IMPORTING i_inp TYPE i.
ENDCLASS.                    "cl_test DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_test IMPLEMENTATION.
  METHOD m_test.
    output = 5.
    output = output * i_inp.
    WRITE: / 'Output = ', output.
    CLEAR output.
  ENDMETHOD.                    "m_test
ENDCLASS.                    "cl_test IMPLEMENTATION

DATA obj_test TYPE REF TO cl_test.

START-OF-SELECTION.
  CREATE OBJECT obj_test.

  CALL METHOD: obj_test->m_test EXPORTING i_inp = 6,
               obj_test->m_test( i_inp = 7 ),
               obj_test->m_test( 8 ).

The output is as follows: