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: 

Control breaks in ALV

Former Member
0 Kudos

Do any body let me know how to implement Control breaks(at first, at new, at end of, at last) in ALV reports.

ASAP.

Regards.

Sifathur Rahman

4 REPLIES 4

former_member181962
Active Contributor
0 Kudos

The control events are more related to internal tables than ALVs.

See the documentation given in sap:

<i><b>AT - Control breaks 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 an internal table, 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 internal tables only if a loop is actively processing an internal table and reference is to the innermost currently active loop.

The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant.

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 character type 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 numeric fields (see also ABAP 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 LOOPs on extracts, there are also special control break control structures you can use.

Note

Non-Catchable Exceptions:

SUM_OVERFLOW: Overflow when calculating totals with SUM.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Compatible Work Area with Control Level Processing and Field Symbols Not Allowed as Control Level Criterion.

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 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.

If you use AT within a LOOP with an explicitly-specified output area, the area must be compatible with the line type of the internal table so that it can be initialized properly (as described above) at the start of a new control level.

You can restrict control break criteria further, regardless of whether they were defined statically or dynamically, by specifying offset and/or length.

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

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 FIRST.

SUM.

WRITE: 'Sum of all SALES:',

55 WA_COMPANIES-SALES.

ENDAT.

WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-PRODUCT,

55 WA_COMPANIES-SALES.

ENDLOOP.

Non-Catchable Exceptions

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

Runtime Error: AT_BAD_PARTIAL_FIELD_ACCESS

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

Runtime Error: AT_ITAB_FIELD_INVALID

Cause: When dynamically specifying the control break criterion using (name, the field name does not contain a valid subfield name.

Runtime Error: ITAB_ILLEGAL_COMPONENT

Cause: Overflow when totalling with SUM.

Runtime Error: SUM_OVERFLOW

Additional help

Processing TableLines in Loops"</b></i>

Former Member
0 Kudos

Hi ,

Its difficult to handle control break statements in ALV. I guess if you use the sort statement on the fields on which you want to have the control break statement i think it works similar to having a control break statements.

On the output screen try doing a sort on the fields on which you want a control break, you will find out the difference. May be this can help.

Cheers

VJ

Former Member
0 Kudos

Hii

use REUSE_ALV_HIERSEQ_LIST_DISPLAY.

FOr the same FM , u can also use the collapse and expand functionality , This will give u the + and - botton adjacen to unique fields .

Regards

Naresh

former_member188685
Active Contributor
0 Kudos

Hi,

control breaks nothing but building the sort table.

based on your required

sort-fieldname = 'VBELN'.
sort-up = 'X'.
sort-spos = 1.
sort-subtot = 'X'.
append sort to it_sort.

like this you build your sort table, that will trigger at new vbeln.

based on new vbeln you can build totals or subtotals.

regards

vijay