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: 

CHANGING

Former Member
0 Kudos

What is the use of keyword CHANGING for:

--- FORM SUB1 CHANGING a b.

and

--- FORM SUB1 CHANGING value(a) value(b).

7 REPLIES 7

Former Member
0 Kudos

Hi,

CHANGING parameters are input and output parameters. When the function module is called, a suitable actual parameter must be specified for every non-optional input or output parameter. When the function module is called, the content of the actual parameter is passed to the input/output parameter, and when the function module is completed, the content of the input/output parameter is passed to the actual parameter. TABLES parameters are table parameters. Table parameters are obsolete CHANGING parameters that are typed as standard tables with a header line. If an internal table without a header line or a table body is passed as an actual parameter to a formal parameter of this type, an empty local header line is generated in the function module. If an internal table with a header line is used as an actual parameter, both the table body and the header line are passed to the function module. Pass by value is not possible in formal parameters defined using TABLES. Formal parameters defined with TABLES can be replaced by formal parameters defined with CHANGING. A local work area can be created for the internal table in the function module by using the addition LIKE LINE OF itab of the DATA statement.

Exceptions

The exception of a function module are defined on the Exceptions tab page in the Function Builder. Here you can select exception classes to define whether class-based exceptions are declared or non-class-based exception are defined. Class-based exceptions are represented in the above syntax by RAISING, and non-class-based exceptions are represented by EXCEPTIONS.

The addition RAISING is used to declare class-based exceptions that can be propagated from the function module to the caller. Exceptions in the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK must be explicitly declared, otherwise a propagation can lead to an interface violation. A violation of the interface leads to the treatable exception CX_SY_NO_HANDLER. Exceptions of the category CX_NO_CHECK are implicitly always declared. The declaration of exceptions of the category CX_STATIC_CHECK is statically checked in the syntax check. For exceptions of the category CX_DYNAMIC_CHECK, the check is not performed until runtime. In a function module in which class-based exceptions are declared with the RAISING addition, the statement CATCH SYSTEM-EXCEPTIONS cannot be used. Instead, the relevant treatable exceptions should be handled in a TRY control structure.

The addition EXCEPTIONS is used to define a list of non-class-based exceptions that can be triggered in the function module using the statements RAISE or MESSAGE RAISING. Exceptions defined in this way - as with formal parameters - are bound to the function module and cannot be propagated. If an exception of this type is triggered in a function module, and no return value has been assigned to it with the homonymous addition EXCEPTIONS of the CALL FUNCTION statement when the call was made, this leads to a runtime error.

Note

For new developments after release 6.10, SAP recommends that you work with class-based exceptions that are independent of the function module.

RFC is a technology which is used to access a functions (Modules) from

the remote systems.

If a function module is set as remote enabled which can be access from

the remote system via RFC.Eg: U can access the Remote enabled function modules in ur VB,Webdynpro,Java,Visual composer program.

A function module can be set as remote enabled by SE37->Go to ur FM->click the option Button "remote enabled".

But Normal function modules can not accessd from the remote system.

Good Example for RFC enabled function module is : BAPI(Business Application Programming Interface)

Note: All BAPIs are Remote enabled but not all remote enabled function modules are BAPI.

CALLING A FUNCTION MODULE:

1)In U ABAP Editor --> Click "Patter" ---> Selection Option Button "Call Function"

--> Write the Corresponding FM name --> Hit Enter

2)The appropriate import ,export Parameters will be displayed in ur editor

3)Pass the Values Here.

Also check these links.

http://www.geocities.com/victorav15/sapr3/abapfun.html

Check this link:

http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm

Check this link:

http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/d94b78ebf811d295b100a0c94260a5/frameset.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm

See the following links:

http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db970e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm

Regards,

Priyanka.

Former Member
0 Kudos

Hi,

The use of changing parameter is you can pass the value by this parameter to form and can get changed value in the same parameter.

PERFORM SUB1 CHANGING a b.

FORM SUB1 CHANGING a b.

a = a+b.

b = b-a.

Now it will use the value of a and b and return the calculated value in same parameter.

hope u understand.

reward if useful.

Thanks

Azad.

Former Member
0 Kudos

Hi,

If a subroutine has a parameter interface, you must supply values to all of the formal parameters in its interface when you call it. You list the actual parameters after the USING or CHANGING addition in the PERFORM statement.

When you pass the values, the sequence of the actual parameters in the PERFORM statement is crucial. The value of the first actual parameter in the list is passed to the first formal parameter, the second to the second, and so on. The additions USING and CHANGING have exactly the same meaning. You only need to use one or the other. However, for documentary reasons, it is a good idea to divide the parameters in the same way in which they occur in the interface definition.

Actual parameters can be any data objects or field symbols of the calling program whose technical attributes are compatible with the type specified for the corresponding formal parameter. When you specify the actual parameters, note that any that you pass by reference to a formal parameter, and any that you pass by value to an output parameter, can be changed by the subroutine. You should therefore ensure that only data objects that you want to be changed appear in the corresponding position of the actual parameter list.

So there is absolutely no difference in the additions USING and CHANGING.. then you may be thinking why the hell did SAP provide both.. the answer is just for the sake of better documentation..

So whenever you write a subroutine its better to give USING only for those parameters which u wont be changing in the subroutine and CHANGING only for those parameters which u'll be definetly changing or updateing or returning the value to the called program

"using Var1" doesn't reflect any changes that we made to Var1 in the subroutine. But "changing Var2" reflects the changes we made to Var2.It is similar to the concept call by value and call by reference.

for ex.

v1=10

v2=20

perform subroutine using v1 changing v2.

form subroutine using a1 changing a2.

a1 =30.

a2=40.

endform.

then the values of v1 = 10 v2 =40.

Look at the link for example Programs

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db979035c111d1829f0000e829fbfe/content.htm

Hope u understood...

Regards

Sudheer

Former Member
0 Kudos

Hi Debarshi,

The keyword CHANGING is used similary to import/exporting values.

FOr Ex.,

a=2, b=3.

PERFORM FORM1 USING a CHANGING b.

FORM FORM1 USING p_a CHANGING p_b.

p_b = p_a * p_b.

(this new value will be exported from this form)

ENDFORM.

THe value of b after the perfom will be 6.

Reward helpful answers.

Regards,

Siddhesh Sanghvi.

0 Kudos

As Sudheer mentions, you can replace CHANGING with USING but you will see warnings in extended program checks if you do this:

 The "CHANGING" parameter "G_VALUE" does not match category "USING" of formal     
 parameter "IO_VALUE". parameters: IO_VALUE, actual parameters: CHANGING).       

I'd suggest you also use a naming convention to indicate whether the value can be "changed" (input & output) or just set (output only) as well to make it easier to spot code problems e.g.:

report zlocal_jc_changing.

data:
  g_value(10)           type c.

start-of-selection.
g_value = 'a'.
perform demo1
  changing
    g_value.
write: / g_value.

perform demo2
  changing
    g_value.
write: / g_value.

perform demo3
  changing
    g_value.
write: / g_value.


*&---------------------------------------------------------------------*
*&      Form  demo1
*&---------------------------------------------------------------------*
form demo1
  using
    io_value            like g_value.
* this form will give Extended check warning
endform.                                                    "demo1

*&---------------------------------------------------------------------*
*&      Form  demo2
*&---------------------------------------------------------------------*
form demo2
  changing
    io_value            like g_value.  "Input/Output
* io_value can be changed = Input + Output
  if io_value = 'a'.
    io_value = 'A'.
  endif.
endform.                                                    "demo2

*&---------------------------------------------------------------------*
*&      Form  demo3
*&---------------------------------------------------------------------*
form demo3
  changing
    o_value             like g_value. "Output
* o_value is output only..
  clear: o_value.
  if sy-uname+0(1) = 'X'.
    o_value = 'X'.
  endif.
endform.                                                    "demo3

Jonathan

0 Kudos

Hi,

The use of value() is you will get the changed value back to the calling program only if the FORM is succesfully completed else the original value before the call to form will be there in the paramters.

But in the first case if the form is exited in between and the value is changed before that in the form you will get that changed value back in your calling porgram which is not advised

Regards,

Sesh

former_member235056
Active Contributor
0 Kudos

Hi,

Mainly the CHANGING keyword is used when we pass the parameter of one type and in output we may get its datatype to be different and these maily occurs when two different datatypes are calculated to give one single output in different format,

This occurs maily at dynamic runtime programs.

In short, CHANGING is used when parameter passed or returned datatype is not known by user.

Pls reward points.

Regards,

Ameet