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

Please go through the code, is it pass by value?

Former Member
0 Likes
1,318

Can any one explain me the diff between call by value and call by reference in Subroutines.

ex :

PERFORM ADD_Z1CLASS1 USING LW_MARA-MATNR

CHANGING IDOC_DATA[].

FORM ADD_Z1CLASS1 USING PV_MATNR TYPE MATNR

CHANGING PT_EDIDD TYPE EDIDD_TT.

Please let me know, if the above code is call by value or call by reference...?

Any suggestions will be appreciated!

Regards,

Kittu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,056

Hiii

I think its call by referenc ebecause u r trying to change the value at the same memory location ..by specifying CHANGING....

Call By Value:

Creates a new memory loaction for use within the

subroutine.The memory is freed once it leaves the

subroutine.Changes made to the variable are not affected

outside the subroutine.

Call By Reference:

Passes a pointer to the memory location.Changes made to the

variable within the subroutine affects the variable outside

the subroutine.

regards

chandu reddy

Can any one explain me the diff between call by value and call by reference in Subroutines.

ex :

PERFORM ADD_Z1CLASS1 USING LW_MARA-MATNR

CHANGING IDOC_DATA[].

FORM ADD_Z1CLASS1 USING PV_MATNR TYPE MATNR

CHANGING PT_EDIDD TYPE EDIDD_TT.

Please let me know, if the above code is call by value or call by reference...?

Any suggestions will be appreciated!

Regards,

Kittu

9 REPLIES 9
Read only

Former Member
0 Likes
1,057

Hiii

I think its call by referenc ebecause u r trying to change the value at the same memory location ..by specifying CHANGING....

Call By Value:

Creates a new memory loaction for use within the

subroutine.The memory is freed once it leaves the

subroutine.Changes made to the variable are not affected

outside the subroutine.

Call By Reference:

Passes a pointer to the memory location.Changes made to the

variable within the subroutine affects the variable outside

the subroutine.

regards

chandu reddy

Read only

0 Likes
1,056

Hi all,

I am new to abap programming

when we say changes made to formal/actual parameter does not affect to formal/actual parameter, what exactly meant by "changes" ?

Regards,

Shiva Sahu

Read only

Former Member
0 Likes
1,056

hi,

using -- Pass by reference

changing -- Pass by reference

using value() -- Pass by value

changing value( )-- Pass by value and result

The main difference between the pass by value and pass by reference is that " In pass by value the actual parameters are not changed while in pass by reference those are changed".

By reference Passes a pointer to the original memory location. Very efficient

By value Allocates a new memory location for use within the subroutine. The memory is freed when the subroutine ends. Prevents changes to passed variable

By value and result Similar to pass by value, but the contents of the new memory is copied back into the original memory before returning. Allows changes and allows a rollback .

Go through the following eg:

pass by ref:

data f1 value 'A'.

perform s1 using f1.

write / f1.

form s1 using p1.

p1 = 'X'.

endform.

o/p is X

using and changing Are Identical in Function

report ztx1805.

data: f1 value 'A',

f2 value 'B'.

write: / f1, f2.

perform s1 using f1

changing f2.

write: / f1, f2.

form s1 using p1

changing p2.

p1 = p2 = 'X'.

endform.

o/p : A B

X X

Pass by value:

data: f1 value 'A'.

perform s1 using f1.

write / f1.

form s1 using value(p1).

p1 = 'X'.

write / p1.

endform.

o/p is X

A

Hope this is clear.

so the code which you have pasted comes under pass by reference.

Reward points if helpful.

Thanks and regards.

Read only

Former Member
0 Likes
1,056

pass by reference

examples

pass by reference

DATA: num1 TYPE i,

num2 TYPE i,

sum TYPE i.

num1 = 2. num2 = 4.

PERFORM addit USING num1 num2 CHANGING sum.

num1 = 7. num2 = 11.

PERFORM addit USING num1 num2 CHANGING sum.

FORM addit

USING add_num1 TYPE any

add_num2 TYPE any

CHANGING add_sum TYPE any.

add_sum = add_num1 + add_num2.

PERFORM out USING add_num1 add_num2 add_sum.

ENDFORM.

FORM out

USING out_num1 TYPE any

out_num2 TYPE any

out_sum TYPE any.

WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.

the changes made in form will be reflected immediatly to the memory location,because actual parameters(parameters with perform statement) and formal parameters(parameters with FORM) are pointing to same memory location

Pass by value:

DATA: num TYPE i VALUE 5,

fac TYPE i VALUE 0.

PERFORM fact USING num CHANGING fac.

WRITE: / 'Factorial of', num, 'is', fac. "#EC NOTEXT

FORM fact

USING value(f_num) TYPE i

CHANGING f_fact TYPE i.

f_fact = 1.

WHILE f_num GE 1.

f_fact = f_fact * f_num.

f_num = f_num - 1.

ENDWHILE.

Here actual parameters and formal parameters are pointing to different memory location

Regds

Murali

Read only

Former Member
0 Likes
1,055

Hi kittu,

the first field PV_MATNR TYPE MATNR and second field PT_EDIDD TYPE EDIDD_TT in the form statement are call by reference.

if u want to use call by value use the addition 'VALUE'

USING VALUE(PV_MATNR)

CHANGING VALUE(PT_EDIDD ).

There is no difference for USING and CHANGING.

the only difference lies with the value addition.

if ur using USING VALUE ADDITION the original parameter values are not changed when u have used CHANGING VALUE ADDITON the original parameter values are effected only the FORM is successfully executed.

Reward if helpful,

Regards,

S.Gangi reddy.

Read only

Former Member
0 Likes
1,055

Fields are passed by Value and Internal Tables are always passed by reference.

See the SAP documentation.

go to abaphelp tcode

Read only

Former Member
0 Likes
1,055

Hello,

Thank you very much for your response!

The info that you had provided was really helpful.

I appreciate it.

Have a good day!

Regards,

Kittu

Read only

former_member194739
Active Participant
0 Likes
1,055
Read only

0 Likes
1,055

Hi Syed,

I have already gone through to this link but still i am not able to find the meaning of "changes made to formal parameter can affect to actual parameter".

what kind of changes can be made to formal parameter and how it can affect to formal parameter. please brief me with an example

Regards,

Shiva Sahu