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: 

statements

Former Member
0 Kudos

explain

on change of

endon.

at new

endat.

4 REPLIES 4

Former Member
0 Kudos

on change of f1.

endon.

This is executed whenever a new value of f1 is encountered.

This can be used in loop-endloop as well as do-enddo statements.

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

loop at itab.

on change of itab-f1.

---> code

endon.

endloop.

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

data : a type i.

a = 1.

do 20 times.

a = a + 1.

on change of a.

---> code

endon.

enddo.

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

Also even multiple fields can be checked.

loop at itab.

on change of itab-f1 or itab-f2.

---> code

endon.

endloop.

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

at new f1.

---> code

endat.

Even this is executed whenever new value of f1 is encountered but this cannot be used in do-enddo and also in case of chewcking multiple fields.

Please reward points if you find it useful

Vasu

former_member189059
Active Contributor
0 Kudos

Hello Veera,

why dont you try searching the forums for those answers before posting such questions

incase you do not know how to do so, try this link

https://www.sdn.sap.com/irj/sdn/forumsearch

Former Member
0 Kudos

<b>ON CHANGE OF </b>

Syntax

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

statement_block

ENDON.

Effect:

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.

Example:

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>ENDON </b>

Syntax

ENDON.

Effect

The ENDON statement closes a conditional statement block introducud by ON CHANGE OF.

<b>AT - itab </b>

Syntax

LOOP AT itab result ...

[AT FIRST.

...

ENDAT.]

[AT NEW comp1.

...

ENDAT.

[AT NEW comp2.

...

ENDAT.

[...]]]

[ ... ]

[[[...]

AT END OF comp2.

...

ENDAT.]

AT END OF comp1.

...

ENDAT.]

[AT LAST.

...

ENDAT.]

ENDLOOP.

Extras:

1. ... FIRST

2. ... |{END OF} comp

3. ... LAST

Effect

The statement block of a LOOP loop can contain control structures for control level processing. The respective control statement is AT. The statements AT and ENDAT define statement blocks that are executed at control breaks. Within these statement blocks, the statement SUM can be specified to total numeric components of a group level. In the case of output behavior result, the same applies as for LOOP AT.

So that group level processing can be executed correctly, the following rules should be noted:

After LOOP there should be no limiting condition cond specified.

The internal table must not be modified within the LOOP loop.

The work area wa specified in the LOOP statement after the INTO addition must be compatible with the line type of the table.

The content of a work area wa specified in the LOOP statement after the INTO addition must not be modified.

The prerequisite for control level processing is that the internal table is sorted in exactly the same sequence as the component of its line type - that is, first in accordance with the first component, then in accordance with the second component, and so on. The line structure and the corresponding sorting sequence gives a group structure of the content of the internal table, whose levels can be evaluated using AT statements. The AT-ENDAT control structures must be aligned one after the other, in accordance with the group structure.

The statement blocks within the AT-ENDAT control structures are listed if an appropriate control break is made in the current table line. Statements in the LOOP-ENDLOOP control structure that are not executed within an AT-ENDAT control structure are executed each time the loop is run through.

If the INTO addition is used in the LOOP statement to assign the content of the current line to a work area wa, its content is changed upon entry into the AT-ENDAT control structure as follows:

The components of the current group key will remain unchanged.

All components with a character-type, flat data type to the right of the current group key are set to character "*" at that position.

All the other components to the right of the current group key are set to their initial value.

When the AT-ENDAT control structure is exited, the content of the current table line is assigned to the entire work area wa.

Regards,

Pavan

Former Member
0 Kudos

Hi

syntax for on change of is

ON CHANGE OF <F1> OR <F2> OR...

<...STMTS...>

ENDON.

syntax for at new is

AT NEW <F>

<...stmts..>

ENDAT.

Both trigger when there is a change in value of a given field(s). We can trigger ON,ENDON for multiple field changes by using OR but AT NEW is triggered only for a single field.

In between AT NEW and ENDAT fields dont have the values i.e., primery keys set to blanks,numeric fields set to * s. But fields do have the value in between ON and ENDON.

If the first value of field is zero or blank ON won't be triggered.But AT NEW triggers even the first field is zero or blank.

AT statements i.e., control break events are to be used only in LOOP and ENDLOOP.

ON CHANGE of can be used in any loop,event...