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
Beginner

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.

AspectPass by ValuePass by Reference
MemoryMore (copies data)Less (passes reference)
SpeedSlowerFaster
Original Changed? NoYes
SyntaxVALUE(...)Default or REFERENCE(...)
REPORT zrep_lclclass.

DATA: lv_val TYPE i VALUE 5,
      lv_ref TYPE i VALUE 5.

CLASS zcl_pass_test DEFINITION.
  PUBLIC SECTION.
    METHODS:
      pass_by_value IMPORTING value(iv_num) TYPE 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_test) = NEW zcl_pass_test( ).

  WRITE: / 'Before pass_by_value: ', lv_val.
  lo_pass_test->pass_by_value( iv_num = lv_val ).
  WRITE: / 'After pass_by_value: ', lv_val. " Unchanged

  SKIP.

  WRITE: / 'Before pass_by_ref: ', lv_ref.
  lo_pass_test->pass_by_ref( CHANGING cv_num = lv_ref ).
  WRITE: / 'After pass_by_ref: ', lv_ref. " Changed 

Output:

 

Related Questions

Leave an answer

Leave an answer