Register Login

Pass by value - actual parameter is not changing

Updated May 18, 2018

hi gurus,

data : a type i value '4',
       b type i value '4',
       c type i value '4'.


write : / c.

perform add using a b changing c.

write : / 'outside' , c.

form add using a1 b1 changing value(c1).

 c1 = a1 + b1.
 write : 'c1' , c1.

 endform.

in this pgm , why the actual parameter is not changing , its returning only the formal parameter value..


Comments

  • 08 Jan 2014 5:27 am nandana ramesh Best Answer

    Hi,

    the values is changing because of the keyword CHANGING in the definition of the subroutine. Instead use the below code

      data : a type i value '4',
           b type i value '4',
           c type i value '4'.


    write : / c.

    perform add using a b c."changing c.

    write : / 'outside' , c.

    form add using a1 b1 value(c1).  "changing value(c1).
     c1 = a1 + b1.
     write : 'c1' , c1.

     endform.

     

    this would answer your question.

     

    regards,

    Nandana

  • 20 Aug 2008 11:51 am Shalesh Singh Visen
    Hi.

    If the output that we r getting is:-
    4
    c1 8
    outside 8

    then its because we are using CHANGING VALUE().
    When CHANGING VALUE() is used the value of the actual parameter remains the same inside the FORM...ENDFORM statements.
    But if u refer to the actual parameter once control passes beyond the ENDFORM statement, the actual parameter will give u the value of the then formal parameter.

    Catch this:

    data : a type i value '4',
    b type i value '4',
    c type i value '4'.
    write : / c.
    ** will write c = 4

    perform add using a b changing c.
    **go to the FORM statement

    write : / 'outside' , c.
    ** and this will write c = c1 = 8.

    form add using a1 b1 changing value(c1).

    c1 = a1 + b1.
    write : 'c1' , c1.
    ** will write c1 = 8 but

    write : 'c' , c.
    ** will write c = 4.

    endform.
    Hope this clears Ur doubt.

    Regards.
    Vipin Varghese.

×