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 break

Former Member
0 Kudos
83

what are the control break statements in Reports?

4 REPLIES 4

Former Member
0 Kudos
64

Control breaking statements are use in within loop only except on change of statement , because on change of can be used in select and also other loops like do while, while also.

This control breaking statements used for we can format the output of internal table contents.

Contrlo breaking Statements are :

AT NEW / ENDAT.

AT FIRST / ENDAT.

AT LAST / ENDAT.

ON CHANGE OF / ENDON.

AT END OF / ENDAT.

SUM

see this program you can understand very easily

Using AT FIRST , AT NEW, AT THE END OF , AT LAST.

DATA: BEGIN OF ITAB OCCURS 0,

F1 TYPE I,

F2(6) TYPE C,

F3(10) TYPE N,

F4(16) TYPE P DECIMALS 2,

END OF ITAB.

DATA: SUB_TOT(10) TYPE P DECIMALS 3.

**--1

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 30.

ITAB-F4 = '3000.00'.

APPEND ITAB.

CLEAR ITAB.

*--2

ITAB-F1 = 2.

ITAB-F2 = 'TWO'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 2.

ITAB-F2 = 'TWO'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

3

ITAB-F1 = 3.

ITAB-F2 = 'THREE'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 3.

ITAB-F2 = 'THREE'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

SORT ITAB BY F1.

LOOP AT ITAB.

AT FIRST.

WRITE: /35 ' MATERIAL DETAILS:'.

ULINE.

ENDAT.

AT NEW F1.

WRITE: / 'DETAILS OF MATERIAL:' COLOR 7 , ITAB-F1.

ULINE.

ENDAT.

WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.

SUB_TOT = SUB_TOT + ITAB-F4.

AT END OF F1.

ULINE.

WRITE: / 'SUB TOTAL :' COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.

CLEAR SUB_TOT.

ENDAT.

AT LAST.

SUM.

ULINE.

WRITE: 'SUM:', ITAB-F4.

ULINE.

ENDAT.

ENDLOOP.

Reward points if useful.

Former Member
0 Kudos
64

Control break statements are of 4 types:

AT FIRST——>this is used for system field heading in ABAP program.

AT NEW———>this is used to display the fields.

AT END———>this is used for row-wise calculation i.e, sub-total.

AT LAST——->this is used for calculation of grand total.

these are the control statements used.

Few Points to remember about control break statements are

#1 when we place control breaks statements with in select & end-select then i will generate an complie time error and says us to use it in loop…...endloop.

#2 when u r using control break commands.internal table must be sorted with key field.and control-break commands must be used in between the LOOP and ENDLOOP only.

Hope this helps

Vinodh Balakrishnan

Former Member
0 Kudos
64

Hi,

Control break statements are used to create statement blocks which process only specific table lines the LOOP – ENDLOOP block.

You open such a statement block with the control level statement AT and close it with the control level statement ENDAT.

Table should be sorted when you use control-break statements. You can break the sequential access of internal tables by using these statements.

1.at first / endat

2.at last / endat

3.at new / endat

4.at end of / endat

5.on change of / endon

Use the at first and at last statements to perform processing during the first or last loop pass of an internal table.

Use at first for:

Loop initialization processing

Writing totals at the top of a report

Writing headings

Use at last for:

Loop termination processing

Writing totals at the bottom of a report

Writing footings

Example code:

DATA: BEGIN OF ITAB OCCURS 0,

BUKRS LIKE LFC1-BUKRS,

UM01H LIKE LFC1-UM01H,

UM01U LIKE LFC1-UM01U,

END OF ITAB.

SELECT BUKRS UM01H UM01U INTO TABLE ITAB FROM LFC1.

SORT ITAB BY BUKRS.

LOOP AT ITAB.

WRITE:/ ITAB-BUKRS,7 ITAB-UM01H,ITAB-UM01U.

AT END OF BUKRS.

SUM.

WRITE:/ ITAB-BUKRS COLOR 7,7 ITAB-UM01H COLOR 7,ITAB-UM01U COLOR 7.

ENDAT.

AT LAST.

SUM.

WRITE:/ ‘TOTAL’ COLOR 3,ITAB-UM01H COLOR 1,ITAB-UM01U COLOR 1.

ENDAT.

ENDLOOP.

reward points,if it is helpful.

Thanks,

chandu

Former Member
0 Kudos
64

Hi chaitanya,

some of the important points before going to use CONTROL BREAK statements.

1.we have to place these statements with in loop.

2.sort the data before going to loop ok.

AT FIRST : FOR HEADINGS

AT NEW : BASED ON FILED DATA IS DISPLAYED

AT END OF : FOR SUBTOTALS

AT LAST : FOR GRAND TOTALS.

syntax:

sort itab by <field1> <field2>

loop at itab.

at first.

endat.

at new <field>

endat.

at end of <filed>

endat

at last

endat.

endloop.

Reward points if helpful.

Kiran Kumar.G.A

Have a Nice Day..