Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

count in internal table

Former Member
0 Likes
929

Hello all,

I need code to perform this logic:

fields: employee no., calendar day, hours.

I need to loop through an internal table to sort it with respect to employee no.and calendar day in ascending order.

I need to find out if 7 records exist for a particular employee.

If any employee has 7 records in that internal table, I need to store the hours of the latest day in a variable.

For example, an emplyee has seven records for seven days in a week from Sunday though saturday, I need to store the saturday hours in a variable.

I need to do this for all employees with seven records and store.

Please help me.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
865

Hi ,

There is no need of the where condition for which I have given for you.

You can remove that if you are fallowing my logic.

6 REPLIES 6
Read only

Former Member
0 Likes
865

Hi, try

LOOP AT ti_itab INTO ws_itab WHERE (condition employee).
  ADD 1 TO l_int.
  IF l_int EQ 7.
    EXIT.
  ENDIF.
ENDLOOP

IF l_int EQ 7.
  ... logic
ENDIF.

Read only

Former Member
0 Likes
865

Hello.

If we have limited number of records probably we may use the following logic.

Step1 : if we have all the records in table I_MAIN.

Step2 : append lines of i_main to i_temp1.

Step3 : delete adjacent entries in i_temp1 comparing employees.

By doing this we will get all the employee numbers.

Step 4:

loop at i_temp1 into wa_temp1.

    At new employee.
" For every employee move all records to temp2.
      append lines of i_mail to i_temp2.
    End at.

Delete table i_temp2 where employee ne wa_temp1-employee.
" Remove other employee details from temp table.

Describe table i_temp2.
  if sy-tfill eq 7.
       sort i_temp2 descending order by date.
        read table i_temp2 index 1 into wa_temp2.
          move wa_temp2-value to ws_variable.         
  endif.

endloop.

Let me know if there is any performance issue. This must work fast.

But don't use hash tables. Because SORT and DELETE will work slow on hash tables.

Here you can use describe table or else you can use LINES( itab ) command which work faster.

All the very best to you.

- Mohan.

Read only

Former Member
0 Likes
865

Hi Raj,

Please go through the below code.


SORT t_itab with key emp_no cal.
LOOP AT t_itab INTO w_itab WHERE (condition employee).
  if w_itab-emp_no EQ empno_temp.
     count = count + 1.
  endif.
  empno_temp = w_itab-empno.
  if count EQ 7.
    hour_temp = w_itab-hour . 
  endif.
You can use the hour_temp which will get the latest hours if employee has 7 records.
ENDLOOP.

Hope this program will help you. Please let me know if you are still facing the problem.

Thanks,

Ravi Kanth.

Read only

0 Likes
865

what does this mean?

WHERE (condition employee).

Read only

0 Likes
865

this means for example

LOOP AT itab INTO s_itab WHERE code_employee EQ g_code_employee.

...

ENDLOOP.

the internal table has a field named code_employee, there .. you should filtrer with a field named g_code_employee

PD: Sry for my bad english

David Carballido ^^

Read only

Former Member
0 Likes
866

Hi ,

There is no need of the where condition for which I have given for you.

You can remove that if you are fallowing my logic.