Sunday, November 22, 2015

Control Break - AT NEW statement


AT NEW is one of a control break statements. It works inside the LOOP – ENDLOOP. Let’s take an example. We have prepared an internal table where we are storing 50 rows of material, plant & storage location data. Now we run the operation of AT NEW for plant record. Whenever the system finds a new plant with respect to previous then it will trigger the AT NEW statement. Here the internal table must be sorted. Otherwise similar plant may come afterwards and system will trigger AT NEW wrongly.


The program is as follows.

TYPES: BEGIN OF ty_tab,
        werks TYPE mard-werks,
        matnr TYPE mard-matnr,
        lgort TYPE mard-lgort,
       END OF ty_tab.

DATA: wtab TYPE ty_tab,
      itab TYPE TABLE OF ty_tab.

START-OF-SELECTION.

  SELECT matnr werks lgort
    UP TO 30 ROWS FROM mard
    INTO CORRESPONDING FIELDS OF TABLE itab.

  IF sy-subrc = 0.
    SORT itab.
    WRITE: / 'Material', 20 'Plant', 27 'Storage Location'.
    ULINE.

    LOOP AT itab INTO wtab.
      WRITE: / wtab-matnr, 20 wtab-werks, 27 wtab-lgort.

      AT NEW werks.
        WRITE: '***** AT NEW plant triggers at ', sy-tabix.
      ENDAT.
    ENDLOOP.
  ENDIF.

Now we shall see at debugging mode how AT NEW works. At the first loop iteration AT NEW will definitely trigger because the plant is read as new. Here SY-TABIX = 1.


After entering into AT NEW, we can see the other fields which are right side of the mentioned field contain ***. Only the mentioned field contains the proper data.


After that whenever system finds a new plant data it will trigger AT NEW similarly. Here at SY-TABIX = 3.


Similarly at SY-TABIX = 16 it will be triggered.


In this way AT NEW is triggered inside the loop. The output is as follows.

17 comments:

swamy said...

Change the plant sequence and see the output.
werks TYPE mard-werks,
matnr TYPE mard-matnr,
lgort TYPE mard-lgort,


then u get to know the correct use of AT New

swamy said...

werks TYPE mard-werks
matnr TYPE mard-matnr,
lgort TYPE mard-lgort,

Change the position plant ate see then you can see the correct use of AT New.

SANDIP ROY said...

Control Break Statement works inside a loop of internal table. Now internal table must have a key field. If we select 2nd or 3rd field as a key field, the system takes all two (1st & 2nd) or all three fields (1st, 2nd & 3rd) as a key. Now any change of any of those fields will treat a new key and system triggers AT NEW.

Inside control break every other fields (non key) hold *** rather than its actual value (except ON CHANGE OF). ON CHANGE OF statement

Rahul said...

Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog on SAP SD.
SAP SD

Rahul said...

It was very nice blog to learn about SAP HR.Thanks for sharing new things.SAP HR

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...


Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

Shruti Ramalingam said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

sushma said...

Best SAP Success Factor Training in Chennai

http://thecreatingexperts.com/sap-training-in-chennai/
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Priyasekar said...


SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Unknown said...


Best SAP MM Material Managemnt Real time hands on Training in chennai

http://thecreatingexperts.com/sap-mm-training-in-chennai/

sushma said...

SAP Success Factors Training in Chennai with Real Time Hands on Experience

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

sushma said...

Informative Blog...For a long time I was craving for a career growth in programming and then I came to know that THE CREATING EXPERTS is the one who provide training with hands on training and real time scenarios

http://thecreatingexperts.com/sap-abap-training-in-chennai/

contact 8122241286

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

Jugul Donald said...

Keep up the good work!!!

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD