Thursday, June 26, 2025

πŸ”„ Pass by Value & Pass by Reference

 

Pass by Value:

  • In pass by value, value (or) values is passed from Actual Parameters to Formal Parameters
  • Both calling part & definition part will share different memory locations
  • In call by value nothing is reflected back to calling part

Example:

DATA v1 TYPE C VALUE ‘a’.

PERFORM sub USING v1.

WRITE:/ v1.

FORM sub USING VALUE(p1).

p1 = ‘b’.

WRITE:/ p1.

ENDFORM.

 

Output:

b

a

Pass by Reference:

  • In pass by reference value is not passed to Formal Parameters instead a Pointer (or) Reference (or) Address is passed to Formal Parameters.
  • Any changes done in Formal Parameters will be effected to Actual Parameters also

Example:

DATA v1 TYPE C VALUE ‘a’.

PERFORM sub USING (or) CHANGING v1.

WRITE:/ v1.

FORM sub USING (or) CHANGING p1.

p1 = ‘b’.

WRITE:/ p1.

ENDFORM.

Output:

b

b

No comments:

Post a Comment