Вы находитесь на странице: 1из 3

Control Break Statements in SAP ABAP

Control break statements are like events inside the loop. There are 5 control break statements in ABAP. These are used within loop.(Except ON CHANGE OF which can be used outside the loop as well)

AT FIRST - ENDAT AT NEW - ENDAT AT END OF - ENDAT AT LAST - ENDAT ON CHANGE OF

Explanation:
AT FIRST : Will trigger at the first run of the loop. AT LAST: Will trigger at the last run of the loop. The below 3 events are normally used when the table is sorted.

AT END OF : When we use At end for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field. The trigger point will be the at the last occurrence of the same value for the field. AT NEW: When we use At new for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field.The trigger point will be the at the first occurrence of the new value for the field.

ON CHANGE OF: On change of it triggers only when there is any change in the particular field. On change of can be used outside the loop too
Below table summarizes the differences between AT NEW and ON CHANGE OF statements. AT NEW It can be used only in AT LOOP statement. ON CHANGE OF It can be used in any loop like SELECT, DO etc..

Only one control field can be used. AT NEW is triggered when a field left to control level changes. Values in the fields to the right of control level contains asterisks and zeros. ELSE addition cannot be used. Changes to work area with AT NEW will be lost.

Multiple control fields separated by OR can be used. ON CHANGE OF is not triggered when a field left to control level changes. Values in the fields to the right of control level contains original values. ELSE addition can be used. Changes to work area with ON CHANGE OF will not be lost.

Difference between append, collect and insert command


Addition of rows can be done either by using append or insert command. Collect command can also be used for the same. So whats the difference between all 3 ? This post will cover it up.

Append command:
Append is used to add entries to end of the internal table. Append will not work for Hashed tables. Append will lead to dump in case you try to add entries in improper sort manner in case of sorted tables. Ex: append wa_mara TO it_mara. "Append lines of" can be used to append another internal table contents having same structure to the other internal table. Ex: APPEND LINES OF it_mara2 to it_mara.

Insert command:
Insert is used to add entries to internal table in the index(line number) specified. Be careful to use this in sorted table else exception/dump will occur if you dont specify the exact line number according to the sort. Ex: INSERT wa_mara INTO it_mara INDEX 3. Insert lines of can be used to copy another internal table contents having same structure to the internal table. We need to mention the line number also from where it will be copied. The existing entries will be shifted accordingly. Ex: INSERT LINES OF it_mara2 INTO it_mara index 1. If you dont want to specify line position explicitly , then you can use insert ... into table. Ex: INSERT wa_mara INTO TABLE it_mara. Similarly : Ex: INSERT LINES OF it_mara2 INTO TABLE it_mara. The line number will be automatically determined based on table type: 1. Standard tables: The line is appended to the end of the internal table. This has thesame effect as the APPEND statement. 2. Sorted tables : The line is inserted into the table automatically according to the sorting of the table key. 3. Hashed tables : The table is inserted into the internal hash administration according to the table key.

Collect command:
Collect is used for summation purpose. If there is no record with that key , then it will create a entry If a entry with same key is already present , then it will add the numeric values of the new record to the existing record without changing the non numeric values.. wa_itab-material = '00001'. wa_itab-qty = 50. COLLECT wa_itab into it_itab. wa_itab-material = '00002'. wa_itab-qty = 100. COLLECT wa_itab into it_itab. Now the contents of IT_ITAB is material => qty 00001 => 50 00002 => 100 wa_itab-material = '00001'. wa_itab-qty = 100. COLLECT wa_itab into it_itab. A entry with key material 00001 is already present having qty as 50. qty 100 will be added to it and the value will become 150 Itab contents after collect is material => qty

00001 00002

=> 150 => 100

Sy-subrc will be zero if the insertion/collection/appending operation is performed successfully.

Вам также может понравиться