05-07-2012 7:53 AM
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
05-07-2012 8:01 AM
05-07-2012 8:01 AM
05-07-2012 8:12 AM
The above suggestion is considering the fact that EMP_NO is the first field of the table.
05-07-2012 8:14 AM
I done the sorting operation by emp no also. still the problem is there.
05-07-2012 8:15 AM
05-07-2012 8:15 AM
05-07-2012 8:19 AM
Internal Table Structure is
Field key init data type length
MANDT X X CLNT 3
OP_NAME X X CHAR 50
OP_DATE DATS 8
EMP_NO CHAR 10
EMP_NAME CHAR 30.
05-07-2012 8:28 AM
Considering the above sturcure AT new EMP_NO will be triggered if any of the fields before or including EMP_NO Changes. i.e. It will ge triggered when any of MANDT OP_NAME OP_DATE OR EMP_NO changes.
To recifiy it. Wo have two options.
1) do the logic your self. Create a locl variable to check store prev. emp no and check to see if the current emp no is same as the previeous.
2) Create local internal table where emp no is the first field. and the rest of the fields after that. Transfer your enteries to this internal table, sort this table and then do the AT NEW. inside the loop of the this table.
05-07-2012 8:34 AM
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.
05-07-2012 8: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.
05-07-2012 8:27 AM
HI Hasan,
thanks for ur reply,
i think you did'nt get point.
I want to display the count of an employee that exists in the table against the emp No.
05-07-2012 8:31 AM
Hi,
try this code...
SORT IT_OPL BY EMP_NO.
LOOP AT IT_OPL INTO WA_OPL.
AT NEW EMP_NO.
WRITE : / IT_OPL-EMP_NO.
ENDAT.
COUNT2 = COUNT2 + 1.
AT END OF EMP-NO..
WRITE : / COUNT2.
COUNT2 = 0.
ENDAT.
ENDLOOP.
05-07-2012 8: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.