Skip to Content
author's profile photo
Former Member

Diff. between At New and On Change Of

Hi,

Could anybody exlain the difference between At New event and On Change Of event in detail? And how can we avoid the inner loops that means avoiding inner loops at internal tables.

ex: loop at it_mara.

loop at it_marc.

-


-


endloop.

endloop.

Please send the reply asap.

thanks.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    author's profile photo
    Former Member
    Oct 05, 2005 at 07:14 AM

    "At New" will be triggered if the key of the internal table ( uptill this field ) changes . Key of an internal table can be specified explicitly or if you donot define it all the charcater fields form the key. Sorting of an itab is necessary to use AT NEW.

    DATA : BEGIN OF ITAB OCCURS 0,

    A(5),

    B(5),

    C(5),

    END OF ITAB.

    ... Put some vales in ITAB.

    SORt ITAB.

    LOOP AT ITAB,

    AT NEW A.

    <Only when value of A Changes.>

    ENDAT

    AT NEW B.

    <When Combined vales of A & B Changes i.e either A or B Or both>.

    ENDAT.

    On CHANGE OF B.

    < Every time a value of B changes >

    ENDON.

    ENDLOOP.

    For On change of sorting is not mandatory.

    Cheers.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 05, 2005 at 07:04 AM

    Hi,

    AT command is used for internal table control break processing. You can also use ON CHANGE for internal tables. But SAP suggest using AT for itabs.

    Instead of nested loop, you can use the combination of DO...ENDDO and READ command.

    Cheers

    Vinod

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 05, 2005 at 07:06 AM

    hai.

    the difference between at new and on change of is when you specify the field name in at new <fieldname> and if there are fields to the left of the fieldname specified in at new then the code will be excuted below the at new even if teh value of <fieldname> does not changes. where as in case of on change of <fieldname> even if you have fields towardsleft of the fieldname specified in on change of then the change of value in left of fields will not trigger the code below on change of , only the <fieldname> values has to changed to trigger the code below the on change of.

    you can make use of EXIT command to skip the inner loops based on condition.

    pls come back if any problem

    award points if helpfull.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 05, 2005 at 07:16 AM

    Hi,

    look F1 for both commands:

    on change of is used during GET events or SELECT/ENDSELECT processing.

    at new / at end of is used for itabs in loops

    2) sometimes you cannot avoid an inner loop- if you are searching for morr than 1 entry- here try to use sorted tables to improve performance

    regards Andreas

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 05, 2005 at 07:50 AM

    one more difference is that with at new you can specify only one field as

    REPORT YBALTEST .

    tables: agr_1251.

    data itab like agr_1251 occurs 0 with header line.

    select * from agr_1251 into table itab .

    sort itab by agr_name.

    loop at itab.

    at new agr_name .

    write : / itab-agr_name.

    endat.

    endloop.

    On change of you can mention as many fields you want to , but it should be in accordance with sorting.

    REPORT YBALTEST .

    tables: agr_1251.

    data itab like agr_1251 occurs 0 with header line.

    select * from agr_1251 into table itab .

    sort itab by agr_name.

    loop at itab.

    on change of itab-agr_name or itab-object.

    write : / itab-agr_name, itab-object.

    endon.

    endloop.

    also as you can see above you have to tell on change that this field belongs to which table.

    hope it helps

    regards

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 05, 2005 at 08:20 AM

    Hi,

    Once I had bad experience of using this AT NEW and AT END events.

    Once in my report when i was using this I am able to see the ******** in the fields next to the field what we give to that event.

    Ex: AT END OF BUKRS.

    After the bukrs field what ever the fields we have they will be display in output as **** *****.

    But when I use the ON CHANGE OF the problem was solved.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded