SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → Modularization units →Pass Type of Formal Parameters
Background
Parameters can be passed to procedures either by reference or by value.
IMPORTING parameters that are passed by reference are protected from explicit changes within the procedure. This is not the case for the pass by value method. RETURNING parameters always require the pass by value method.
Rule
Choose a suitable pass-by type
When selecting the pass-by type, consider both speed and security:
Details
The pass by reference method generally has a higher performance than pass by value because no values need to be copied. This speed advantage can be noticed especially in the case of large parameters, such as internal tables or strings, or in mass data processing. In the case of small, flat parameters, the pass by value method usually does not lead to problems because the copy costs incurred are not high here. Furthermore, for strings and internal tables, sharing takes effect in the case of pass by value. Consequently, only references are passed here. The time-intensive copy process is skipped if the data objects involved are only to be read-accessed, such as in the case of EXPORTING parameters that are filled within a procedure (method), and are not modified by the calling program after the pass.
Despite the speed advantage, the pass by reference method can lead to problems due to the following aspects:
If passing by value will not cause performance problems, that is, if small data sets are passed or sharing can be used, you should use this method for security reasons. If speed is an issue, you should work with passing by reference. In this case, you must consider the potential risks in the implementation of the procedure (method).
Example
See the example in the section about the Code Inspector. In this example, an internal table is passed by reference due to performance reasons, while an elementary parameter is passed by value due to robustness reasons.