Wednesday, November 25, 2015

Control Break - AT END OF Statement



AT END OF statement always triggers when there is any change of fields’ data. This statement triggers at the last occurrence of that value. Let’s take an example. We have a table MARD which contains material, plant & storage location. Now we want to trigger AT END OF at the last occurrence of plant data as follows.


As we can see that the statement triggers at the last occurrence of plant data.

REPORT  zctrlbrk_at_end_of NO STANDARD PAGE HEADING.

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.

  SORT itab BY werks.

  WRITE: / 'Material Number', 20 'Plant', 27 'Storage Location'.
  ULINE.

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

    AT END OF werks.
      WRITE: '=== At End Of plant - triggers at line ', sy-tabix.
    ENDAT.
  ENDLOOP.

Here we have shifted the plant (WERKS) at field 1 in structure level. Otherwise system will consider material & plant both as a key. Because the AT END OF will trigger if there is any change from left most field to the particular field.

Now we want to see at the debugging level of AT END OF statement. On second line it has triggered because that is the last occurrence of plant 1200. SY-TABIX = 2. For the rest of the rows system will skip the AT END OF statement.


Similarly it has triggered at last occurrence of plant 3000. SY-TABIX = 15.


There is only one entry for plant 7500. So it triggers at the next loop iteration. SY-TABIX = 16.


At the last of the table record AT END OF triggers. Here the plant occurrence & table data both are of last entry.


The output is as follows:

5 comments:

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

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

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

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

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

Anonymous said...

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

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

Anonymous 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

Unknown said...

well said thank you for sharing lovely info sap hr online classes