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 statement.

Former Member
0 Likes
1,074

Hi Experts,

I have a requirement, where I used Control break statement and I am using the At New---Endat statement.

As this statement will invoke when a particular value of table field will change.   But I have a table  and the table has the following fields like below.

field1       field2      field3

5              5           5

5              6           5

5               5          5

When I used At New statement for the first row, it ll not invoke and also for 2nd row first column it will not invoke but when it goes for 2nd row 2nd column what will happen  and again for all.   Please explain ??

Regards,

Ajit

9 REPLIES 9
Read only

former_member188827
Active Contributor
0 Likes
1,044

Your question is not clear. If you want to do some processing whenever value of field2 changes, you can do so as follows:

first sort the table by field1 and field2.

Then loop through table and use AT new event.

sort itab by field1 field2.

loop at itab.

at new field2.

...

endat.

endloop.

Regards

Read only

Former Member
0 Likes
1,044

Hi,

As Sap Says, At New-- End at will invoke while a particular field value change.

So In my case for first row it will not invoke.But for 2nd row 2nd column the value is change which is (6).

So in that case the At new-- Endat will invoke. So what will happen to next  ? (Value means  the next rows and next column values.)

Regards,

Ajit

Read only

0 Likes
1,044

Control break statements work when table is sorted according to fields on which you want to apply the statement. In your example, after sorting, your table would be:

field1       field2      field3

5              5           5

5               5          5

5              6           5

Please remember that the statement wont work properly if table is not sorted.

Regards

Read only

Former Member
0 Likes
1,044

Hi,

The statement at new  will not  work properly if table is not sorted.

TYPES:

     BEGIN OF TY_TABLE,

       FIELD1 TYPE I,

       FIELD2 TYPE I,

       FIELD3 TYPE i,

       END OF TY_TABLE.

data:

      t_table TYPE STANDARD TABLE OF TY_TABLE,

      x_table TYPE TY_TABLE.

x_table-FIELD1   = '5'.

x_table-field2   = '5'.

x_table-FIELD3   = '5'.

APPEND x_table to t_table.

x_table-FIELD1   = '5'.

x_table-field2   = '6'.

x_table-FIELD3   = '5'.

APPEND x_table to t_table.

x_table-FIELD1   = '5'.

x_table-field2   = '5'.

x_table-FIELD3   = '5'.

APPEND x_table to t_table.



SORT t_table by FIELD1 FIELD2.



loop at t_table INTO x_table.



at new FIELD2.

write: /, x_table-FIELD2.



endat.



endloop.

Output :

5

6

Read only

former_member209120
Active Contributor
0 Likes
1,044

Hi Ajit Sarangi,

AT NEW.

If a group of lines of a particular column have same value, it can be displayed at the beginning only once using the control level statement

At New <column name>.

     The columns to the left of <column name> are also considered by the 'At New' condition.

For example

Say internal table contents are as follows:

Carrid              connid

AA                  0017                385                  349

AB                  0017                345                  254

AA                  0017                386                  432

AB                  0016                243                  423

Sort internal table before using At New

Carrid              connid

AA                  0017                385                  349

AA                  0017                386                  432

AB                   0017                345                 254

AB                  0016                243                  423

Now Sorted  the use at new

"At New Connid."    Works as follows:

Carrid              Connid

  AA                 0017             

                                               385                  349

                                               386                 432

  AB                  0017             345                 254

  AB                   0016             243                  423  

For your code

field1       field2      field3

5              5           5

5              6           5

5               5          5

it was not in sorted manner so Field2 - 5 6 5 every time new

so it display output 5 6 5.

If you sort the output would like this

TYPES: BEGIN OF ty_final,
        field1 TYPE i,
        field2 TYPE i,
        field3 TYPE i,
        END OF ty_final.

DATA: it_final TYPE TABLE OF ty_final,
       wa_final TYPE ty_final.

wa_final-field1 = '5'.
wa_final-field2 = '5'.
wa_final-field3 = '5'.
APPEND wa_final TO it_final.
CLEAR wa_final.

wa_final-field1 = '5'.
wa_final-field2 = '6'.
wa_final-field3 = '5'.
APPEND wa_final TO it_final.
CLEAR wa_final.

wa_final-field1 = '5'.
wa_final-field2 = '5'.
wa_final-field3 = '5'.
APPEND wa_final TO it_final.
CLEAR wa_final.

SORT it_final BY field1 field2.

LOOP AT it_final INTO wa_final.

   AT NEW field2.

     WRITE: / wa_final-field2.

   ENDAT.

ENDLOOP.

Out put:

5

6

Read only

matt
Active Contributor
0 Likes
1,044

Rather than have people guess at what the issue is, how about posting the relevant section of your program?

Read only

former_member220538
Active Participant
0 Likes
1,044

Hi,

Control break statements works only with sorted table.AT NEW statement will work when values of the field changes.At End Of will trigger when the last value of the field encountered for the specified field in a group of similar fields in an internal table.

If field1 is used in control break statements then AT NEW and AT END OF will be triggered only once.

If field2 is used then AT NEW and AT END OF will be triggered twice if the internal table is sorted if not it will be 3 times. If it is not sorted then in the first row the value will be 5, AT NEW and AT END OF will be triggered  because the next value is 6. Similary in the second row value will be 6 and  control statements will be triggered and so on. You will get exact output only if the table is sorted.

Read only

Former Member
0 Likes
1,044

Hi Ajit ,

Are you using any field name in the at new , at end .As people above suggested do sort and check whether its working .

Else put your code snippet .

Regards

Juneed K Manha

Read only

Former Member
0 Likes
1,044

Thanks To all For this valuable answers...

Regards,

Ajit