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: 

pre

Former Member
0 Kudos

wht are the prerequisites have to be followed while using 'on change of' and 'at new'

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Have to <b>sort the internal table</b> by that field

<b>Reward points for useful Answers</b>

Regards

Anji

4 REPLIES 4

Former Member
0 Kudos

hi,

a) When AT NEW occurs,

the alpha-numeric fields have ******* in their value,

b) where as in case of ON CHANGE,

the alpha-numeric fields have their corresponding value,

of that particular record,

where the Event gets fired.*----


Other differences are :

ON CHANGE OF can be used any where in the program..

on change of differs from at new in the following respects:

1.It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

2.A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

3.When used within a loop, a change in a field to the left of the control level does not trigger a control break.

4.When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

5.You can use else between on change of and endon.

6.You can use it with loop at it where . . ..

7.You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

8.Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

while

AT NEW can be used only within a loop of an INTERNAL TABLE..

*----


5. Sample program to get the taste of it

(just copy paste)

6.

REPORT ABC.

DATA : BEGIN OF ITAB OCCURS 0,

bukrs like t001-bukrs,

f1(10) type c,

end of itab.

itab-bukrs = '1000'.

itab-f1 = '1111111'.

append itab.

itab-bukrs = '1100'.

itab-f1 = '3333333'.

append itab.

itab-bukrs = '1200'.

itab-f1 = '555555'.

append itab.

*----


AT NEW

loop at itab.

at new bukrs.

write 😕 itab-bukrs , itab-f1.

endat.

endloop.

*----


AT ONCHANGE

loop at itab.

ON CHANGE OF ITAB-BUKRS.

write 😕 itab-bukrs , itab-f1.

ENDON.

endloop.

check these threads..

Former Member
0 Kudos

Hi

Have to <b>sort the internal table</b> by that field

<b>Reward points for useful Answers</b>

Regards

Anji

Former Member
0 Kudos

Hello sandeep,

Please reward valuable answers.

Rakesh.

Former Member
0 Kudos

<b>At New:</b>

AT - itab

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} compi 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, that is, when the control structure is changed. The additions to the AT statements determine the control break at which their statement blocks are executed. Within these statement blocks, the statement SUM can be specified to add together the numeric components of a control level. For the output behavior result, the same applies as for LOOP AT. 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 in each pass of the loop. In order that control level processing is carried out properly, the following rules must be observed: After LOOP, a restricting condition cond can only be specified if this selects a consecutive line block of the internal table. Otherwise, the behavior of control level processing is undefined. The internal table cannot be modified within the LOOP loop. A work area wa specified in the LOOP statement after the addition INTO must be compatible with the line type of the table. The content of a work area wa specified after the addition INTO in the LOOP statement must not be modified. 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 control key remain unchanged. All components with a character-type, flat data type to the right of the current control key are set to character "*" in every position. All the other components to the right of the current control 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. Addition 2 ... |{END OF} compi/>

Effect

: Control levels are defined by the beginning or end of a group of lines with the same content in the component compi (where i = 1, 2, and so on) and in the components to the left of compi. The control breaks take place when the content of the component compi or another component to the left of compi changes.

The compi components can be specified as described in Specification of Components, with the limitation that access to object attributes is not possible here.

Note

If the INTO or ASSIGNING additions are used in the LOOP statement, a field symbol can be entered after AT |{END OF} outside classes, to which the corresponding component of the work area wa or the field symbol <fs> is assigned. This form of dynamic component specification is obsolete and has been replaced by specification in the format (name).

<b>

On Change:</b>

<i>on change is obsolute now.</i>

ON CHANGE OF

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.

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.

Note:

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

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.