Friday, March 15, 2013

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:

5 comments:

yektek training said...

thanks for sharing this nice nformation siri

Anonymous said...

Thank you for the info. I wanted to ask abt the output on the first program? Shouldnt it be 30, 35, 40?

Sandip Roy said...

Thank you.
By mistake I uploaded the wrong picture. Now it's alright.

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Unknown said...

Best SAP Success Factors Training Institute in Chennai
Best SAP MM Training in Chennai
Best SAP SD Training in Chennai
Best SAP ABAP Training in Chennai
Best SAP FICO Training in Chennai
Best SAP BASIS Training in Chennai

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/
http://thecreatingexperts.com/sap-abap-training-in-chennai/
http://thecreatingexperts.com/sap-basis-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!