Application Development 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: 

HR ABAP for employee groups with possible custom table...

Former Member
0 Kudos

Hi Members

I have a internal table where employee name and employee group are maintained.

Next, i have other tables where employee name is there and his salary. now I want to add all the salaries of the employees with same groups, how can I do this.

for Example, I have employee group as ENG, DOC, NUR Etc. (Also I wanted to use some kind of dynamic conditions as emplyee groups might added latter in custom table.

Thank you.

Edited by: Julius Bussche on Sep 23, 2008 10:18 PM

1 ACCEPTED SOLUTION

former_member212653
Active Contributor
0 Kudos

Check out this code:


*&---------------------------------------------------------------------*
*& Report  ZTEST3
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest3.
TYPES:
BEGIN OF x_employee,
  id TYPE n LENGTH 10,
  name TYPE c LENGTH 20,
  group TYPE c LENGTH 4,
END OF x_employee,
BEGIN OF x_emp_sal,
  id TYPE n LENGTH 10,
  salary TYPE p LENGTH 16 DECIMALS 2,
END OF x_emp_sal,
BEGIN OF x_final,
  group TYPE c LENGTH 4,
  id TYPE n LENGTH 10,
  name TYPE c LENGTH 20,
  salary TYPE p LENGTH 16 DECIMALS 2,
END OF x_final.

DATA:
i_employee TYPE STANDARD TABLE OF x_employee INITIAL SIZE 0,
i_final TYPE STANDARD TABLE OF x_final INITIAL SIZE 0,
i_salary TYPE STANDARD TABLE OF x_emp_sal INITIAL SIZE 0,
wa_employee TYPE x_employee,
wa_salary TYPE x_emp_sal,
wa_final TYPE x_final,
wa_final_temp TYPE x_final.

DEFINE append_employee.
  wa_employee-id = &1.
  wa_employee-name = &2.
  wa_employee-group = &3.
  append wa_employee to i_employee.
END-OF-DEFINITION.
DEFINE append_salary.
  wa_salary-id = &1.
  wa_salary-salary = &2.
  append wa_salary to i_salary.
END-OF-DEFINITION.

append_employee:
1 'John' 'ENG',
2 'Mary' 'ENG',
3 'Pooja' 'IT',
4 'Payal' 'IT',
5 'Sourav' 'IT'.

append_salary:
1 '111.00',
2 '1111.00',
3 '11111.00',
4 '111111.00',
5 '1111111.00'.

LOOP AT i_employee INTO wa_employee.
  READ TABLE i_salary INTO wa_salary
   WITH KEY id = wa_employee-id.
  IF sy-subrc = 0.
    wa_final-id = wa_employee-id.
    wa_final-name = wa_employee-name.
    wa_final-group = wa_employee-group.
    wa_final-salary = wa_salary-salary.
    APPEND wa_final TO i_final.
  ENDIF.
ENDLOOP.

SORT i_final BY group.

LOOP AT i_final INTO wa_final_temp.
  wa_final = wa_final_temp.
  AT END OF group.
    SUM.
    WRITE: /1 wa_final_temp-group, 5 wa_final_temp-salary.
  ENDAT.
ENDLOOP.

output will be:


ENG                         1.222,00   
IT                      1.233.333,00   

Edited by: Sourav Bhaduri on Sep 24, 2008 1:44 AM

3 REPLIES 3

former_member212653
Active Contributor
0 Kudos

Check out this code:


*&---------------------------------------------------------------------*
*& Report  ZTEST3
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest3.
TYPES:
BEGIN OF x_employee,
  id TYPE n LENGTH 10,
  name TYPE c LENGTH 20,
  group TYPE c LENGTH 4,
END OF x_employee,
BEGIN OF x_emp_sal,
  id TYPE n LENGTH 10,
  salary TYPE p LENGTH 16 DECIMALS 2,
END OF x_emp_sal,
BEGIN OF x_final,
  group TYPE c LENGTH 4,
  id TYPE n LENGTH 10,
  name TYPE c LENGTH 20,
  salary TYPE p LENGTH 16 DECIMALS 2,
END OF x_final.

DATA:
i_employee TYPE STANDARD TABLE OF x_employee INITIAL SIZE 0,
i_final TYPE STANDARD TABLE OF x_final INITIAL SIZE 0,
i_salary TYPE STANDARD TABLE OF x_emp_sal INITIAL SIZE 0,
wa_employee TYPE x_employee,
wa_salary TYPE x_emp_sal,
wa_final TYPE x_final,
wa_final_temp TYPE x_final.

DEFINE append_employee.
  wa_employee-id = &1.
  wa_employee-name = &2.
  wa_employee-group = &3.
  append wa_employee to i_employee.
END-OF-DEFINITION.
DEFINE append_salary.
  wa_salary-id = &1.
  wa_salary-salary = &2.
  append wa_salary to i_salary.
END-OF-DEFINITION.

append_employee:
1 'John' 'ENG',
2 'Mary' 'ENG',
3 'Pooja' 'IT',
4 'Payal' 'IT',
5 'Sourav' 'IT'.

append_salary:
1 '111.00',
2 '1111.00',
3 '11111.00',
4 '111111.00',
5 '1111111.00'.

LOOP AT i_employee INTO wa_employee.
  READ TABLE i_salary INTO wa_salary
   WITH KEY id = wa_employee-id.
  IF sy-subrc = 0.
    wa_final-id = wa_employee-id.
    wa_final-name = wa_employee-name.
    wa_final-group = wa_employee-group.
    wa_final-salary = wa_salary-salary.
    APPEND wa_final TO i_final.
  ENDIF.
ENDLOOP.

SORT i_final BY group.

LOOP AT i_final INTO wa_final_temp.
  wa_final = wa_final_temp.
  AT END OF group.
    SUM.
    WRITE: /1 wa_final_temp-group, 5 wa_final_temp-salary.
  ENDAT.
ENDLOOP.

output will be:


ENG                         1.222,00   
IT                      1.233.333,00   

Edited by: Sourav Bhaduri on Sep 24, 2008 1:44 AM

0 Kudos

Hi Sourav,

Thanks for your help and sample program, my problem is solved and i am closing this thread.

Regards

madhu

Former Member
0 Kudos

Please use a proper subject title and check your mail about "the rules"...

Such threads will be deleted!

Cheers,

Julius