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: 

form using,changing

Former Member
0 Kudos
8,409

Hi experts,

Can any one give me the simple exmaple on how to use &

where to use


FORM test <b>USING</b> var1 var2 <b>CHANGING</b> 

END FORM.

I want know where exactly used <b>USING</b> & <b>CHANGING</b> and why?

reward guaranteed

thanks

kaki

11 REPLIES 11

Former Member
0 Kudos
1,280

Hi Kaki

try this

***************************************

TABLES: VBAK.

DATA: BEGIN OF I_VBAK OCCURS 0,

VBELN LIKE VBAK-VBELN,

ERDAT LIKE VBAK-ERDAT,

END OF I_VBAK.

****************************************

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN MATCHCODE OBJECT VMVA OBLIGATORY.

****************************************

AT SELECTION-SCREEN.

SELECT SINGLE * FROM VBAK WHERE VBELN IN S_VBELN.

IF SY-SUBRC <> 0.

MESSAGE E000(ZER).

ENDIF.

*****************************************

START-OF-SELECTION.

PERFORM SUB_SELECT USING S_VBELN-LOW S_VBELN-HIGH

CHANGING I_VBAK[].

*****************************************

END-OF-SELECTION.

LOOP AT I_VBAK.

WRITE 😕 I_VBAK-VBELN UNDER 'SALES DOC.', I_VBAK-ERDAT UNDER

'ORDER DATE'.

ENDLOOP.

*****************************************

TOP-OF-PAGE.

WRITE: 10 'SALES DOC.', 30 'ORDER DATE'.

*****************************************

FORM SUB_SELECT USING S_VBELN_LOW S_VBELN_HIGH

CHANGING I_VBAK TYPE INDEX TABLE.

SELECT VBELN ERDAT INTO TABLE I_VBAK FROM VBAK WHERE VBELN BETWEEN

S_VBELN_LOW AND S_VBELN_HIGH.

ENDFORM.

regards

kishore

Former Member
0 Kudos
1,280

HI

report ztx1805.

data: f1 value 'A',

f2 value 'B'.

write: / f1, f2.

perform s1 using f1

changing f2.

write: / f1, f2.

<b> form s1 using p1

changing p2.

p1 = p2 = 'X'.

endform.</b>

IF THIS IS HELPFUL PLEASE REWARD POINTS.

REGARDS

ANOOP

Former Member
0 Kudos
1,280

Hi,

DATA : v1 , v2 , v3.

v1 = 10.

v2 = 20.

Perform change_values using v1 v2 changing v3.

form change_values using p_v1 p_v2 changing P_v3.

p_v3 = p_v1 + p_v2.

endform.

After the perform call V3 has a value 30.

Regards,

GSR.

Former Member
0 Kudos
1,280

HI Kaki,

Using variables are used to pass the input data to the subroutine. Whereas the changing Variables are (Pass by reference) used for passing Input as well as getting the output in the same variable.

Perform test using var1 var2 changing var3.

the value of var 3 here will be equal to the sum of

var1,2 & 3.

whereas var1 and var2 remain unchanged.

....

...

FORM test USING p1 p2 CHANGING p3

data : p4 type c.

p4 = p1 + p2 + p3

p3 = p4.

END FORM.

Hope it helps....

Lokesh

pls. reward appropriate points

hymavathi_oruganti
Active Contributor
0 Kudos
1,280

DIFFERENCE BETWEEN USING AND CHANGING:

THERE ARE THREE TYPES OF PASSING PARAMETERE RIGHT!,

<b>1. PASS BY VALUE

2. PASS BY REFERNCE

3. PASS BY VALUE AND RETURN</b>.

<u><b>

PASS BY VAUE</b></u>: WE WILL USE <b>USING VALUE </b> in this type, this means we are passing the parameter and any changes to the parameter inside the form will not affect the parameter outside the form, means the value of the parameter is changed only inside the form locally, but not globally. EX: <b>PERFORM SUB USING (VALUE A)</b>

<u><b>PASS BY REFERENCE</b></u>: WE WILL USE <b>USING</b> or<u><b> CHANGING</b></u> while passing parameters

ex <b>PERFORM SUB USING A</b> or <b>PERFORM SUB CHANGING A</b>. any changes to the parameter inside the form are affected globally, means the value is changed permanantly.

<u><b>PASS BY VALUE AND RETURN</b></u>: WE WILL USE

<b>CHANGING VALUE</b> HERE. IT MEANS , THE CHANGES TO THE

PARAMETERS INSIDE THE FORM ARE EFFECTED GLOBALLY LIKE THE 2ND CASE UNLESS AND UNTIL THE FORM IS EXITED EXPLICITLY WITH OUT REACHING THE END OF FORM.

<b>INSIDE THE FORM, IF THERE IS AN EXIT STATEMENT OR IF THERE

IS SOME ERROR SO THAT IT GOES TO DUMP, THEN THE CHANGES ARE NOT EFFECTED GLOBALLY AND EFFECTS ONLY LOCALLY</b>.

Former Member
0 Kudos
1,280

Hi kaki

this can give you the diference between the using and chnaging

data: test type i value 10,test1 type i value 10.

perform sum using test changing test1.

write: test,test1.

form sum using value(test) changing test1.

test = test + 10.

test1 = test1 + 10.

endform.

regards

kishore

Former Member
0 Kudos
1,280

Hi Kaki,

When you use FORM test USING var1 and

FORM test changing var1 ..

its all one and the same..

BUT ..Formal parameters defined for pass by reference should not be changed in the subroutine using USING.

You should use CHANGING instead WHEN YOU ARE GOING TO CHANGE THE VARIABLE ...

...

But there is a difference in using the value() addition in both ..

in USING value()..

the change in the value is not reflected outside form..

in CHANGING value().

the change in the value is not reflected outside form<b> until ENDFORM is reached</b>.. incase the FORM is terminated before ENDFORM is reached..eg.

using STOP .. the change is not reflected in this case also..

regards

satesh

Former Member
0 Kudos
1,280

Hi Kaki ,

We can use form with either USING , CHANGING or Tables as the signature.

Points to remmber.

1)FORM test USING var1 var2

      • normal use of var1 and var2 for procssing data.

END FORM.

This means that we will be making use of Var1 and Var2 in our routine, we are not changing any values or anything is not outputed from it.

2)FORM test USING var1 var2 CHANGING var3

var3 = var1 - var2 .

END FORM.

This forms particularly means that v will be making use of var1 and var2 in the form which will be helpful to fetch the value of var3 which will be outputed from the form.

I hope you will now be clear with their uses.

If helpful do reward points.

Cheers

Sunny

Former Member
0 Kudos
1,280

HI

IF YOU ARE PASSING BY REFERNCE THERE IS ABSOLUTELY NO DIFFERENCE BETWEEN USING and CHANGING.

For calling by reference, USING and CHANGING are equivalent.

For documentation purposes, you should use <u>USING</u> for input parameters which are not changed in the subroutine, and <u>CHANGING</u> for output parameters which are changed in the subroutine.

REGARDS

ANOOP

Message was edited by: ANOOP R.S

abdul_hakim
Active Contributor
0 Kudos
1,280

Hi Kaki,

Techically there is no difference between USING and CHANGING but if you change the value passed with CHANGING you will get a warning in extended program check.

So SAP is advicing to use USING for input and CHANGING for output.

for eg,

<b>PARAMETERES: A1 TYPE I,

A2 TYPE I.

DATA RES TYPE I.

PERFORM SUB1 USING A1 A2 CHANGING RES.

WRITE RES.

FORM SUB1 USING L_1 L_2 CHANGING L_3.

L_3 = L_1 + L_2.

ENDFORM.</b>

Regards,

Abdul Hakim

Former Member
0 Kudos
1,280

<b>

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.

</b>