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

controlbreak statments

Former Member
0 Likes
811

hai everyone, plz tell me where should we use the control break statments in the reports i want format of the reports

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
783

After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information (such as totals) at the top or bottom of the report. There might also be interim summaries (such as subtotals) within the body of the report.

For example, suppose you need to write the G/L figures from ztxlfc1 for each vendor, with subtotals by fiscal year and a grand total at the bottom of the report.

To do this, you can read the data into an internal table and then, within loop at, use the following statements:

  • at first / endat

  • at last / endat

  • at new / endat

  • at end of / endat

  • sum

  • on change of / endon

on change of differs from at new in the following respects:

  • It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

  • A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

  • When used within a loop, a change in a field to the left of the control level does not trigger a control break.

  • When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

  • You can use else between on change of and endon.

  • You can use it with loop at it where . . ..

  • You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

  • Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

Using on change of in Two Different Ways: Inside of loop at and Inside of select

report ztx1312.

tables ztxlfa1.

data: begin of it occurs 4,

f1 type i,

f2,

f3 type i,

f4,

end of it.

it-f1 = 1. it-f2 = 'A'. it-f3 = 11. it-f4 = 'W'. append it.

it-f1 = 3. it-f2 = 'A'. it-f3 = 22. it-f4 = 'X'. append it.

it-f1 = 1. it-f2 = 'A'. it-f3 = 33. it-f4 = 'Y'. append it.

it-f1 = 2. it-f2 = 'A'. it-f3 = 44. it-f4 = 'Z'. append it.

loop at it.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

endon.

endloop.

write: / 'End of loop'.

  • executing the same code again - the aux field still contains 'A'

loop at it.

at first.

write: / 'Looping without a reset...'.

endat.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

else.

write: / 'on change of not triggered for row', sy-tabix.

endon.

endloop.

write: / 'End of loop'.

*reset the aux field to blanks

clear it-f2.

on change of it-f2.

endon.

loop at it.

at first.

write: / 'Looping after reset...'.

endat.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

endon.

endloop.

write: / 'End of loop'.

free it.

select * from ztxlfa1 where land1 = 'US'.

on change of ztxlfa1-land1.

write: / 'land1=', ztxlfa1-land1.

endon.

endselect.

write: / 'End of select'.

*executing the same select again without a reset works find

select * from ztxlfa1 where land1 = 'US'.

on change of ztxlfa1-land1.

write: / 'land1=', ztxlfa1-land1.

endon.

endselect.

write: / 'End of select'.

O/p :

1 A 11 W

End of loop

Looping without a reset...

on change of not triggered for row 2

on change of not triggered for row 3

on change of not triggered for row 4

End of loop

Looping after reset...

1 A 11 W

End of loop

land1= US

End of select

land1= US

End of select

6 REPLIES 6
Read only

Former Member
0 Likes
783

Hi,

Control level processing is allowed within a LOOP over an internal table. This means that you can divide sequences of entries into groups based on the contents of certain fields.

The control break statements are used within

LOOP AT ITAB.

...

..

ENDLOOP. statements

Internal tables are divided into groups according to the sequence of the fields in the line structure. The first column defines the highest control level and so on. The control level hierarchy must be known when you create the internal table.

The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the HEADER field group. After sorting, you can <b>use the AT statement within a loop</b> to program statement blocks that the system processes only at a control break, that is, when the control level changes.

Please do mark if its useful to you.

Regards,

Saumya

Read only

Former Member
0 Likes
783

Hi,

These are used to calculate the Totals, sums for a particular field.

Itan has to be sorted first before this is used.

Example code:

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Regards,

Anji

Read only

Former Member
0 Likes
783

Refer the demo programs: DEMO_INT_TABLES_AT_1 and DEMO_INT_TABLES_AT_2

Regards,

Ravi

Read only

Former Member
0 Likes
783

Hi vikram,

Control break statement is also called loop events which we can use like

AT FIRST.

AT NEW <f>

AT END of <f>

AT LAST.

These are only used with in the loop.

And also we have another contral break statement ON CHANGE OF. It is used outside loop also.

Regards,

Vinai.k

Read only

Former Member
0 Likes
783

hi,

use control break stmts between Loop at... and endloop.

first u need to <b>sort</b> the internal table

SORT ITAB BY MATNR.

Eg:

LOOP AT ITAB.

AT END OF MATNR.

SUM.

WRITE: / ITAB-MATNR, 'SUB-TOTAL ', ITAB-VALUE.

ENDAT.

ENDAT.

regards,

priya.

ENDLOOP.

Read only

Former Member
0 Likes
784

After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information (such as totals) at the top or bottom of the report. There might also be interim summaries (such as subtotals) within the body of the report.

For example, suppose you need to write the G/L figures from ztxlfc1 for each vendor, with subtotals by fiscal year and a grand total at the bottom of the report.

To do this, you can read the data into an internal table and then, within loop at, use the following statements:

  • at first / endat

  • at last / endat

  • at new / endat

  • at end of / endat

  • sum

  • on change of / endon

on change of differs from at new in the following respects:

  • It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

  • A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

  • When used within a loop, a change in a field to the left of the control level does not trigger a control break.

  • When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

  • You can use else between on change of and endon.

  • You can use it with loop at it where . . ..

  • You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

  • Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

Using on change of in Two Different Ways: Inside of loop at and Inside of select

report ztx1312.

tables ztxlfa1.

data: begin of it occurs 4,

f1 type i,

f2,

f3 type i,

f4,

end of it.

it-f1 = 1. it-f2 = 'A'. it-f3 = 11. it-f4 = 'W'. append it.

it-f1 = 3. it-f2 = 'A'. it-f3 = 22. it-f4 = 'X'. append it.

it-f1 = 1. it-f2 = 'A'. it-f3 = 33. it-f4 = 'Y'. append it.

it-f1 = 2. it-f2 = 'A'. it-f3 = 44. it-f4 = 'Z'. append it.

loop at it.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

endon.

endloop.

write: / 'End of loop'.

  • executing the same code again - the aux field still contains 'A'

loop at it.

at first.

write: / 'Looping without a reset...'.

endat.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

else.

write: / 'on change of not triggered for row', sy-tabix.

endon.

endloop.

write: / 'End of loop'.

*reset the aux field to blanks

clear it-f2.

on change of it-f2.

endon.

loop at it.

at first.

write: / 'Looping after reset...'.

endat.

on change of it-f2.

write: / it-f1, it-f2, it-f3, it-f4.

endon.

endloop.

write: / 'End of loop'.

free it.

select * from ztxlfa1 where land1 = 'US'.

on change of ztxlfa1-land1.

write: / 'land1=', ztxlfa1-land1.

endon.

endselect.

write: / 'End of select'.

*executing the same select again without a reset works find

select * from ztxlfa1 where land1 = 'US'.

on change of ztxlfa1-land1.

write: / 'land1=', ztxlfa1-land1.

endon.

endselect.

write: / 'End of select'.

O/p :

1 A 11 W

End of loop

Looping without a reset...

on change of not triggered for row 2

on change of not triggered for row 3

on change of not triggered for row 4

End of loop

Looping after reset...

1 A 11 W

End of loop

land1= US

End of select

land1= US

End of select