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: 

hai alll

Former Member
0 Kudos

can you tell me about control break statements briefly

5 REPLIES 5

former_member194669
Active Contributor
0 Kudos

Hi,

Chaitanya,

My suggestion is before making a query to make a search in this forum , there are lot thread have answers to queries, that will give you various points of view of your query

Former Member
0 Kudos

Hi

Control break statements use in Loop..endloop.

At new

Ex AT NEW matnr

write : / something

endat.

whenever new material,display something.

At first field

display soemthig

endat

at last

if you want to write or any calclation after that last field use this

end at

at end

if u want to do sum for material

use

AT END

SUM

ENDAT

calculations can be done .

Thanks

Narendran Muthu...

Posts: 6,233

Questions: 4

Registered: 11/21/04

Forum points: 14,694

Unassign

Solved problem (10)

Very helpful answer (6)

Helpful answer (2)

Re: control break statements

Posted: Jun 5, 2007 6:16 AM in response to: Ashu Reply E-mail this post

Hi,

1)

AT NEW will be triggered when the first occurence of the value in the internal table..

Let's say..

1

1

1

2

The AT NEW will be triggered when SY-TABIX = 1 AND SY-TABIX = 4.

2) the AT FIRST will be triggered at the first time of the internal table processing..

IF SY-TABIX = 1.

3) The AT END OF will be triggered at the last occurence of the value..

Let's say..

1

1

1

2

The AT END OF will be triggered at the rows SY-TABIX = 3 & 4

4) AT LAST

AT LAST will be triggered at the last occurence of the internal table processing..

Refer

<b>Reward points if useful</b>

Regards

Ashu

Former Member
0 Kudos

Hi,

Control break statements are used to stop the control at a particular point.

At New.

At End.

At First.

At Last.

On change of.

At New is used when we need to write something for a particular field.i.e.for every new item.

At End is used at the end of the item.

At First and At Last are also like that.

Effect

In a LOOP which processes a dataset created with EXTRACT, you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT. The sequence of statements which lies between is executed whenever a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is processing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted.

At the end of a control group ( AT END OF, AT LAST), there are two types of control level information between AT and ENDAT:

If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER), the field CNT(h) contains the number of control breaks in the (subordinate) control level h.

For extracted number fields g (see also ABAP Number Types), the fields SUM(g) contain the relevant control totals.

Notes

The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur.

The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF, AT LAST), not at the beginning (AT FIRST, AT NEW).

When calculating totals with SUM(g), the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded.

You can also use special control break control structures with LOOPs on internal tables.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

f is a field from the field group HEADER. The enclosed sequence of statements is executed if

the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER) and

the field f or a superior sort criterion has a different value in the current LOOP line than in the preceding (AT NEW) or subsequent (AT END OF) record of the extract dataset.

If f is not an assigned field symbol, the control break criterion is ignored, and the subsequent sequence of statements is not executed. If a field symbol is assigned, but does not point to the HEADER field group, the system triggers a runtime error.

Example

DATA: NAME(30),

SALES TYPE I.

FIELD-GROUPS: HEADER, INFOS.

INSERT: NAME INTO HEADER,

SALES INTO INFOS.

...

LOOP.

AT NEW NAME.

NEW-PAGE.

ENDAT.

...

AT END OF NAME.

WRITE: / NAME, SUM(SALES).

ENDAT.

ENDLOOP.

Notes

If the extract dataset is not sorted before processing with LOOP, no control level structure is defined and the statements following AT NEW or AT END OF are not executed.

Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF. This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST) or on the last loop pass (with AT LAST).

Variant 5

AT fg.

Addition:

... WITH fg1

Effect

This statement makes single record processing dependent on the type of extracted record.

The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record).

Addition

... WITH fg1

Effect

Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1.

Additional help

Control Level Processing

Regards,

Padmam.

mohammed_moqeeth
Active Participant
0 Kudos

Hi Chaitanya,

<b>Following are the control break statements:</b>

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

All default key fields (on the right) are filled with "*" after the current control level key.

All other fields (on the right) are set to their initial values after the current control level key.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.

Notes

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control break control structures you can use.

Note

Runtime errors

SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

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 f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

<b>Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / COMPANIES-NAME.

ENDAT.

WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / COMPANIES-NAME, COMPANIES-SALES.

ENDAT.

ENDLOOP.</b>

The AT statements refer to the field COMPANIES-NAME .

<u>Note:</u>

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.

Note

Runtime errors

AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.

AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT FIRST.

SUM.

WRITE: 'Sum of all SALES:',

55 COMPANIES-SALES.

ENDAT.

WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,

55 COMPANIES-SALES.

ENDLOOP.

Regards,

Moqeeth.

Former Member
0 Kudos

AT - Control break with internal tables

Variants

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

All default key fields (on the right) are filled with "*" after the current control level key.

All other fields (on the right) are set to their initial values after the current control level key.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.

Notes

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control break control structures you can use.

Note

Runtime errors

SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

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 f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / COMPANIES-NAME.

ENDAT.

WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / COMPANIES-NAME, 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.

Note

Runtime errors

AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.

AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT FIRST.

SUM.

WRITE: 'Sum of all SALES:',

55 COMPANIES-SALES.

ENDAT.

WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,

55 COMPANIES-SALES.

ENDLOOP.

AT - Control break with extracts

Variants

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

5. AT fg.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the end of a control group ( AT END OF , AT LAST ), there are two types of control level information between AT and ENDAT :

If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER ), the field CNT(h) contains the number of control breaks in the (subordinate) control level h .

For extracted number fields g (see also ABAP/4 number types ), the fields SUM(g) contain the relevant control totals.

Notes

The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur.

The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF , AT LAST ), not at the beginning ( AT FIRST , AT NEW ).

When calculating totals with SUM(g) , the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded.

You can also use special control break control structures with LOOP s on internal tables.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

f is a field from the field group HEADER . The enclosed sequence of statements is executed if

the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER ) and

the field f or a superior sort criterion has a different value in the current LOOP line than in the prceding ( AT NEW ) or subsequent ( AT END OF ) record of the extract dataset.

Example

DATA: NAME(30),

SALES TYPE I.

FIELD-GROUPS: HEADER, INFOS.

INSERT: NAME INTO HEADER,

SALES INTO INFOS.

...

LOOP.

AT NEW NAME.

NEW-PAGE.

ENDAT.

...

AT END OF NAME.

WRITE: / NAME, SUM(SALES).

ENDAT.

ENDLOOP.

Notes

If the extract dataset is not sorted before processing with LOOP , no control level structure is defined and the statements following AT NEW or AT END OF are not executed.

Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF . This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST ) or on the last loop pass (with AT LAST ).

Variant 5

AT fg.

Addition

... WITH fg1

Effect

This statement makes single record processing dependent on the type of extracted record.

The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record).

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

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm