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

control break statements

Hi Guru's,

I am new to ABAP.Please can anybody tell me correct difference between AT FIRST,AT LAST,AT NEW F(FIELD),AT THE END OF F(FIELD).

And what is significance of using SUM statement inside the AT AND ENDAT statement.

Thanks

priya.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 05:06 AM

    Hi

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi priya.,

      you can not add values in that events, coz u are processing the itab here not populating.

      if you want to add the integer values in the itab use collect stmt while populating the itab else,

      use SUM command between those control break stmts while processing the itab.

      <b><i>Reward points if useful</i></b>

      Chandra

  • Posted on Dec 03, 2007 at 05:24 AM

    hi

    at first triggers before reading first record of the internal table

    at new <field>triggers whenever field value changes

    at end of <field> triggers at after field vaue changes

    at last triggers after reading last record from internal table

    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.

    reward if u find useful

    Regards.

    Nagesh.Paruchuri

    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.