Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

control break statements?

Former Member
0 Likes
979

1) what r control break statements?

2) can any one send me the step by step procedure for creating userexits in detail? plz help me in this.....

3 REPLIES 3
Read only

Former Member
0 Likes
454

Hello,


Check this.


AT - Control breaks with extracts 
 
 
Variants: 
 
1. AT NEW f. 
 
2. AT END OF f. 
 
3. AT FIRST. 
 
4. AT LAST.
 
5. AT fg.
 
 
 
 
Effect 
In a LOOP which processes a dataset created with EXTRACT, you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT. The sequence of statements which lies between is executed whenever a control break occurs. 
 
You can use these key words for control break processing with extract datasets only if the active LOOP statement is processing an extract dataset. 
 
The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted. 
 
At the end of a control group ( AT END OF, AT LAST), there are two types of control level information between AT and ENDAT: 
 
 
 
If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER), the field CNT(h) contains the number of control breaks in the (subordinate) control level h. 
 
 
For extracted number fields g (see also ABAP Number Types), the fields SUM(g) contain the relevant control totals. 
 
 
 
Notes 
The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur. 
 
 
The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF, AT LAST), not at the beginning (AT FIRST, AT NEW). 
 
 
When calculating totals with SUM(g), the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded. 
 
 
You can also use special control break control structures with LOOPs on internal tables. 
 
 
 
Variant 1 
AT NEW f. 
 
Variant 2 
AT END OF f. 
 
 
 
Effect 
f is a field from the field group HEADER. The enclosed sequence of statements is executed if 
 
 
 
the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER) and 
 
 
 
the field f or a superior sort criterion has a different value in the current LOOP line than in the preceding (AT NEW) or subsequent (AT END OF) record of the extract dataset. 
 
 
 
If f is not an assigned field symbol, the control break criterion is ignored, and the subsequent sequence of statements is not executed. If a field symbol is assigned, but does not point to the HEADER field group, the system triggers a runtime error. 
 
Example
DATA: NAME(30), 
      SALES TYPE I. 
FIELD-GROUPS: HEADER, INFOS. 
INSERT: NAME  INTO HEADER, 
        SALES INTO INFOS. 
... 
LOOP. 
  AT NEW NAME. 
    NEW-PAGE. 
  ENDAT. 
  ... 
  AT END OF NAME. 
    WRITE: / NAME, SUM(SALES). 
  ENDAT. 
ENDLOOP. 
 
 
 
Notes 
If the extract dataset is not sorted before processing with LOOP, no control level structure is defined and the statements following AT NEW or AT END OF are not executed. 
 
 
 
Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF. This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order. 
 
 
 
Variant 3 
AT FIRST. 
 
Variant 4 
AT LAST. 
 
 
 
Effect 
Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST) or on the last loop pass (with AT LAST). 
 
 
 
Variant 5 
AT fg. 
 
 
 
Addition: 
... WITH fg1 
 
 
 
Effect 
This statement makes single record processing dependent on the type of extracted record. 
 
The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record). 
 
 
 
Addition 
... WITH fg1 
 
 
Effect 
Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1. 
 
 
Additional help 
Control Level Processing 
 



If useful reward.
Vasanth 

Read only

Former Member
0 Likes
454

10 Control Break statements are the statements like At new, at first , at end of etc.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm

2) You do not create user exits. User exits are predefoned locations in programs, which do not have any code inside them initially. For customer specific requirements, you can write code inside such routines, function modules and activate the project in CMOD transaction.

http://www.sap-img.com/abap/a-short-tutorial-on-user-exits.htm

Regards,

Ravi

Read only

Former Member
0 Likes
454

Hi,

1) Processing Control Levels

When you sort an extract dataset, control levels are defined in it. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the HEADER field group. After sorting, you can use the AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.

AT NEW <f> | AT END OF <f>.

...

ENDAT.

A control break occurs when the value of the field <f> or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field <f> must be part of the HEADER field group.

If the extract dataset is not sorted, the AT... ENDAT block is never executed. Furthermore, all extract records with the value HEX 00 in the field <f> are ignored when the control breaks are determined.

The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the HEADER field group, but can also be the one determined in the SORT statement.

If you have sorted an extract dataset by the fields <f1>, <f2>, ..., the processing of the control levels should be written between the other control statements as follows:

LOOP.

AT FIRST.... ENDAT.

AT NEW <f1>....... ENDAT.

AT NEW <f2>....... ENDAT.

...

AT <fgi>..... ENDAT.

<single line processing without control statement>

...

AT END OF <f2>.... ENDAT.

AT END OF <f1>.... ENDAT.

AT LAST..... ENDAT.

ENDLOOP.

You do not have to use all of the statement blocks listed here, but only the ones you require.

REPORT DEMO.

DATA: T1(4), T2 TYPE I.

FIELD-GROUPS: HEADER.

INSERT T2 T1 INTO HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 2. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 2. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 1. EXTRACT HEADER.

T1 ='AAAA'. T2 = 3. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

SORT BY T1 T2.

LOOP.

AT FIRST.

WRITE 'Start of LOOP'.

ULINE.

ENDAT.

AT NEW T1.

WRITE / ' New T1:'.

ENDAT.

AT NEW T2.

WRITE / ' New T2:'.

ENDAT.

WRITE: /14 T1, T2.

AT END OF T2.

WRITE / 'End of T2'.

ENDAT.

AT END OF T1.

WRITE / 'End of T1'.

ENDAT.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

This program creates a sample extract, containing the fields of the HEADER field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:

In the loop, the system displays the contents of the dataset and the control breaks it encountered as follows:

2)