banner ads

Method Calling by One Import Parameter

Method Calling by One Import Parameter 

We can call 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:


We can do this similar thing by using PARAMETERS. In this case we can enter our dynamic values to the import parameters.  In the following example we have used this with the help of PARAMETERS.

REPORT  zsr_test NO STANDARD PAGE HEADING.

PARAMETERS: p_one TYPE i,
            p_two TYPE i,
            p_thr TYPE i.

*----------------------------------------------------------------------*
*       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 = p_one,
               obj_test->m_test( i_inp = p_two ),
               obj_test->m_test( p_thr ).

Now we shall have a selection screen where we enter our parameters value.


The output is as follows:

No comments