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: 

sub routines

Former Member
0 Kudos
64

hi

can any one give me sample code for understanding the parametres of a subroutines...especially

 <b>"using"</b>

an

<b>"changing"</b>

parameters in both call by reference and call value method ...

thank u

Ginni

1 ACCEPTED SOLUTION

Former Member
0 Kudos
45

Hi,

PROGRAM FORM_TEST.

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 
             ADD_NUM2 
       CHANGING ADD_SUM.

  ADD_SUM = ADD_NUM1 + ADD_NUM2.
  PERFORM OUT USING ADD_NUM1 ADD_NUM2 ADD_SUM.

ENDFORM.

FORM OUT 
       USING OUT_NUM1 
             OUT_NUM2 
             OUT_SUM.

  WRITE: / 'Sum of', OUT_NUM1, 'and', OUT_NUM2, 'is', OUT_SUM.

ENDFORM.

The produces the following output:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

In this example, the actual parameters NUM1, NUM2, and SUM are passed by reference to the formal parameters of the subroutine ADDIT. After changing ADD_SUM, the latter parameters are then passed to the formal parameters OUT_NUM1, OUT_NUM2, and OUT_SUM of the subroutine OUT.

Input parameters which are changed in the subroutine are also changed in the calling program. To prevent this, you must pass the parameter by value in a USING addition.

2 REPLIES 2

Former Member
0 Kudos
45
data: a type i value 10, 
      b type i value 10.
 
 
perform sum using a changing b.
write: a,b.
 
 
form sum using a changing b.
a = a + 1.
b = b + 1.
endform.

This link will clear all your Doubts reagrding Perform Statement.

Have a look:

http://help.sap.com/saphelp_erp2005/helpdata/en/9f/db977635c111d1829f0000e829fbfe/frameset.htm

Regards,

Santosh

Message was edited by:

Santosh Kumar Patha

Former Member
0 Kudos
46

Hi,

PROGRAM FORM_TEST.

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 
             ADD_NUM2 
       CHANGING ADD_SUM.

  ADD_SUM = ADD_NUM1 + ADD_NUM2.
  PERFORM OUT USING ADD_NUM1 ADD_NUM2 ADD_SUM.

ENDFORM.

FORM OUT 
       USING OUT_NUM1 
             OUT_NUM2 
             OUT_SUM.

  WRITE: / 'Sum of', OUT_NUM1, 'and', OUT_NUM2, 'is', OUT_SUM.

ENDFORM.

The produces the following output:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

In this example, the actual parameters NUM1, NUM2, and SUM are passed by reference to the formal parameters of the subroutine ADDIT. After changing ADD_SUM, the latter parameters are then passed to the formal parameters OUT_NUM1, OUT_NUM2, and OUT_SUM of the subroutine OUT.

Input parameters which are changed in the subroutine are also changed in the calling program. To prevent this, you must pass the parameter by value in a USING addition.