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

General...

Hi,

What is difference between ON Change of & At New Field??

Select Single * from & select Upto 1 rows

Reg,

Suresh.V

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2007 at 03:32 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2007 at 03:31 AM

    Hi,

    1)

    ON CHANGE OF will also work in SELECT..ENDSELECT and LOOP..ENDLOOP.

    AT NEW will work only in LOOP...ENDLOOP..

    2)

    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2007 at 03:34 AM

    Hi Suresh,

    Select Single * from TABLE where <condition>..................

    here, it selects the first row which satisfies the select criteria

    select ... from TABLE ....... Upto 1 rows

    this selects the first row from the table

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Suresh,

      Select Single fetches the 1st record which satifies the WHERE condition whereas SELECT upto 1 row selects any 1 row from the Database table.

      Regarding

      ON CHANGE OF - this is an obselete statement and is recommended not to use the same.

      AT NEW of - It is used within LOOP statement. Every time the field and any other field to the left of it have a new value, this would be triggered.

      Hope this helps.

      Regards,

      Bharati

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

    Hi,

    • The Major Difference is :

    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.

    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set.

    you can check the transaction in tcode se93 and in the table TSTC.

    go thru these..

    http://www.easymarketplace.de/transactions.php

    http://www.sap-img.com/general/find-the-list-of-sap-transaction-codes.htm

    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

    Regards,

    Priyanka.

    Add a comment
    10|10000 characters needed characters exceeded

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

    <b>Both is used for same purpose. But in recent versions of SAP 'ON CHANGE' command is obsolute. Instead SAP recomanded to use "AT NEW FIELD' for the same purpose.</b>

    ON 
    
    Basic form 
    ON CHANGE OF f. 
    
    This statement is not allowed in an ABAP Objects context. See Prohibit ON CHANGE OF - ENDON. 
    
    Effect 
    Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing). 
    
    Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing. 
    
    
    
    Note 
    There are special control structures for processing control breaks in LOOP s on internal tables or extract datasets (AT). 
    
    ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value. 
    
    
    
    Example
    DATA T100_WA TYPE T100. 
    SELECT * FROM T100 
             INTO T100_WA 
             WHERE SPRSL = SY-LANGU AND 
                             MSGNR < '010' 
                       ORDER BY PRIMARY KEY. 
      ON CHANGE OF T100_WA-ARBGB. 
        ULINE. 
        WRITE: / '***', T100_WA-ARBGB, '***'. 
      ENDON. 
      WRITE: / T100_WA-MSGNR, T100_WA-TEXT. 
    ENDSELECT. 
    
    
    
    Displays all messages with their numbers in the logon language, provided the number is less than '010'. 
    Each time the message class changes, it is output.

    AT NEW f. 
    
    The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Compatible Work Area with Control Level Processing and Field Symbols Not Allowed as Control Level Criterion. 
    
    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 fhas a different value than in the preceding (AT NEW) or subsequent (AT END OF) table line. 
    
    
    
    Example
    TYPES: BEGIN OF COMPANIES_TYPE, 
            NAME(30), 
            PRODUCT(20), 
            SALES TYPE I, 
          END   OF COMPANIES_TYPE. 
    
    DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH 
                         NON-UNIQUE DEFAULT KEY INITIAL SIZE 20, 
          WA_COMPANIES TYPE COMPANIES_TYPE. 
    
    ... 
    
    LOOP AT COMPANIES INTO WA_COMPANIES. 
      AT NEW NAME. 
        NEW-PAGE. 
        WRITE / WA_COMPANIES-NAME. 
      ENDAT. 
      WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES. 
      AT END OF NAME. 
        SUM. 
        WRITE: / WA_COMPANIES-NAME, WA_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. 
    
    
    
    If you use AT within a LOOP with an explicitly-specified output area, the area must be compatible with the line type of the internal table so that it can be initialized properly (as described above) at the start of a new control level. 
    
    You can restrict control break criteria further, regardless of whether they were defined statically or dynamically, by specifying offset and/or length

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2007 at 03:52 AM

    Hi Suresh

    The Difference Between On Change Of and At-New is On-Change-Of will trigger in the initial row and also only for that particular field.B ut At-New will trigger whenever The control level Changes...See the simple eg: given below,you will get a clear idea...

    itab-f1 itab-f2 itab-f3.

    On-Change-Of Itabf3.

    At-New f3.

    The Difference is On Change Of will Trigger only the f3 value changes....But At-new will trigger when f1 or f2 or f3 changes..That means any of the field(called control level) changes.

    Also On-Change-of is obsolute so better avoid the use of that...

    The difference between Select Single and Select Upto 'n' rows is

    In Select Single you have to specify all the key fields otherwise it will be a problem.You can goto SLIN check and see the error if you are not giving all the keys. And before using Select Single make sure that with this Criteria only one row is existing in the database table....Because it will retrieve only one row fromk the database.

    In Selecet upto you can specify the number of rows in that 'n' clause and its not necessary to specify all the keys..You can retrieve more that one row using this.

    Hope you got a clear idea...

    Reward All Helpfull Answers.........

    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.