Application Development and Automation 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: 
Read only

Using and changing explaination with the below code

0 Likes
880

Hello experts,

i have written a simple code to understand the difference between the changing and using parameters, but i am getting the value as 3 4 0. why am i not getting the value as 1 2 0 for p1 p2 p3.



START-OF-SELECTION.

perform test.

form test.

 data: p1 type i value 1,

      p2 type i value 2,

      p3 type i.

 perform test1 using p1 p2 changing p3.

 WRITE: p1,p2,p3.

ENDFORM.

form two USING p2 p3.

  write:/ p3,' ',p2.

endform.

FORM test1 USING p1 TYPE i p2 TYPE i  CHANGING p3 TYPE i.

      data : p4 type i.

 p1 = 3.

 p2 = 4.


ENDFORM.
3 REPLIES 3
Read only

FredericGirod
Active Contributor
684

it is possible but it is "illegal" for SAP

  • A USING parameter declared for pass by reference behaves in the same way as a CHANGING parameter, which however means that the content of the actual parameter could be changed in an illegal way.

if you would like to work with this kind of things, the better is to use Object oriented

Read only

Nawanandana
Active Contributor
684

HI,

If the additions USING and CHANGING are specified, a type-friendly actual parameter p1 p2 ... must be assigned to each of the formal parameters p1 p2 ... and change p3 ... defined using the same additions of the statement FORM TEST1. Together, the actual parameters specified after USING and CHANGING are a single shared list. They are assigned to the formal parameters using the position in the shared list.
that why you value will change according to that. If you need to print 1 2 0 you have pass only the value. kindly look at bellow code .


START-OF-SELECTION.

perform test.

form test.
data: p1 type i value 1,

      p2 type i value 2,
      p3 type i.

 perform test1 using p1 p2 changing p3.


 WRITE: p1,p2,p3.

ENDFORM.

form two USING p2 p3.
  write:/ p3,' ',p2.

endform.

FORM test1 USING VALUE(p1)  VALUE(p2)  CHANGING VALUE(p3).

data : p4 type i.

 p1 = 3.
 p2 = 4.
ENDFORM.

Further plz refer this.PERFORM - parameter_list

Read only

Sandra_Rossi
Active Contributor
0 Likes
684

USING and CHANGING have an identical "changing" behavior if the parameter is passed by reference, but have the expected behaviors (USING arguments cannot change) if the parameter is passed by value.

Creating subroutines is obsolete, use methods instead.