You may try the following code:
FIELD-SYMBOLS <l_fs_data> LIKE LINE OF it_data.
DATA:
l_index TYPE i,
l_uid LIKE it_data-uid,
l_grp LIKE it_data-grp1.
SORT it_data BY uid grp1.
LOOP AT it_data ASSIGNING <l_fs_data>.
IF l_uid IS INITIAL OR l_grp IS INITIAL
OR l_uid NE <l_fs_data>-uid OR l_grp NE <l_fs_data>-grp1.
l_index = 1.
ELSE.
ADD 1 TO l_index.
ENDIF.
l_uid = <l_fs_data>-uid.
l_grp = <l_fs_data>-grp1.
<l_fs_data>-upd1 = l_index.
ENDLOOP.