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

Explain At New At End At first At Last On change of

Dear All

Pls Explain At New, At End of, At first, At Last ,On change of .

Vikas

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 Jul 12, 2007 at 12:19 PM

    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.

    <b>Reward points for useful Answers</b>

    Regards

    Anji

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 12:26 PM

    hi,

    Control break logic dictates that the table be sorted in the order of the "break" fields.

    a) When AT NEW occurs,

    the alpha-numeric fields have ******* in their value,

    b) where as in case of ON CHANGE,

    the alpha-numeric fields have their corresponding value,

    of that particular record,

    where the Event gets fired.*----


    Other differences are :

    ON CHANGE OF can be used any where in the program..

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

    1.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.

    2.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.

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

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

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

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

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

    8.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.

    while

    AT NEW can be used only within a loop of an INTERNAL TABLE..

    *----


    5. Sample program to get the taste of it

    (just copy paste)

    6.

    REPORT ABC.

    DATA : BEGIN OF ITAB OCCURS 0,

    bukrs like t001-bukrs,

    f1(10) type c,

    end of itab.

    itab-bukrs = '1000'.

    itab-f1 = '1111111'.

    append itab.

    itab-bukrs = '1100'.

    itab-f1 = '3333333'.

    append itab.

    itab-bukrs = '1200'.

    itab-f1 = '555555'.

    append itab.

    *----


    AT NEW

    loop at itab.

    at new bukrs.

    write :/ itab-bukrs , itab-f1.

    endat.

    endloop.

    *----


    AT ONCHANGE

    loop at itab.

    ON CHANGE OF ITAB-BUKRS.

    write :/ itab-bukrs , itab-f1.

    ENDON.

    endloop.

    check these threads..

    differnce-between-at-new-and-on-change-of

    diff-between-at-new-and-on-change-of

    diff-bet-at-new--on-change-of

    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.