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: 

subroutine parameters.....

Former Member
0 Kudos

hai.........

can any body give me the difference between 'changing' and 'using' while passing parameters to subroutines.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

using -


means u r using those variables inside the subroutine to carry out some tasks from the main pgm.

changing----


means u r changing the values of those variables based on some operations, conditions etc., which can be used after the perform stmt in the main pgm.

Sharin.

2 REPLIES 2

Former Member
0 Kudos

Hi,

using -


means u r using those variables inside the subroutine to carry out some tasks from the main pgm.

changing----


means u r changing the values of those variables based on some operations, conditions etc., which can be used after the perform stmt in the main pgm.

Sharin.

Former Member
0 Kudos

By Value:When the subroutine is called ,the formal parameters are copies of the actual parameters(with their own storage location)

By Value and Result : the formal parameters have a separate storage location .At the end of subroutine the value of the formal parameter is passed to the storage location of the actual parameter

Assigned

By Reference: when called the formal parameters are not allocated separate storage locations. Instead the address of the actual parameter is passed. Changes to the values of the formal parameters therefore have a direct effect on the assigned main program fields.

PERFORM <name> USING <a1> <a2> <a3> <a4>

FORM <name > TABLES <table name> USING VALUE (<f1>) CHANGING VALUE (<f2>)

Include:

INCLUDE <name>

Function modules:

CALL FUNCTION u2018function nameu2019

EXPORTING u2026

IMPORTING u2026

The EXCEPTIONS parameter is a section in the CALL FUNCTION statement where exceptional situations can be processed.

CALL FUNCTION u2018function nameu2019

EXPORTINGu2026

IMPORTINGu2026

EXCEPTIONS NOT_FOUND = 3D1

NOT_VALID = 3D2

OTHERS = 3D3

CASE SY-SUBRC

WHEN 1

WHEN 2

Source : https://forums.sdn.sap.com/click.jspa?searchID=15094055&messageID=5773174

The USING and CHANGING additions in the FORM statement define the formal parameters of a subroutine. The sequence of the additions is fixed. Each addition can be followed by a list of any number of formal parameters. When you call a subroutine, you must fill all formal parameters with the values from the actual parameters. At the end of the subroutine, the formal parameters are passed back to the corresponding actual parameters.

Within a subroutine, formal parameters behave like dynamic local data. You can use them in the same way as normal local data objects that you would declare with the DATA statement. They mask global data objects with the same name. The value of the parameters at the start of the subroutine is the value passed from the corresponding actual parameter.

Parameters Passed by Reference

You list these parameters after USING or CHANGING without the VALUE addition:

FORM <subr> USING ... <pi> LIKE <f> ...

CHANGING ... <pi> LIKE <f> ...

The formal parameter occupies no memory of its own. During a subroutine call, only the address of the actual parameter is transferred to the formal parameter. The subroutine works with the field from the calling program. If the value of the formal parameter changes, the contents of the actual parameter in the calling program also change.

For calling by reference, USING and CHANGING are equivalent. For documentation purposes, you should use USING for input parameters which are not changed in the subroutine, and CHANGING for output parameters which are changed in the subroutine.

To avoid the value of an actual parameter being changed automatically, you must pass it by value.

Input Parameters That Pass Values

You list these parameters after USING with the VALUE addition:

FORM <subr> USING ... VALUE(<pi>) LIKE <f> ...

The formal parameter occupies its own memory space. When you call the subroutine, the value of the actual parameter is passed to the formal parameter. If the value of the formal parameter changes, this has no effect on the actual parameter.

Output Parameters That Pass Values

You list these parameters after CHANGING with the VALUE addition:

FORM <subr> CHANGING ... VALUE(<pi>) LIKE <f> ...

The formal parameter occupies its own memory space. When you call the subroutine, the value of the actual parameter is passed to the formal parameter. If the subroutine concludes successfully, that is, when the ENDFORM statement occurs, or when the subroutine is terminated through a CHECK or EXIT statement, the current value of the formal parameter is copied into the actual parameter.

If the subroutine terminates prematurely due to an error message, no value is passed. It only makes sense to terminate a subroutine through an error message in the PAI processing of a screen, that is, in a PAI module, in the AT SELECTION-SCREEN event, or after an interactive list event.

Source : https://forums.sdn.sap.com/click.jspa?searchID=15094055&messageID=5788721

Go through the above links to get a better idea.

Have A Good Day

Chaitanya.