Hi
It very much looks like you're not closing the cursor correctly. There is an else missing on your last if statement..
ELSE.
CLOSE CURSOR S_CURSOR.
MOVE 1 TO SY-SUBRC.
ENDIF.
Also you left out the whole error handling before you do this:
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
CASE SY-SUBRC.
WHEN '0'.
WHEN '1'. RAISE NO_MORE_DATA.
WHEN '2'.
LOG_WRITE SY-MSGTY SY-MSGID SY-MSGNO SY-MSGV1 SY-MSGV2.
RAISE ERROR_PASSED_TO_MESS_HANDLER.
WHEN OTHERS.
LOG_WRITE SY-MSGTY SY-MSGID SY-MSGNO SY-MSGV1 SY-MSGV2.
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
hope that helps
Martin