Skip to Content

Difference between Using and Changing in Subroutines

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Nov 04, 2015 at 04:26 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 04, 2015 at 03:46 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 19 at 10:16 AM
    -1

    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 .

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.