Application Development and Automation 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: 
Read only

Control Break events........

Former Member
0 Likes
1,252

When I'm using AT NEW <f>...ENDAT and in <f> I'm taking the 2nd fieldname of the internal table it shows nothing in list. Can anyone tell me whats the problem? Can we use the 2nd field here? If not what should be done?

Thanks

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
1,228

hi Sagar.

AT NEW <FIELD> Is triggered when the <field> is changed or any of it's Left fields are changed.

This is the Example ;

If the internal table has fields A , B ,C.

Then :

SORT ITAB BY A B.

LOOP AT ITAB.

AT NEW B.

WRITE:/ A , B.

ENDAT.

ENDLOOP.

In this case the AT NEW B is triggered even if A is changed or B is changed.

<b>reward if Helpful.</b>

Hi Varma,

Thanks for this. whatever u said is ok but onething can i take more than one field in AT NEW...? and according to your example

AT NEW B.

WRITE:/ A , B.

ENDAT.

the output is same as shown in intenal table i.e; all the values will be shown for field A and B. take the values of A = 1, 2, 3, 4 and B= M, M, M, N. I hav checked it and result is 1 M

2 M

3 M

4 N

Thanks

9 REPLIES 9
Read only

Former Member
0 Likes
1,228

take the second field no problem.But if it is second field in internal table

population there is no problem.other wise some time if the field is not new it goes

to at new command.

Read only

varma_narayana
Active Contributor
0 Likes
1,229

hi Sagar.

AT NEW <FIELD> Is triggered when the <field> is changed or any of it's Left fields are changed.

This is the Example ;

If the internal table has fields A , B ,C.

Then :

SORT ITAB BY A B.

LOOP AT ITAB.

AT NEW B.

WRITE:/ A , B.

ENDAT.

ENDLOOP.

In this case the AT NEW B is triggered even if A is changed or B is changed.

<b>reward if Helpful.</b>

Read only

0 Likes
1,228

Hi Varma,

Thanks for this. whatever u said is ok but onething can i take more than one field in AT NEW...? and according to your example

AT NEW B.

WRITE:/ A , B.

ENDAT.

the output is same as shown in intenal table i.e; all the values will be shown for field A and B. take the values of A = 1, 2, 3, 4 and B= M, M, M, N. I hav checked it and result is 1 M

2 M

3 M

4 N

Thanks

Read only

0 Likes
1,228

I want the result like

1 M

2

3

4 N

Is anything to be done more in code?

Thanks.

Read only

Former Member
0 Likes
1,228

Hello,

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.

<b>AT NEW f.

AT END OF f.</b>

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.

Regards,

LIJO

Read only

Former Member
0 Likes
1,228

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.

Hope this helps.

Regards,

Nicolas.

Read only

Former Member
0 Likes
1,228

Hi,

Fields to the right of second field will be cleared or '*' in side at new block.

Try

On change of <f>

-


endon.. for the same result

Read only

Former Member
0 Likes
1,228

sagar

Read only

Former Member
0 Likes
1,228

Hi,

sort itab by field2.

loop at itab2.

write:/field1.

at new field2.

write field2.

endat.

endloop.

*reward if helpful.*