Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

Pass by Value VS Pass by Reference in SAP ABAP

In SAP ABAP, pass by value and pass by reference are two methods of passing data to methods, function modules, or forms. They determine how the data is handed over and whether changes to the data affect the original variable.

Aspect Pass by Value Pass by Reference
Memory More (copies data) Less (passes reference)
Speed Slower Faster
Original Changed?  No Yes
Syntax VALUE(...) Default or REFERENCE(...)
REPORT zrep_lclclass.

DATAlv_val TYPE VALUE 5,
      lv_ref TYPE VALUE 5.

CLASS zcl_pass_test DEFINITION.
  PUBLIC SECTION.
    METHODS:
      pass_by_value IMPORTING value(iv_numTYPE i,
      pass_by_ref   CHANGING  cv_num TYPE i.
ENDCLASS.

  CLASS zcl_pass_test IMPLEMENTATION.

  METHOD pass_by_value.
    iv_num iv_num + 10.
    WRITE/ 'Inside pass_by_value'iv_num.
  ENDMETHOD.

  METHOD pass_by_ref.
    cv_num cv_num + 10.
    WRITE/ 'Inside pass_by_ref'cv_num.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  DATA(lo_pass_testNEW zcl_pass_test).

  WRITE/ 'Before pass_by_value'lv_val.
  lo_pass_test->pass_by_valueiv_num lv_val ).
  WRITE/ 'After pass_by_value'lv_val" Unchanged

  SKIP.

  WRITE/ 'Before pass_by_ref'lv_ref.
  lo_pass_test->pass_by_refCHANGING cv_num lv_ref ).
  WRITE/ 'After pass_by_ref'lv_ref" Changed 

Output:

 

Related Questions

Leave an answer

Leave an answer