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: 

What is the use of at new statement?

Former Member
0 Kudos

What is the use of at new statement?

6 REPLIES 6

former_member386202
Active Contributor
0 Kudos

Hi,

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 1 ... FIRST Effect The control level is defined by the first line of the internal table. The control break takes place when this line is read. Note In the group level AT FIRST, the current group key contains no components and all character-type components of the work area wa are filled with "*" and all remaining components are set to their initial value. 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).

Addition 3

... LAST

Effect

: The control level is defined by the last line of the internal table. The control break takes place when this line is read.

Note

In the group level AT LAST, the current group key contains no components and all character-type components of the work area wa are filled with "*" and all remaining components are set to their initial value.

Regards,

Prashant

Former Member
0 Kudos

Hi,

In a loop, when ever there is new entry for the field, AT NEW is trigerred and the process the block.

FOR EX:

SORT I_VBAP BY VBELN.

LOOP AT I_VBAP.

AT NEW VBELN.

ENDAT.

ENDLOOP.

in the internal table i_vbap, whenever the new vbeln is found, at new event is trigerred.

regards,

madhu

former_member624107
Contributor
0 Kudos

Hi,

AT NEW can be used inside the loop.

AT NEW f.

f is a sub-field of an internal table processed with LOOP. The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before fhas a different value than in the preceding (AT NEW) or subsequent (AT END OF) table line.

Example

TYPES: BEGIN OF COMPANIES_TYPE,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES_TYPE.

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,

WA_COMPANIES TYPE COMPANIES_TYPE.

...

LOOP AT COMPANIES INTO WA_COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / WA_COMPANIES-NAME.

ENDAT.

WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-SALES.

ENDAT.

ENDLOOP.

The AT statements refer to the field COMPANIES-NAME.

Notes

If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name. If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.

By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.

A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.

Former Member
0 Kudos

Former Member
0 Kudos

It is a control statement in table loop...

it trigers for the record having defferent value comparing to the previoues record.

Example.

internal table

data: beign of i_tab occurs 0,

name(10) type c,

no type i,

end of i_tab.

i_tab have the below records.

abc 10,

abc 12

b 10

b 10

c 10

b 10.

here in loop at i_tab.

at new name,

it triggers 1st,3rd,5th,6th records,

endat.

endloop.

*& if u sart the table by name.

records will be

abc 10,

abc 12

b 10

b 10

b 10.

c 10

then it tirggers the records 1st,3rd,6th......only

so before using at new u have to sort the table using all the fields before the column used in at new statement......

Regards,

Vamshidhar .

manubhutani
Active Contributor
0 Kudos

Hi

It is used in a loop

when u loop at internal table

for ex one of the field in internal table is salary

then for first two records have salary 10k then other 3 have 20k

then

in a loop

at new salary

this event will be triggered when loop comes to 3rd record

ie new salary ie 20 k.

then again if three records of 20k are there and then 30 k is there

then this event will be triggered on 6th record when new sal ie 30 is acheived

let me know if issue

please reward points