Differences between Call by Value and Call by Reference

by | Jun 26, 2019 | ODATA

Home » SAP » ABAP » ODATA » Differences between Call by Value and Call by Reference

Preface – This post is part of the SAP ABAP OData Tutorial series.

Before discussing the differences between Call by Value and Call by Reference, let’ have a quick introduction of the two.

Introduction

Modularization techniques in ABAP is a way to write codes in different processing blocks like subroutine, Function Modules and ABAP objects. If these blocks have any parameter interface, while calling them it is required to pass values to all the formal parameter interface. These blocks with parameters can be called via either Call by Value or Call by Reference.

Call by Value

In Call by Value, the value of the actual parameters is copied to the formal parameter of the function. The value of the two types of parameters is stored in different memory locations. The memory location of the formal parameter is allocated when the function/subroutine is called and gets freed when the function/subroutine returns. The references to the formal parameter refer to a unique memory and are only known within the function/subroutine. Any changes done inside the function/subroutine are not reflected in the actual parameter.

Call by Reference

In Call by Reference, the address of the actual parameters is copied to the formal parameters of the function. The references to the formal parameter reference the same memory as of the actual parameter. Any changes done inside the function/subroutine are reflected in the actual parameter i.e. all the operations are performed on the value stored at the address of the actual parameter, and the modified value is stored at the same address.

Now, let’s have a look at their difference.

call by value and call by reference

Differences between Call by Value and Call by Reference

Call by ValueCall by Reference
The value of the actual parameter is copied into the formal parameter.The address of the actual parameter is copied into the formal parameter
Both the parameters are stored in different memory locations.Both the parameters refer the same memory location.
The change in formal parameters is not reflected in the actual parameters.The change in formal parameters is reflected in the actual parameters.
Original value cannot be changed.Original value is changed.

 

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author