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

AT NEW Statement is not working.

Hi everyone,

Here i am trying to display the count of number entries are there against an employee number.

For ex. an employee with emp no 1000 is present in the table thrice then the count shoul be 3.

For this i used the AT NEW statement in loop.The code is below one.

Data : Count2 type i.

select * from zsr_opl into table ot_opl.

loop at it_opl.


at new emp-no.

WRITE : / IT_OPL-EMP_NO.

ENDAT.

COUNT2 = COUNT2 + 1.

AT END.

WRITE : / COUNT2.

COUNT2 = 0.

ENDAT.

ENDLOOP.

HERE ZSR_OPL IS THE DB TABLE WHERE EMP-NO IS NOT KEY FIELD.

Moderator Message: Please be more specific about the problem - thread locked.

Message was edited by: Suhas Saha

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 07, 2012 at 07:01 AM

    Add this before your loop.

    Sort It_opl by EMP_no.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      sort IT_OPL by EMP_NO.

      data lv_count type i.

      loop at IT_OPL into WA_OPL.

      AT first.

      lv_empid = wa_opl-emp_no.

      endat.

      if lv_empid = wa_opl-emp_no.

      lv_count = lv_count + 1.

      else.

      write: 'Employee Id' lv_empid 'Count:' lv_count.

      lv_count = 1.

      lv_empid = wa_opl-emp_no.

      endif.

      endloop.

  • author's profile photo Former Member
    Former Member
    Posted on May 07, 2012 at 07:21 AM

    Hi Try this.

    sort IT_OPL by EMP_NO.

    loop at IT_OPL into WA_OPL.

    at new emp-no.

    WRITE : / IT_OPL-EMP_NO.

    COUNT2 = COUNT2 + 1.

    ENDAT.

    AT END OF EMP-NO..

    WRITE : / COUNT2.

    ENDAT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 07, 2012 at 07:39 AM

    Hi,

    So, is this what you want?

    EMP_NO COUNT

    1000 1

    1000 2

    1000 3

    Please correct if I'm wrong.

    Jake.

    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.