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:

9 comments:

yektek training said...

thanks for sharing this nice nformation siri

Ramya k said...

Thanks for the great information in your blog SAP SF Training in Chennai

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.

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

sanayamohit 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!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

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

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

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

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!!!!!!

Keerthi Suresh said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-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!!!!!!