‎2008 Apr 23 9:24 AM
Hi All,
I have a ztable and the user has to access the ztable to find the max of ID to insert the next record. This ID increment was done in coding level. It was working fine when a user hit the DB. If multiple user access the same, it throws the error as duplicate records. How to solve this? Can any one give the soln for this?
Thanks in Advance,
Pon
‎2008 Apr 23 9:33 AM
You can use lock mechanism to prevent two users access the same table at a time.
‎2008 Apr 23 10:15 AM
hi Murugesh,
whenever you are updating the data into table through the report.
you need to lock the table before inserting into the table and unloak after inserting the records into the Table.
locking.
FORM lock_spotter.
*
LOOP AT gt_spotter INTO gs_spotter.
CALL FUNCTION 'ENQUEUE_EZSPOTTERS'
EXPORTING
mode_zspotters = 'E'
aktnr = gs_spotter-aktnr
artnr = gs_spotter-artnr
mebme = gs_spotter-mebme
unique_key = gs_spotter-unique_key
x_aktnr = ' '
x_artnr = ' '
x_mebme = ' '
x_unique_key = ' '
_scope = '2'
_wait = ' '
_collect = 'X'
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
*
CALL FUNCTION 'FLUSH_ENQUEUE'
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
unlocking
LOOP AT gt_spotter INTO gs_spotter.
CALL FUNCTION 'DEQUEUE_EZSPOTTERS'
EXPORTING
mode_zspotters = 'E'
aktnr = gs_spotter-aktnr
artnr = gs_spotter-artnr
mebme = gs_spotter-mebme
unique_key = gs_spotter-unique_key
x_aktnr = ' '
x_artnr = ' '
x_mebme = ' '
x_unique_key = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP
hope this will help you.
Regards,
Madhavi
‎2008 Apr 23 2:16 PM
You could use a custom number range to give you the next available id. That way multiple users can create records without issue.