Skip to Content
author's profile photo Former Member
Former Member

how to use AT END OF statement.

Hi all,

my itab structure contains 5 fields,

i want to do AT END OF F2......i.e filed 2 in my structure.

here my F1 ( 1st field ) is key field..........so i should keep it in the first place of itab structure.

but when iam looping at itab, 'AT END OF F2' is executing every time (even though F2 entry value is same).

one more thing is i need to sum up my F3 (3rd field) before AT END OF F2.

so please tell me how can i proceed............

Thanks,

KK.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:13 AM

    Hi,

    U can keep the second field first in the interanl table...

    But while displaying u can first display the key field...

    or while filling field catalog, u can fill the key field first..

    thats not a problem...

    Regards,

    lavanya

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:17 AM

    Hi,

    Based on following code,change according to ur requirement.

    1.When ever u want to use AT END OF event,the field should be in first field in internal table.

    2.For ur requirement put ur key field in second place and first field as the field which u want to sum.

    3.In write statement give the key field as first field and remaining are next.

    DATA: BEGIN OF ITAB OCCURS 0,

    BUKRS LIKE LFC1-BUKRS,

    UM01H LIKE LFC1-UM01H,

    UM01U LIKE LFC1-UM01U,

    END OF ITAB.

    SELECT BUKRS UM01H UM01U INTO TABLE ITAB FROM LFC1.

    SORT ITAB BY BUKRS.

    LOOP AT ITAB.

    WRITE:/ ITAB-BUKRS,7 ITAB-UM01H,ITAB-UM01U.

    AT END OF BUKRS.

    SUM.

    WRITE:/ ITAB-BUKRS COLOR 7,7 ITAB-UM01H COLOR 7,ITAB-UM01U COLOR 7.

    ENDAT.

    AT LAST.

    SUM.

    WRITE:/ ‘TOTAL’ COLOR 3,ITAB-UM01H COLOR 1,ITAB-UM01U COLOR 1.

    ENDAT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank u for ur kind response,

      but my database table is having huge volume of records,

      if i write select statement with out using key field........it is taking much time to excecute.

      so i should keep my key field..........

      kk.

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:25 AM

    hi kusuma

    itab-f1 f-2 f-3

    1 2 1

    2 2 1

    2 3 1

    when u write at end of f2

    it means it will trigger every new value of f1&f2

    in this case every time it will trigger bcz for f1&f2 it has different value every time

    loop at itab.

    at end of f2

    endat.

    endloop.

    loop---1

    f1 & f2 = 1,2

    so it checks any record with same values . if no it will trigger

    suppose u have records like this

    1 2 1

    1 2 2

    2 2 1

    2 3 1

    in this case

    loop 1 -


    f1 & f2 = 1,2

    loop 2 -


    f1 &f2 = 1,2

    in both caese f1&f2 have same value so it will trigger second time

    so analyze itab with u r data.

    &&

    suppose u want sum of f3 before at end of f2 then u can write in At new f2. Check This Code

    sort itab.

    loop at itab.

    at new f2

    sum.

    write:/ itab-f3

    endat.

    At end of f2.

    endat.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:03 AM

    Hi

    SORT ITAB1 BY COST_CENTRE.
      LOOP AT ITAB1.
        MOVE-CORRESPONDING ITAB1 TO WA1.
        AT NEW COST_CENTRE.
          MOVE WA1-COST_CENTRE TO ITAB-COST_CENTRE.
        ENDAT.
        AT END OF COST_CENTRE.
          SUM.
          ADD ITAB1-BASIC THEN ITAB1-HRA UNTIL ITAB1-SPL_ALL_05 GIVING
          ITAB-MGMT_STAFF.
          ITAB-MGMT_STAFF = ITAB-MGMT_STAFF * 12.
          ITAB-MEDICAL = ITAB1-BASIC.
          APPEND ITAB.CLEAR ITAB.
        ENDAT.
      ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:12 AM

    AT END OF will not only consider field2 but it also considers all the fields which are on left side of field 2. In your case, if values of field1 and field2 is changed this event will be triggerred. I think if every time its going inside loop then field1 values must be changing everytime. If you need to consider only FILED2 then make sure that your itab contains field2 as first field.

    Let me know if you have any doubts.

    Best Regards,

    Vibha

    Please mark all the helpful answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:16 AM

    hi

    try to use AT LAST and COLLECT for executing code only at last of ITAB and to get SUM in the last of tables respectively.

    reward if helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 10:19 AM

    to make use of at end of make F2 as first column, or else try go for on change event

    reward if useful

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.