Monday, March 18, 2013

Import Parameters Passed by Reference and Passed by Value


We can pass parameters into a method by import parameter. Now there are two ways to pass the method. We can pass by Reference and Pass by value. The variable, passed by reference can’t be changed inside the method. We only can change the value of variable which is passed by value.

In the following example we have created a local class cl_pass_para. A method m_pass_para has been declared with import parameters in the public section of this class. We are passing v_ref (passed by reference) and v_val (passed by value) parameters. In the implementation part we are writing both of the variable’s value. Here according to the function we can’t change the value of v_ref (passed by reference) parameter. Following syntax error will come for this condition.


The correct program is as follows.

REPORT  zsr_test NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*       CLASS cl_pass_para DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_pass_para DEFINITION.
  PUBLIC SECTION.
    METHODS m_pass_para IMPORTING v_ref TYPE i
                                  value(v_val) TYPE i.
ENDCLASS.                    "cl_pass_para DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_pass_para IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_pass_para IMPLEMENTATION.
  METHOD m_pass_para.
    WRITE: / 'Parameter passed by reference', v_ref,
           / 'Parameter passed by value', v_val.
    v_val = 10.
    WRITE: / 'Parameter passed by reference can''t be changed', v_ref,
           / 'Parameter passed by value can be changed', v_val.
  ENDMETHOD.                    "m_pass_para
ENDCLASS.                    "cl_pass_para IMPLEMENTATION

START-OF-SELECTION.
  DATA obj TYPE REF TO cl_pass_para.
  CREATE OBJECT obj.
  CALL METHOD obj->m_pass_para
    EXPORTING
      v_ref = 5
      v_val = 7.

We have the following output for this program.

9 comments:

yektek training said...

Very nice information given by you thank you

yektek training said...
This comment has been removed by the author.
Cindy Dy said...

I love this site! I could find all the information I needed in a split second! It's rare that you stumble upon excellent sites like this! Now this website resides in my favorites! Great job guys.

www.gofastek.com

fishtail said...

i appreciate you spending some time and effort to put this article together. i can not wait to read far more from you. this is actually terrific site.

www.triciajoy.com

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


ufgop.org
ufgop.org

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/

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD