Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Subroutine Pass by Value, Pass by Reference using xstring

Former Member
0 Likes
447

Hi,

I am trying to check the difference between pass by value, pass by reference, pass by return value to a subroutine. When I tried integers as parameters the following functionality worked. When I am using xstring as parameters I am not getting desired results.

Some one please explain me how the xstring's are passed to a subroutine.

Here I am giving the code and output of the code.


data : s_passbyref    type xstring,
       s_passbyval    type xstring,
       s_passbyretval type xstring.

* Pass by Value, Pass by Reference, Pass by return value - STRINGS
s_passbyref     = 'ABCD'.
s_passbyval     = 'ABCD'.
s_passbyretval  = 'ABCD'.

write : / 'ByRef :', s_passbyref, 20 'By Val :', s_passbyval, 40 'By Return Value : ', s_passbyretval.

perform call_str_sub using s_passbyref s_passbyval changing s_passbyretval.

write : / 'ByRef :', s_passbyref, 20 'By Val :', s_passbyval, 40 'By Return Value : ', s_passbyretval.

form call_str_sub using ps_passbyref value(ps_passbyval) changing value(ps_passbyretval).
  ps_passbyretval = 'XYZ'.
  ps_passbyref    = 'XYZ'.
  ps_passbyval    = 'XYZ'.
endform.

OUTPUT

ByRef : ABCD By Val : ABCD By Return Value : ABCD

ByRef : By Val : ABCD By Return Value :

Thanks in advance

Naveen

2 REPLIES 2
Read only

Former Member
0 Likes
339

try this

write : / 'ByRef :', s_passbyref, 20 'By Val :', s_passbyval, 40 'By Return Value : ', ps_passbyretval.

Read only

0 Likes
339

The parameter "ps_passbyretval" is local to subroutine. Its not accessible in the main program.