Skip to Content
author's profile photo Former Member
Former Member

hi guru's where we can use control break statements

hi guru's where we can use control break statements plz help me

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 04:25 AM

    Hi Sri,

    Control breaking statements are use in within loop only except <b>on change of</b> 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 :

    <b>AT NEW / ENDAT.

    AT FIRST / ENDAT.

    AT LAST / ENDAT.

    ON CHANGE OF / ENDON.

    AT END OF / ENDAT.

    SUM</b>

    Regards,

    Vijay

    Message was edited by:

    Vijay.V

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 30, 2007 at 04:35 AM

    Hi,

    Within loop we can use control break statement except ON CHANGE OF / ENDON.

    AT NEW / ENDAT.

    AT FIRST / ENDAT.

    AT LAST / ENDAT.

    AT END OF / ENDAT.

    SUM

    Regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 04:35 AM

    Hi,

    Before using control braek statemnets , you SORT the internal table as per the fields we will be using in AT NEW..AT END OF ..

    The main purpose of control break statements is to :

    To display headings (AT FIRST)

    To display SuBHEADING (AT NEW)

    To display subtotals (AT END OF )

    To get grand total and Footer(AT LAST)

    On change of - it can be used in any loops like do, loop at,etc.

    Reward with points if helpful.

    Regards,

    Vani

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 30, 2007 at 04:36 AM

    hi

    control break statements can be used within loop and endloop

    REPORT zinternaltable.

    TYPES:BEGIN OF itab,

    num TYPE i,

    name(10) TYPE c,

    amt type i,

    END OF itab.

    DATA : wa_itab TYPE itab,

    it_itab TYPE STANDARD TABLE OF itab.

    DATA : v_lines TYPE i.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1000.

    append wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 2000.

    append wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1500.

    append wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 500.

    append wa_itab tO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 600.

    append wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 700.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1200.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1300.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1400.

    append wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 900.

    append wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 300.

    append wa_itab TO it_itab.

    sort it_itab.

    LOOP AT it_itab INTO wa_itab.

    at first.

    write :/ 'details of sales order:'.

    uline.

    endat.

    at new num.

    write :/ 'serial num:', wa_itab-num.

    uline.

    endat.

    WRITE :/ wa_itab-num , wa_itab-name , wa_itab-amt.

    at end of num.

    uline.

    sum.

    write :/ 'total amount:',wa_itab-amt.

    uline.

    endat.

    *

    at last.

    sum.

    uline.

    write:/ 'grand total:',wa_itab-amt.

    endat.

    ENDLOOP.

    describe table it_itab lines v_lines.

    WRITE:/'no of records :', v_lines.

    Regards

    Nagesh.Paruchuri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 05:11 AM

    Hi

    All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

    FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

    Some time you will get * when mopving data from this int table to other table using these commands

    so you have to use

    READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 05:41 AM

    hi sri,

    <b>It is used for Report and Module Pool Programming and ALV.</b>

    Contrlo breaking Statements are :

    At New / EndAt.

    At First / EndAt.

    AT LAST / EndAt.

    On Change Of <b><itab></b>/ EndOn.

    At End Of <b><itab></b> / EndAt.

    Sum

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 05:42 AM

    hi sri,

    <b>It is used for Report and Module Pool Programming and ALV.</b>

    Contrlo breaking Statements are :

    At New / EndAt.

    At First / EndAt.

    AT LAST / EndAt.

    On Change Of <b><itab></b>/ EndOn.

    At End Of <b><itab></b> / EndAt.

    Sum

    Thanks

    s.suresh.

    reward if useful

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 06:01 AM

    you run the program in debugguing mode and go with (F5) step by step ,so that you can understand easily.it's a very good one.

    REPORT.

    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.

    <u><b>This is the other example.</b></u>

    Control break statements are used to stop the control at a particular point.

    1. AT NEW f.

    2. AT END OF f.

    3. AT FIRST.

    4. AT LAST.

    Effect

    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 them is then executed if a control break occurs.

    You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing 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 start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

    All default key 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 number fields (see also ABAP/4 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 LOOP s on extracts, there are also special control break control structures you can use.

    Note

    Runtime errors

    SUM_OVERFLOW : Overflow when calculating totals with SUM .

    Variant 1

    AT NEW f.

    Variant 2

    AT END OF f.

    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 f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

    Example

    DATA: BEGIN OF COMPANIES OCCURS 20,

    NAME(30),

    PRODUCT(20),

    SALES TYPE I,

    END OF COMPANIES.

    ...

    LOOP AT COMPANIES.

    AT NEW NAME.

    NEW-PAGE.

    WRITE / COMPANIES-NAME.

    ENDAT.

    WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.

    AT END OF NAME.

    SUM.

    WRITE: / COMPANIES-NAME, 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.

    Note

    Runtime errors

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

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

    ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

    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

    DATA: BEGIN OF COMPANIES OCCURS 20,

    NAME(30),

    PRODUCT(20),

    SALES TYPE I,

    END OF COMPANIES.

    ...

    LOOP AT COMPANIES.

    AT FIRST.

    SUM.

    WRITE: 'Sum of all SALES:',

    55 COMPANIES-SALES.

    ENDAT.

    WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,

    55 COMPANIES-SALES.

    ENDLOOP.

    <u>Also check the following links.</u>

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm

    using-control-break-statements-in-report

    <b>Reward if useful.</b>

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.