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: 

Perform Statement - Using & Changing

Former Member
0 Kudos

Hi Guys,

Can u pls clarify this ??? As i know Using in perform statement is used to pass the parameters to the form....So what's the use of changing extention ??? Can you explain me with an example

1 ACCEPTED SOLUTION

Former Member

HI mavrick Kar

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

Cheers,

Vijay Raheja

10 REPLIES 10

Former Member
0 Kudos

Using - Pass By Value

Changing - Pass By Reference.

You can change the value of the parameter which comes changing list inside the perform and the value will be reflected outside the subroutine.

Regards,

Ravi

Former Member
0 Kudos

Hi,

For USING:

These two additions have an identical function. However, you should always use the same addition as is used in the corresponding FORM definition (for documentary reasons).

The statement passes the parameters p1 p2 p3 ... to the subroutine. A subroutine may have any number of parameters.

The order in which you list the parameters is crucial. The first parameter in the PERFORM statement is passed to the first formal parameter in the FORM defintion, the second to the second, and so on.

You can specify offset and length of a parameter as variables. If you use the addition ' ...USING p1+off(*)', the parameter p1 will be passed with the offset off, but the length will not exceed the total length of the field.

Example

DATA: NUMBER_I TYPE I VALUE 5,

NUMBER_P TYPE P VALUE 4,

BEGIN OF PERSON,

NAME(10) VALUE 'Paul',

AGE TYPE I VALUE 28,

END OF PERSON,

ALPHA(10) VALUE 'abcdefghij'.

FIELD-SYMBOLS <POINTER> TYPE ANY.

ASSIGN NUMBER_P TO <POINTER>.

PERFORM CHANGE USING 1

NUMBER_I

NUMBER_P

<POINTER>

PERSON

ALPHA+NUMBER_I(<POINTER>).

FORM CHANGE USING VALUE(PAR_1)

PAR_NUMBER_I

PAR_NUMBER_P

PAR_POINTER

PAR_PERSON STRUCTURE PERSON

PAR_PART_OF_ALPHA.

ADD PAR_1 TO PAR_NUMBER_I.

PAR_NUMBER_P = 0.

PAR_PERSON-NAME+4(1) = ALPHA.

PAR_PERSON-AGE = NUMBER_P + 25.

ADD NUMBER_I TO PAR_POINTER.

PAR_PART_OF_ALPHA = SPACE.

ENDFORM.

Field contents after the PERFORM statement:

NUMBER_I = 6

NUMBER_P = 6

<POINTER> = 6

PERSON-NAME = 'Paula'

PERSON-AGE = 25

ALPHA = 'abcde j'

Notes

If you want to pass the body of an internal table itab that has a header line, you must use the notation itab[] (see Data Objects). If you do not use the brackets, the header line of the tabel is passed.

The field types and lengths of the parameters remain the same. If a parameter is changed within the subroutine, it will still have the changed value after the subroutine has finished. This does not apply to parameters passed using VALUE. werden.

If you pass literals, they may not be changed unless you pass them to a formal parameter defined with USING VALUE.

TYPES: BEGIN OF ITAB_TYPE,

TEXT(50),

NUMBER TYPE I,

END OF ITAB_TYPE.

DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 100,

BEGIN OF ITAB_LINE,

TEXT(50),

NUMBER TYPE I,

END OF ITAB_LINE,

STRUC like T005T.

...

PERFORM DISPLAY TABLES ITAB

USING STRUC.

FORM DISPLAY TABLES PAR_ITAB STRUCTURE ITAB_LINE

USING PAR like T005T.

DATA: LOC_COMPARE LIKE PAR_ITAB-TEXT.

WRITE: / PAR-LAND1, PAR-LANDX.

...

LOOP AT PAR_ITAB WHERE TEXT = LOC_COMPARE.

...

ENDLOOP.

ENDFORM.

Within the subroutine DISPLAY, you can use any internal table operation to work with the internal table that you passed to it.

Note

If you use TABLES, it must always be the first addition in a PERFORM statement.

Thanks.

Former Member
0 Kudos

Hi,

Changing is assigned for those variables which have certain value before perform and during perfom its get modified.

let's say

Var = 23.

perform -


changing

var--

---

After execution you will have another value of var.

Hope this helps.

Regards

Amit

Former Member
0 Kudos

When you use 'Using' means you are not going to change any value of those variables.

When you use 'Changing' means you are changing those variable and those changed variables will reflect after calling that perform.

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>) [TYPE <t>|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>) [TYPE <t>|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.

Cheers,

Satya

Former Member

HI mavrick Kar

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

Cheers,

Vijay Raheja

Former Member
0 Kudos

See this sample code for CHANGING

DATA : c1 TYPE i, c2 TYPE i, res TYPE i.
c1 = 1.
c2 = 2.
data: subroutinename(3) VALUE 'SUM'.
PERFORM (subroutinename) IN PROGRAM Y_JJTEST1<b>USING c1 c2 CHANGING res.</b>
*WRITE:/ res.
*&---------------------------------------------------------------------
*
*& Form sum
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
form sum using p_c1 p_c2 changing value(p_res).
p_res = p_c1 + p_c2.
endform. " sum

Reward points if this helps u.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Using helps to use the parameter value passed.

Changing helps to change the parameter value and then use the same in main program with changed value.

Sample:
data : val1 type i value 1,
       val2 type i value 0.
perform calc using val1 changing val2.

Write / : 'Changing :' , val2.
write / : 'Using :' , val1.
*&---------------------------------------------------------------------*
*&      Form  calc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_VAL1  text
*      <--P_VAL2  text
*----------------------------------------------------------------------*
form calc  using    p_val1
           changing p_val2.
p_val2 = p_val1 + 100.
*p_val1 = p_val1 + 100.
*Since p_val1 is passed as using,the above is not *permitted
endform.                    " calc

Kindly reward points by clicking the star on the left of reply,if it helps.

0 Kudos

very helpful

0 Kudos

solomon.raja

It's wrong.

data : val1 type i value 1,
       val2 type i value 0.
perform calc using val1 changing val2.

Write / : 'Changing :' , val2.
write / : 'Using :' , val1.
*&---------------------------------------------------------------------*
*&      Form  calc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_VAL1  text
*      <--P_VAL2  text
*----------------------------------------------------------------------*
form calc  using    p_val1
           changing p_val2.
  p_val2 = p_val1 + 100.
  p_val1 = p_val1 + 100. " Warning
endform.                    " calc

This only gives a warning.

If you use:

form calc  using    value(p_val1)
           changing p_val2.

You won't even get a warning.

However, FORM and PERFORM have been obsolete for years and should never be used in new developments.

0 Kudos

This is in keeping with SAP's view that all the world will write Object-Oriented ABAP. Since SAP doesn't do this themselve, most of us have, obviously, decided to ignore the "obsolete" statement. FORM...ENDFORM is described as obsolete on page 342 of the Official ABAP Programming Guidelines manual, published by Galileo Press and sold by SAP Press.

This was the first reference I saw that described this usage as obsolete, thanks for reminding.

How ever There are of course, a few thousand new usages of FORM....ENDFORM being written every day in SAP.