<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Control Break Statements in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473653#M834945</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One more diff is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case of AT NEW,&lt;/P&gt;&lt;P&gt;   At a time we specify one filed name. But we can call n no.of times with different field names.&lt;/P&gt;&lt;P&gt;Loop itab.&lt;/P&gt;&lt;P&gt; at new f&lt;/P&gt;&lt;P&gt;end at.&lt;/P&gt;&lt;P&gt;at new g&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case of on change of,&lt;/P&gt;&lt;P&gt; we specify more than one field at a time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on change of f g.&lt;/P&gt;&lt;P&gt;endon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At Statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The AT statement introduces a statement block that you end with the ENDAT statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT level.&lt;/P&gt;&lt;P&gt;  statement block&lt;/P&gt;&lt;P&gt;ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can react to the following control level changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;level&lt;/P&gt;&lt;P&gt; Meaning&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;FIRST&lt;/P&gt;&lt;P&gt; First line of the internal table&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;LAST&lt;/P&gt;&lt;P&gt; Last line of the internal table&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;NEW f&lt;/P&gt;&lt;P&gt; Beginning of a group of lines with the same contents in the field f and in the fields left of f&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;END Of f&lt;/P&gt;&lt;P&gt; End of a group of lines with the same contents in the field f and in the fields left of f&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use control level statements to react to control breaks in internal tables instead of programming them yourself with logical expressions. Within the loop, you must order the AT-ENDATstatement blocks according to the hierarchy of the control levels. If the internal table itab has the columns f1, f2,.... and if it is sorted by these columns, you must program the loop as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab.&lt;/P&gt;&lt;P&gt;  AT FIRST.... ENDAT.&lt;/P&gt;&lt;P&gt;    AT NEW f1....... ENDAT.&lt;/P&gt;&lt;P&gt;      AT NEW f2....... ENDAT.&lt;/P&gt;&lt;P&gt;     ....... &lt;/P&gt;&lt;P&gt;          single record processing&lt;/P&gt;&lt;P&gt;     ....... &lt;/P&gt;&lt;P&gt;      AT END OF f2.... ENDAT.&lt;/P&gt;&lt;P&gt;    AT END OF f1.... ENDAT.&lt;/P&gt;&lt;P&gt;  AT LAST..... ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The innermost hierarchy level single line processing processes the table lines that do not correspond to a control level change. You do not have to use all control level statements. But you must place the ones that you use in the above sequence. You should not use control level statements in loops where the line selection is restricted by WHERE or FROM and TO. Neither should the table be modified during the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a control level field f1, f2,.... is not known until runtime, you can specify it dynamically as (n1), (n2), &amp;#133; where n1, n2,.... contains the field of f1, f2,.... . If n1, n2,....  is empty at runtime, the criterion for changing the control level is ignored. You can further restrict the group level fields  f1, f2,.... to partial fields by specifying offset and length.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are working with a work area wa, it does not contain the current line in the AT-ENDATstatement block. All character fields to the right of the current group key are filled with asterisks (*). All other fields to the right of the current group key contain their initial value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within an AT-ENDAT block, you can calculate the contents of the numeric fields of the corresponding control level using the SUMstatement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can only use this statement within a LOOP. If you use SUM in an AT-ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes them to the corresponding fields in the work area (see example in  ). If you use the SUM statement outside an AT-ENDAT block (single entry processing), the system calculates totals for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT-ENDAT blocks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the table contains a nested table, you cannot use the SUMstatement. Neither can you use it if you are using a field symbol instead of a work area in the LOOP statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT demo_int_tables_at_1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF line,&lt;/P&gt;&lt;P&gt;         col1(1) TYPE c,&lt;/P&gt;&lt;P&gt;         col2 TYPE i,&lt;/P&gt;&lt;P&gt;         col3 TYPE i,&lt;/P&gt;&lt;P&gt;      END OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE HASHED TABLE OF line&lt;/P&gt;&lt;P&gt;          WITH UNIQUE KEY col1 col2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line-col1 = 'A'.&lt;/P&gt;&lt;P&gt;DO 3 TIMES.&lt;/P&gt;&lt;P&gt;  line-col2 = sy-index.&lt;/P&gt;&lt;P&gt;  line-col3 = sy-index ** 2.&lt;/P&gt;&lt;P&gt;  INSERT line INTO TABLE itab.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line-col1 = 'B'.&lt;/P&gt;&lt;P&gt;DO 3 TIMES.&lt;/P&gt;&lt;P&gt;  line-col2 = 2 * sy-index.&lt;/P&gt;&lt;P&gt;  line-col3 = ( 2 * sy-index ) ** 2.&lt;/P&gt;&lt;P&gt;  INSERT line INTO TABLE itab.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO line.&lt;/P&gt;&lt;P&gt;  WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;  AT END OF col1.&lt;/P&gt;&lt;P&gt;    SUM.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;    WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;    SKIP.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;  AT LAST.&lt;/P&gt;&lt;P&gt;    SUM.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;    WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The list output is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          1          1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          2          4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          3          9&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          6         14&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          2          4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          4         16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          6         36&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B         12         56&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;        18         70&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program creates a hashed table itab, fills it with six lines, and sorts it. In the LOOP - ENDLOOP block, the work area LINE is output for each loop pass. The first field of the table key, col1, is used for control level processing. The total for all numeric fields is always calculated when the contents of col1 change and when the system is in the last loop pass. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; REPORT demo_int_tables_at_2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF line,&lt;/P&gt;&lt;P&gt;        carrid   TYPE sbook-carrid,&lt;/P&gt;&lt;P&gt;        connid   TYPE sbook-connid,&lt;/P&gt;&lt;P&gt;        fldate   TYPE sbook-fldate,&lt;/P&gt;&lt;P&gt;        custtype TYPE sbook-custtype,&lt;/P&gt;&lt;P&gt;        class    TYPE sbook-class,&lt;/P&gt;&lt;P&gt;        bookid   TYPE sbook-bookid,&lt;/P&gt;&lt;P&gt;      END OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY table_line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT carrid connid fldate custtype class bookid&lt;/P&gt;&lt;P&gt;       FROM sbook INTO CORRESPONDING FIELDS OF TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  AT FIRST.&lt;/P&gt;&lt;P&gt;    WRITE / 'List of Bookings'.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    AT NEW carrid.&lt;/P&gt;&lt;P&gt;      WRITE: / 'Carrid:', line-carrid.&lt;/P&gt;&lt;P&gt;    ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      AT NEW connid.&lt;/P&gt;&lt;P&gt;        WRITE: / 'Connid:', line-connid.&lt;/P&gt;&lt;P&gt;      ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        AT NEW fldate.&lt;/P&gt;&lt;P&gt;          WRITE: / 'Fldate:', line-fldate.&lt;/P&gt;&lt;P&gt;        ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          AT NEW custtype.&lt;/P&gt;&lt;P&gt;            WRITE: / 'Custtype:', line-custtype.&lt;/P&gt;&lt;P&gt;          ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;               WRITE: / line-bookid, line-class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            AT END OF class.&lt;/P&gt;&lt;P&gt;              ULINE.&lt;/P&gt;&lt;P&gt;            ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example, the sorted internal table itab is filled with data from the database table SBOOK using the Open SQL statement SELECT. The sequence of the columns in the internal table defines the control level hierarchy. Since the table key is the entire line, the sort sequence and the control level hierarchy are the same. The sequence of the AT-ENDAT blocks within the LOOP - ENDLOOP statements is important.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output looks something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;List of Bookings&lt;/P&gt;&lt;P&gt;Carrid: AA&lt;/P&gt;&lt;P&gt;Connid: 0017&lt;/P&gt;&lt;P&gt;Fldate: 1998/11/22&lt;/P&gt;&lt;P&gt;Custtype: B&lt;/P&gt;&lt;P&gt;00063509 C&lt;/P&gt;&lt;P&gt;00063517 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;00063532 F&lt;/P&gt;&lt;P&gt;00063535 F&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;Custtype: P&lt;/P&gt;&lt;P&gt;00063653 C&lt;/P&gt;&lt;P&gt;00063654 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;00063668 F&lt;/P&gt;&lt;P&gt;00063670 F&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;Fldate: 1998/29/11&lt;/P&gt;&lt;P&gt;Custtype: B&lt;/P&gt;&lt;P&gt;00064120 C&lt;/P&gt;&lt;P&gt;00064121 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On chnage of event:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ON CHANGE OF dobj [OR dobj1 [OR dobj2] ... ]. &lt;/P&gt;&lt;P&gt;  statement_block &lt;/P&gt;&lt;P&gt;ENDON. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect: &lt;/P&gt;&lt;P&gt;The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added, linked by OR. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first time a statement ON CHANGE OF is executed, the statement block is executed if at least one of the specified data objects is not initial. The statement block is executed for each additional execution of the same statement ON CHANGE OF, if the content of one of the specified data objects has been changed since the last time the statement ON CHANGE OF was executed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each time the statement ON CHANGE OF is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement ON CHANGE OF is executed while the associated data object is initial. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: &lt;/P&gt;&lt;P&gt;This control structure, which is forbidden in classes, is particularly prone to errors and should be replaced by branches with explicitly declared auxiliary variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: &lt;/P&gt;&lt;P&gt;In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA spfli_wa TYPE spfli. &lt;/P&gt;&lt;P&gt;SELECT * &lt;/P&gt;&lt;P&gt;       FROM spfli &lt;/P&gt;&lt;P&gt;       INTO spfli_wa &lt;/P&gt;&lt;P&gt;       ORDER BY carrid. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  ON CHANGE OF spfli_wa-carrid. &lt;/P&gt;&lt;P&gt;    ... &lt;/P&gt;&lt;P&gt;  ENDON. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following section of a program shows how the ON control structure can be replaced by an IF control structure with an explicit auxiliary variable carrid_buffer. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA carrid_buffer TYPE spfli-carrid. &lt;/P&gt;&lt;P&gt;CLEAR carrid_buffer. &lt;/P&gt;&lt;P&gt;SELECT * &lt;/P&gt;&lt;P&gt;       FROM spfli &lt;/P&gt;&lt;P&gt;       INTO spfli_wa &lt;/P&gt;&lt;P&gt;       ORDER BY carrid. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  IF spfli_wa-carrid &amp;lt;&amp;gt; carrid_buffer. &lt;/P&gt;&lt;P&gt;    carrid_buffer = spfli_wa-carrid. &lt;/P&gt;&lt;P&gt;    ... &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is helpful rewards points.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Pratap.M&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Mar 2008 05:52:16 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-08T05:52:16Z</dc:date>
    <item>
      <title>Control Break Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473651#M834943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;In Control break statements what is the difference between 'At New '  and 'On Change'  statements.&lt;/P&gt;&lt;P&gt;Thanks in advance .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 17:07:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473651#M834943</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-07T17:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Control Break Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473652#M834944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At New&lt;/P&gt;&lt;P&gt;1. When a new record comes at new triggers. Atnew only used inside loop and endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. At new is controlbreak statment on at new the left side field change, the event &lt;/P&gt;&lt;P&gt;trigers and the values become 0 and *&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On Change&lt;/P&gt;&lt;P&gt;1. On change of works same like at-new but the diff is it can be used out side of a loop,like select and &lt;/P&gt;&lt;P&gt;endselect,case endcase.&lt;/P&gt;&lt;P&gt;2.. on change of is not a control break statement and we can use onchange of out side the loop&lt;/P&gt;&lt;P&gt;and &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Major difference between the two is that AT NEW can be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;used ONLY for INTERNAL TABLES, while ON CHANGE OF can be used for any loop processing i.e do..enddo, while..endwhile and loop..endloop also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we use At new for a field, it will trigger whenever there is any change in al lthe fields from the left to that of the particular field. But when we use On change of it triggers only when there is any change in the particular field. &lt;/P&gt;&lt;P&gt;At new can only be used inside loop. On change of can used outside the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No logical Expressions can be added with at new. Logical expressions like AND OR can be used with on change of. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When AT NEW occurs, the alpha-numeric fields have * in their value,where as in case of On Change, the alphanumeric fields have their Corresponding value, of that particular record, where the Event gets fired. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On Change of executes for the first value of field too, this is not the case with At New.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On change of cannot be used in ABAP objects At new can be used in this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 17:14:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473652#M834944</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-07T17:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Control Break Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473653#M834945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One more diff is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case of AT NEW,&lt;/P&gt;&lt;P&gt;   At a time we specify one filed name. But we can call n no.of times with different field names.&lt;/P&gt;&lt;P&gt;Loop itab.&lt;/P&gt;&lt;P&gt; at new f&lt;/P&gt;&lt;P&gt;end at.&lt;/P&gt;&lt;P&gt;at new g&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case of on change of,&lt;/P&gt;&lt;P&gt; we specify more than one field at a time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on change of f g.&lt;/P&gt;&lt;P&gt;endon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At Statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The AT statement introduces a statement block that you end with the ENDAT statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT level.&lt;/P&gt;&lt;P&gt;  statement block&lt;/P&gt;&lt;P&gt;ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can react to the following control level changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;level&lt;/P&gt;&lt;P&gt; Meaning&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;FIRST&lt;/P&gt;&lt;P&gt; First line of the internal table&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;LAST&lt;/P&gt;&lt;P&gt; Last line of the internal table&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;NEW f&lt;/P&gt;&lt;P&gt; Beginning of a group of lines with the same contents in the field f and in the fields left of f&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;END Of f&lt;/P&gt;&lt;P&gt; End of a group of lines with the same contents in the field f and in the fields left of f&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use control level statements to react to control breaks in internal tables instead of programming them yourself with logical expressions. Within the loop, you must order the AT-ENDATstatement blocks according to the hierarchy of the control levels. If the internal table itab has the columns f1, f2,.... and if it is sorted by these columns, you must program the loop as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab.&lt;/P&gt;&lt;P&gt;  AT FIRST.... ENDAT.&lt;/P&gt;&lt;P&gt;    AT NEW f1....... ENDAT.&lt;/P&gt;&lt;P&gt;      AT NEW f2....... ENDAT.&lt;/P&gt;&lt;P&gt;     ....... &lt;/P&gt;&lt;P&gt;          single record processing&lt;/P&gt;&lt;P&gt;     ....... &lt;/P&gt;&lt;P&gt;      AT END OF f2.... ENDAT.&lt;/P&gt;&lt;P&gt;    AT END OF f1.... ENDAT.&lt;/P&gt;&lt;P&gt;  AT LAST..... ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The innermost hierarchy level single line processing processes the table lines that do not correspond to a control level change. You do not have to use all control level statements. But you must place the ones that you use in the above sequence. You should not use control level statements in loops where the line selection is restricted by WHERE or FROM and TO. Neither should the table be modified during the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a control level field f1, f2,.... is not known until runtime, you can specify it dynamically as (n1), (n2), &amp;#133; where n1, n2,.... contains the field of f1, f2,.... . If n1, n2,....  is empty at runtime, the criterion for changing the control level is ignored. You can further restrict the group level fields  f1, f2,.... to partial fields by specifying offset and length.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are working with a work area wa, it does not contain the current line in the AT-ENDATstatement block. All character fields to the right of the current group key are filled with asterisks (*). All other fields to the right of the current group key contain their initial value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within an AT-ENDAT block, you can calculate the contents of the numeric fields of the corresponding control level using the SUMstatement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can only use this statement within a LOOP. If you use SUM in an AT-ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes them to the corresponding fields in the work area (see example in  ). If you use the SUM statement outside an AT-ENDAT block (single entry processing), the system calculates totals for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT-ENDAT blocks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the table contains a nested table, you cannot use the SUMstatement. Neither can you use it if you are using a field symbol instead of a work area in the LOOP statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT demo_int_tables_at_1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF line,&lt;/P&gt;&lt;P&gt;         col1(1) TYPE c,&lt;/P&gt;&lt;P&gt;         col2 TYPE i,&lt;/P&gt;&lt;P&gt;         col3 TYPE i,&lt;/P&gt;&lt;P&gt;      END OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE HASHED TABLE OF line&lt;/P&gt;&lt;P&gt;          WITH UNIQUE KEY col1 col2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line-col1 = 'A'.&lt;/P&gt;&lt;P&gt;DO 3 TIMES.&lt;/P&gt;&lt;P&gt;  line-col2 = sy-index.&lt;/P&gt;&lt;P&gt;  line-col3 = sy-index ** 2.&lt;/P&gt;&lt;P&gt;  INSERT line INTO TABLE itab.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line-col1 = 'B'.&lt;/P&gt;&lt;P&gt;DO 3 TIMES.&lt;/P&gt;&lt;P&gt;  line-col2 = 2 * sy-index.&lt;/P&gt;&lt;P&gt;  line-col3 = ( 2 * sy-index ) ** 2.&lt;/P&gt;&lt;P&gt;  INSERT line INTO TABLE itab.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO line.&lt;/P&gt;&lt;P&gt;  WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;  AT END OF col1.&lt;/P&gt;&lt;P&gt;    SUM.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;    WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;    SKIP.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;  AT LAST.&lt;/P&gt;&lt;P&gt;    SUM.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;    WRITE: / line-col1, line-col2, line-col3.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The list output is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          1          1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          2          4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          3          9&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A          6         14&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          2          4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          4         16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B          6         36&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B         12         56&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;________________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;        18         70&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program creates a hashed table itab, fills it with six lines, and sorts it. In the LOOP - ENDLOOP block, the work area LINE is output for each loop pass. The first field of the table key, col1, is used for control level processing. The total for all numeric fields is always calculated when the contents of col1 change and when the system is in the last loop pass. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; REPORT demo_int_tables_at_2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF line,&lt;/P&gt;&lt;P&gt;        carrid   TYPE sbook-carrid,&lt;/P&gt;&lt;P&gt;        connid   TYPE sbook-connid,&lt;/P&gt;&lt;P&gt;        fldate   TYPE sbook-fldate,&lt;/P&gt;&lt;P&gt;        custtype TYPE sbook-custtype,&lt;/P&gt;&lt;P&gt;        class    TYPE sbook-class,&lt;/P&gt;&lt;P&gt;        bookid   TYPE sbook-bookid,&lt;/P&gt;&lt;P&gt;      END OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY table_line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT carrid connid fldate custtype class bookid&lt;/P&gt;&lt;P&gt;       FROM sbook INTO CORRESPONDING FIELDS OF TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  AT FIRST.&lt;/P&gt;&lt;P&gt;    WRITE / 'List of Bookings'.&lt;/P&gt;&lt;P&gt;    ULINE.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    AT NEW carrid.&lt;/P&gt;&lt;P&gt;      WRITE: / 'Carrid:', line-carrid.&lt;/P&gt;&lt;P&gt;    ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      AT NEW connid.&lt;/P&gt;&lt;P&gt;        WRITE: / 'Connid:', line-connid.&lt;/P&gt;&lt;P&gt;      ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        AT NEW fldate.&lt;/P&gt;&lt;P&gt;          WRITE: / 'Fldate:', line-fldate.&lt;/P&gt;&lt;P&gt;        ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          AT NEW custtype.&lt;/P&gt;&lt;P&gt;            WRITE: / 'Custtype:', line-custtype.&lt;/P&gt;&lt;P&gt;          ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;               WRITE: / line-bookid, line-class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            AT END OF class.&lt;/P&gt;&lt;P&gt;              ULINE.&lt;/P&gt;&lt;P&gt;            ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example, the sorted internal table itab is filled with data from the database table SBOOK using the Open SQL statement SELECT. The sequence of the columns in the internal table defines the control level hierarchy. Since the table key is the entire line, the sort sequence and the control level hierarchy are the same. The sequence of the AT-ENDAT blocks within the LOOP - ENDLOOP statements is important.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output looks something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;List of Bookings&lt;/P&gt;&lt;P&gt;Carrid: AA&lt;/P&gt;&lt;P&gt;Connid: 0017&lt;/P&gt;&lt;P&gt;Fldate: 1998/11/22&lt;/P&gt;&lt;P&gt;Custtype: B&lt;/P&gt;&lt;P&gt;00063509 C&lt;/P&gt;&lt;P&gt;00063517 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;00063532 F&lt;/P&gt;&lt;P&gt;00063535 F&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;Custtype: P&lt;/P&gt;&lt;P&gt;00063653 C&lt;/P&gt;&lt;P&gt;00063654 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;00063668 F&lt;/P&gt;&lt;P&gt;00063670 F&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;______________________________________________&lt;/P&gt;&lt;P&gt;Fldate: 1998/29/11&lt;/P&gt;&lt;P&gt;Custtype: B&lt;/P&gt;&lt;P&gt;00064120 C&lt;/P&gt;&lt;P&gt;00064121 C&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On chnage of event:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ON CHANGE OF dobj [OR dobj1 [OR dobj2] ... ]. &lt;/P&gt;&lt;P&gt;  statement_block &lt;/P&gt;&lt;P&gt;ENDON. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect: &lt;/P&gt;&lt;P&gt;The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added, linked by OR. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first time a statement ON CHANGE OF is executed, the statement block is executed if at least one of the specified data objects is not initial. The statement block is executed for each additional execution of the same statement ON CHANGE OF, if the content of one of the specified data objects has been changed since the last time the statement ON CHANGE OF was executed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each time the statement ON CHANGE OF is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement ON CHANGE OF is executed while the associated data object is initial. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: &lt;/P&gt;&lt;P&gt;This control structure, which is forbidden in classes, is particularly prone to errors and should be replaced by branches with explicitly declared auxiliary variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: &lt;/P&gt;&lt;P&gt;In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA spfli_wa TYPE spfli. &lt;/P&gt;&lt;P&gt;SELECT * &lt;/P&gt;&lt;P&gt;       FROM spfli &lt;/P&gt;&lt;P&gt;       INTO spfli_wa &lt;/P&gt;&lt;P&gt;       ORDER BY carrid. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  ON CHANGE OF spfli_wa-carrid. &lt;/P&gt;&lt;P&gt;    ... &lt;/P&gt;&lt;P&gt;  ENDON. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following section of a program shows how the ON control structure can be replaced by an IF control structure with an explicit auxiliary variable carrid_buffer. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA carrid_buffer TYPE spfli-carrid. &lt;/P&gt;&lt;P&gt;CLEAR carrid_buffer. &lt;/P&gt;&lt;P&gt;SELECT * &lt;/P&gt;&lt;P&gt;       FROM spfli &lt;/P&gt;&lt;P&gt;       INTO spfli_wa &lt;/P&gt;&lt;P&gt;       ORDER BY carrid. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  IF spfli_wa-carrid &amp;lt;&amp;gt; carrid_buffer. &lt;/P&gt;&lt;P&gt;    carrid_buffer = spfli_wa-carrid. &lt;/P&gt;&lt;P&gt;    ... &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is helpful rewards points.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Pratap.M&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Mar 2008 05:52:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/control-break-statements/m-p/3473653#M834945</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-08T05:52:16Z</dc:date>
    </item>
  </channel>
</rss>

