Application Development 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: 

Difference between Using and Changing in Subroutines

0 Kudos

Hi All,

I am using a Subroutine Example in My Program. I know the basic differences between using and changing each pointing to Call by value and Call by reference respectively. I know that using Call by Value in Subroutines won't change change the values in Actual parameters whatever happens to formal parameters. I am using the following code,

DATA : A TYPE I,

        B TYPE I,

        C TYPE I,

        D TYPE I,

        E TYPE I,

        F TYPE I.

A = 3.

B = 4.

D = 5.

E = 7.

PERFORM ADD USING A B C.

PERFORM ADD USING D E F.

FORM ADD  USING    P_A TYPE I

                                  P_B TYPE I

                                 P_C TYPE I.

P_C = P_A + P_B.

ENDFORM.


Using this code, as per definition in Call by value whatever changes happen to Formal Parameter (P_C) , Value of Actual Parameter (C or F) shouldn't change. But the values of actual parameters ( C and F ) are changing after 'Perform' statement even if I use that in after 'Using' in Subroutine call.


Kindly help me understand this.


Thanks & Regards,


Jai.

1 ACCEPTED SOLUTION

0 Kudos

Hi All,

Got the Solution. I have to use 'Value' after 'Using' for each variables in 'FORM' statement like this,

FORM ADD USING VALUE(P_A) VALUE(P_B) VALUE(P_C).

By using this, Value of Actual Parameters aren't changing.

3 REPLIES 3

Former Member
0 Kudos

Hi Jai

You are setting the value P_C in your routine, so if the system is allowing it, then I assume it's allowed.

If you don't want C or F to change...don't change P_C. Use a different value.

Hope this help.

Regards

Arden

0 Kudos

Hi All,

Got the Solution. I have to use 'Value' after 'Using' for each variables in 'FORM' statement like this,

FORM ADD USING VALUE(P_A) VALUE(P_B) VALUE(P_C).

By using this, Value of Actual Parameters aren't changing.

chauhanmadhav17
Explorer
0 Kudos

When you use USING the value which you assign as a Formal value will not effect the Actual value.

But when we use CHANGING - The Formal value will overwrite on the Actual value.

Formal value is the value which you assign in the Subroutine.

It creates the copy of the VARIABLE.

While USING the VARIABLE value stores in a copy of the ACTUAL VARIABLE'S .

When you use CHANING it STORES in the address of the ACTUAL VARIABLE .