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: 

doubt in control break statement

Former Member
0 Kudos

Hi All,

Is there any way to trigger control break statements at new & at end of for non primary key fields.

i want to trigger both control break statements for my requirement , not at change of, because i want to trigger at end of also. Please let me know if any possibility. Thanks

regards

vishal

9 REPLIES 9

Former Member
0 Kudos

hi vishal,

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.

0 Kudos

Thanks for ur all replies.

Below is my code , can u pls check let me know where is the problem.

when i keep at new kunnr, it working fine, but when i use at new txjcd, its not triggering, please let me know how to get trigger this. Thanks.

types : begin of typ_bset,

bukrs like bset-bukrs,

belnr like bset-belnr,

gjahr like bset-gjahr,

hkont like bset-hkont,

txjcd like bset-txjcd,

end of typ_bset.

data : it_bset type typ_bset occurs 0,

wa_bset type typ_bset.

select-options : s_bukrs for i_bukrs no intervals no-extension.

select bukrs

belnr

gjahr

hkont

txjcd

from bset

into table it_bset

where bukrs in s_bukrs.

loop at it_bset into wa_bset.

at new TXJCD.

write : /1 wa_bset-txjcd.

endat.

write : /5 wa_bset-bukrs, wa_bset-belnr, wa_bset-hkont.

endloop.

0 Kudos

Hi All,

Can any one help me by checking my code , where is the problem in my code, at new TXJCD. statement triggering for each line, unlike new txjcd. Please help me to find error in my ocde.

Regards

Vishal

0 Kudos

hi

AT NEW will be trieggered whenever the control break changes or any field prior to the control level change.

so for eg.

data: begin of itab occurs 0,

f1 type i,

f2 type i,

f3 type i,

end of itab.

do 3 times.

itab-f1 = sy-index.

itab-f2 = sy-index * 2.

itab-f3 = sy-index * 3.

append itab.

enddo.

sort itab.

loop at itab.

at new f2.

write / 'inside at new'.

endat.

endloop.

Note: Here the control break statement AT NEW will be triggered whenever f2 changes or f1 changes.This is the default behaviour of AT NEW and you cannot override it.

Hope this will help you to solve your problem..

Cheers,

Abdul Hakim

Mark all useful answers..

0 Kudos

the only flaw with at new is , it will work properly for the middle fields.

it will display ******** and 0000000000 before and after.

what is the problem for u to use on change of

0 Kudos

Thanks for ur all replies,

As per the fuctionality of the at new statement , in my code, its not triggering at new whene ever the values changes in that perticular filed which i mentioned in at new <f>, it is triggering for each line unlike value of field change, I didnt understand where is the problem in my code.

Hymavathi, i can use on change of , its working fine, but in my requirement i also need to use at end , but when i use (at end txjcd), its not working , means its triggering for evry line .

Can any body check my code which sent in my prevoius code and help me to resolve my problem.

thanks in advance.

regards

vishal

0 Kudos

Hi Priya!

I saw ur Ans in SDN. I have 1 new query about Control Break Statement.......... In the o/p i want.. For a Particular Purchase Organization, i want to SUM all PO values and Invoice values. My Program is like this:

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

REPORT Z_PURCHASING_1 .

tables: s011.

data: begin of itab occurs 0,

ekorg like s011-ekorg,

netwr type i,

rewrt type i,

end of itab.

select ekorg netwr rewrt from s011 into itab.

append itab.

endselect.

sort itab by ekorg.

loop at itab.

at new ekorg.

sum.

endat.

write: /(25) itab-ekorg, (25) itab-netwr, (25) itab-rewrt.

endloop.

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

But the Run-time error occuring SUM_OVERFLOW.

PO VALUE and INVOICE value, the SUM is resulting in Overflow. You know how to takle this OVERFLOW.

...... Please mail me at: harshal.panchal@yahoo.com

I will be very Thankful to you.

Message was edited by: Harshal Panchal

0 Kudos

Hi Priya !

Can I have ur email ID please? I want to ask u abt Control Break statements. Please mail me at harshal.panchal@gmail.com

Thank you.

Former Member
0 Kudos

Hi Vishal,

at new & at end of statment will trigger for even non primary fields too .. the below example illustrates how it can be done

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.

Regards,

Santosh

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.