Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Database access by Multiple users

Former Member
0 Likes
486

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

3 REPLIES 3
Read only

Former Member
0 Likes
444

You can use lock mechanism to prevent two users access the same table at a time.

Read only

Former Member
0 Likes
444

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

Read only

che_eky
Active Contributor
0 Likes
444

You could use a custom number range to give you the next available id. That way multiple users can create records without issue.