Skip to Content

At NEW/END OF statement

Hi,

I have an internal table with following records

Record1.

itab-f1 = J

itab-f2 = 20080623

Record1.

itab-f1 = V

itab-f2 = 20080617

Record2.

itab-f1 = V

itab-f2 = 20080618

Record3

itab-f1 = V

itab-f2 = 20080619

Record4

itab-f1 = V

itab-f2 = 20080620

I have written the following code


data: dt_from type datum,
        dt_to     type datum.

loop at itab into wa.
  at new f1.
    clear dt_from.
    dt_frm = wa-f2.
  endat.
  at end of f1.
    clear dt_to.
    dt_to = wa-f2.
  endat.
endloop.

However, at the end of the loop, I get dt_from = 20080620 and dt_to = 20080620.

I debugged the application and found that in every loop, control is goin inside both the at.. endat statements.

Ideally, I think for the first record I should get dt_from and dt_to = 20080623

and then for f1 = V, dt_from = 20080617 and dt_to = 20080620.

Basically I wnat to get the first and last date for every set of f1.

Is there any thing wrong with the code???

Regards,

Reema.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 03:51 PM

    Hi,

    To overcome that..at the beginning of the loop move the wa into a temporary wa..and use that temporary work area in that loop for assignments..marked in bold..

    loop at itab into wa.

    wa_tmp = wa.

    at new f1.

    clear dt_from.

    dt_frm = wa_tmp-f2.

    endat.

    at end of f1.

    clear dt_to.

    dt_to = wa_tmp-f2.

    endat.

    endloop.

    Thanks

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 03:30 PM

    Hi,

    If you are using AT NEW..make sure you do the following things.

    1) Sort the internal table by F1.

    2) Also make sure the field F1 is the first field in your internal table declarations. Let's say in the internal table declaration you have one more column before F1. If there is a change in the value of the previous column then also AT NEW F1 will trigger...

    Thanks

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 17, 2008 at 03:28 PM

    Hi reema,

    Please sort your internal table before you use the control statements like at new etc.

    data: dt_from type datum,
            dt_to     type datum.
     
    sort itab by f1.
    loop at itab into wa.
      at new f1.
        clear dt_from.
        dt_frm = wa-f2.
      endat.
      at end of f1.
        clear dt_to.
        dt_to = wa-f2.
      endat.
    endloop.

    Regards,

    Ravi

    Edited by: Ravi Kanth Talagana on Jun 17, 2008 5:28 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 17, 2008 at 03:34 PM

    Sorry, I didnot mention this.

    Before looping through itab, I have this statement.

    
    sort itab ascending by f1 f2.
    
    

    However, f1 is not the first field of my internal table. I will try changing that.

    Regards,

    Reema.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 03:35 PM

    Hi,

    Please let me know if it works.

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Naren,

      Having put f1 as the first field of the internal table, it worksfine. Control goes in the at new.. endat

      and at endof. endat.... statements correctly.

      However, in both cases, when control goes inside the at new and at endof statements, the field f2 is replaces by asterisks (*)

      So I am not able to get the value of f2 in the fields. How can I overcome this?

      Regards,

      Reema.

  • Posted on Jun 17, 2008 at 04:03 PM

    Thanks Naren for your timely help.

    Reema.

    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.