Hi Experts,
I have populated one z table with records. The table coloumns are as below:
Mandt
Pernr
Personnel Area
Total Points
Rank
I have to sort the table records in descending order of Total Points. In many cases there will be same total points for many records. In such cases we have to arrange records in following fashion:
If more than 1 person have same total points then person having more years of service will have higher rank
If more than 1 person have same total points and same years of service then older people (date of birth) will have higher rank.
I have written following program. It is not working. Please help me. If you have some ready made code, please share with me.
Regards,
Gary
IF NOT itab_prio[] IS INITIAL.
CLEAR v_index.
v_index = 1.
SORT itab_prio BY z_prio_pts DESCENDING .
itab_rank[] = itab_prio[].
LOOP AT itab_prio.
*---Check eligibility.
CALL FUNCTION 'zmy_prg_CHECK_ELIGIBILITY'
EXPORTING
pernr = itab_prio-z_pernr
IMPORTING
return = return.
IF return-type = 'E'.
itab_prio-z_prio_pts = 0.
itab_prio-z_prio = 0.
MODIFY itab_prio TRANSPORTING z_prio_pts z_prio.
ELSE.
LOOP AT itab_rank WHERE z_prio_pts = itab_prio-z_prio_pts
AND z_pernr NE itab_prio-z_pernr.
*---Get Hiring date for same rank.
CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
EXPORTING
pernr = itab_rank-z_pernr
IMPORTING
hiring_date = hire_new.
*---Get Hiring date of update emp.
CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
EXPORTING
pernr = itab_prio-z_pernr
IMPORTING
hiring_date = hire_old.
IF hire_old = hire_new.
*---Check for Birth date of both employees.
READ TABLE it_date WITH KEY pernr = itab_rank-z_pernr.
IF sy-subrc = 0.
hijri_new = it_date-zzhdob.
ENDIF.
READ TABLE it_date WITH KEY pernr = itab_prio-z_pernr.
IF sy-subrc = 0.
hijri_old = it_date-zzhdob.
ENDIF.
IF hijri_old > hijri_new.
flag = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
IF flag NE 'X'.
itab_prio-z_prio = v_index.
v_index = v_index + 1.
MODIFY itab_prio TRANSPORTING z_prio.
ELSE.
itab_prio-z_prio = v_index.
v_index = v_index + 1.
MODIFY itab_prio TRANSPORTING z_prio.
ENDIF.
ENDIF.
CLEAR : flag , return.
ENDLOOP.
MODIFY zhop_priority_pt FROM TABLE itab_prio.
COMMIT WORK.
IF sy-subrc = 0.
MESSAGE i000(zz) WITH 'sucessfully generated'.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
Please use code tags to format your code
Edited by: Rob Burbank on Sep 29, 2010 1:59 PM