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: 

Hi

Former Member
0 Kudos

Hi all,

I want to use <b>on change of</b> statement in my program, but I am bit confused on the use of it. It's function is not clear to me.

Kindly help me out on this.

Thanks,

Rishi

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Rishi,

Try this, if it can solve your problem:

<b>Use of on change of:</b>

SELECT * FROM T100

WHERE SPRSL = SY-LANGU

AND MSGNR < '010'

ORDER BY PRIMARY KEY.

ON CHANGE OF T100-ARBGB.

ULINE.

WRITE: / '**', T100-ARBGB, '**'.

ENDON.

WRITE: / T100-MSGNR, T100-TEXT.

ENDSELECT.

The first time a statement on change of is executed, the statement block is executed if at least one of the specified data objects is not initial.

If the content of one of the specified data objects has been changed since the last time the statement on change of was executed. For each time the statement on change of is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement on change of is executed while the associated data object is initial.

6 REPLIES 6

Former Member
0 Kudos

HI Rishi,

ON CHANGE

Introduces a branch.

Syntax

ON CHANGE OF <f> [OR <f1> OR <f2>...].

Opens an ON control structure, concluded with ENDON. The statement block is executed whenever the contents of the field <f> or one of the other fields <fi> has changed since the statement was last executed.

Refer the links -

<b>Reward points if this helps.

Manish</b>

Former Member
0 Kudos

the following example might be useful for you .. instead of 'at new f_ebeln' you can also use 'on change of f_ebeln'

loop at it_out.

at new f_ebeln.

netpr_old = 0.

endat.

write:

/2 it_out-f_ebeln color 5,

15 it_out-f_lifnr,

25 it_out-f_ebelp,

35 it_out-f_matnr,

45 it_out-f_netpr,

65 it_out-f_name1.

netpr_tot = it_out-f_netpr + netpr_old.

at end of f_ebeln.

write:

/45 netpr_tot color 3.

write: sy-uline.

endat.

netpr_old = it_out-f_netpr.

endloop.

Former Member
0 Kudos

Hi

<b>ON CHANGE OF</b>

ON CHANGE OF dobj [OR dobj1 [OR dobj2] ... ].

statement_block

ENDON.

The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added, linked by OR.

The first time a statement ON CHANGE OF is executed, the statement block is executed if at least one of the specified data objects is not initial. The statement block is executed for each additional execution of the same statement ON CHANGE OF, if the content of one of the specified data objects has been changed since the last time the statement ON CHANGE OF was executed.

For each time the statement ON CHANGE OF is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement ON CHANGE OF is executed while the associated data object is initial.

This control structure, which is forbidden in classes, is particularly prone to errors and should be replaced by branches with explicitly declared auxiliary variables.

<b>sample</b>

In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed.

DATA spfli_wa TYPE spfli.

SELECT *

FROM spfli

INTO spfli_wa

ORDER BY carrid.

...

ON CHANGE OF spfli_wa-carrid.

...

ENDON.

...

ENDSELECT.

The following section of a program shows how the ON control structure can be replaced by an IF control structure with an explicit auxiliary variable carrid_buffer.

DATA carrid_buffer TYPE spfli-carrid.

CLEAR carrid_buffer.

SELECT *

FROM spfli

INTO spfli_wa

ORDER BY carrid.

...

IF spfli_wa-carrid <> carrid_buffer.

carrid_buffer = spfli_wa-carrid.

...

ENDIF.

...

ENDSELECT.

<b>Reward if usefull</b>

Former Member
0 Kudos

Hi Rishi,

Try this, if it can solve your problem:

<b>Use of on change of:</b>

SELECT * FROM T100

WHERE SPRSL = SY-LANGU

AND MSGNR < '010'

ORDER BY PRIMARY KEY.

ON CHANGE OF T100-ARBGB.

ULINE.

WRITE: / '**', T100-ARBGB, '**'.

ENDON.

WRITE: / T100-MSGNR, T100-TEXT.

ENDSELECT.

The first time a statement on change of is executed, the statement block is executed if at least one of the specified data objects is not initial.

If the content of one of the specified data objects has been changed since the last time the statement on change of was executed. For each time the statement on change of is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement on change of is executed while the associated data object is initial.

Former Member
0 Kudos

Hi,

Welcome to SDN

say u have internal table having following records.

value field1 field2

10

10

20

30

30

40

U want to execute some statements when VALUE field changes, u can try out.

Loop at itab.

on change of itab-value..

write :/' Value changing',itab-value.

ebdon.

endloop

this will result o/p

Value changing 10

Value changing 20

Value changing 30

Value changing 40

    • reawrd if helpful**