2010 Oct 09 7:09 AM
Hi Experts,
I have written following code. The code is working fine. This code is creating records in table zhop_priority_pt. In the table the records are getting stored and priority of records is getting stored properly (zhop_priority_pt-z_prio). Every record of the table has distinct zhop_priority_pt-z_prio.
In the table zhop_priority_pt, I have stored location.
Now I have to calculate the priority (zhop_priority_pt-z_prio) seperately for each location.
For a given set of records in zhop_priority_pt, there may be say n distinct locations. So I have to create the priority list seperately for each location.
How I can do so? In my view, first of all I have to find out all distinct locations zhop_priority_pt-location.
After that for each location, I have to run the loop.
What changes should I make in the code.
IF NOT itab_prio[] IS INITIAL.
CLEAR v_index.
v_index = 1.
SORT itab_prio BY z_prio_pts DESCENDING z_seniority descending z_hij_dob ascending. "
LOOP AT itab_prio.
MODIFY itab_prio TRANSPORTING z_prio_pts z_prio.
if itab_prio-z_prio_pts > 0.
itab_prio-z_prio = v_index.
v_index = v_index + 1 .
MODIFY itab_prio TRANSPORTING z_prio.
endif.
ENDLOOP.
MODIFY zhop_priority_pt FROM TABLE itab_prio.
COMMIT WORK.
ENDIF.
ENDIF.Please help.
Regards,
Gary
2010 Oct 09 7:29 AM
hi gary ,
SORT itab_prio BY z_prio_pts DESCENDING z_seniority descending z_hij_dob ascending.you are having
say itab having column location ,proirity
mundwa , 9
mundwa 10
mundwa 7
spec 6
spec 4
spec 1
sort itab by location descending proirity .
then you can also create another internal table say itab1 having only column location and prority
move distinct location to itab1 .
then sort both table according to requirment say
sort itab by location descending proirity .
sort itab1 by location .
loop at itab .
at new location .
read table itab1 with key location = itab-location .
if sy-subrc = 0 .
move priority to itab1 .
append itab1 .
endif.
endat .
endloop.
you can try this .
Regards
Deepak.
hi gary ,
SORT itab_prio BY z_prio_pts DESCENDING z_seniority descending z_hij_dob ascending.you are having
say itab having column location ,proirity
mundwa , 9
mundwa 10
mundwa 7
spec 6
spec 4
spec 1
sort itab by location descending proirity .
then you can also create another internal table say itab1 having only column location and prority
move distinct location to itab1 .
then sort both table according to requirment say
sort itab by location descending proirity .
sort itab1 by location .
loop at itab .
at new location .
read table itab1 with key location = itab-location .
if sy-subrc = 0 .
move priority to itab1 .
append itab1 .
endif.
endat .
endloop.
you can try this .
Regards
Deepak.
2010 Oct 09 7:29 AM
hi gary ,
SORT itab_prio BY z_prio_pts DESCENDING z_seniority descending z_hij_dob ascending.you are having
say itab having column location ,proirity
mundwa , 9
mundwa 10
mundwa 7
spec 6
spec 4
spec 1
sort itab by location descending proirity .
then you can also create another internal table say itab1 having only column location and prority
move distinct location to itab1 .
then sort both table according to requirment say
sort itab by location descending proirity .
sort itab1 by location .
loop at itab .
at new location .
read table itab1 with key location = itab-location .
if sy-subrc = 0 .
move priority to itab1 .
append itab1 .
endif.
endat .
endloop.
you can try this .
Regards
Deepak.
2010 Oct 09 9:07 AM
Hi Deepak,
Thanks. It is working fine after some minor modification.
Regards,
Gary
Modified Code
IF NOT itab_prio[] IS INITIAL.
CLEAR v_index.
v_index = 1.
SORT itab_prio BY z_location z_prio_pts DESCENDING z_seniority descending z_hij_dob ascending.
LOOP AT itab_prio.
at new z_location.
read table itab_prio with key
z_location = itab_prio-z_location.
if sy-subrc = 0.
move itab_prio-z_location to it_loc_pr.
append it_loc_pr.
endif.
endat.
endloop.
SORT it_loc_pr BY location.
DELETE ADJACENT DUPLICATES FROM it_loc_pr COMPARING location.
loop at it_loc_pr.
CLEAR v_index.
v_index = 1.
LOOP AT itab_prio where z_location = it_loc_pr-location.
ENDLOOP.
endloop.
MODIFY zmyprogram_priority_pt FROM TABLE itab_prio.
COMMIT WORK.
ENDIF.
2010 Oct 09 12:32 PM
hi ,
Good work ... Congrats
This will boost you to and make you happy .
Regards
Deepak
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |