Application Development 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: 

How to apply lock logic on a z table?

Former Member
0 Kudos

hi gurus,

we want to apply application lock on one of our ztables, the requirements are

when some read an entry, there will be a lock on it, then nobody could read it, until the user closes the applicaiton or after a cetain period of time ,say 1 hours.

thanks and best regards.

Jun

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

use ENQUE_SLEEP FM

check this part of code

DO 360 TIMES.

CALL FUNCTION 'ENQUEUE_EY_YTSD0091'

EXPORTING

mode_ytsd0091 = 'E'

mandt = sy-mandt

yestockpoint = fu_h_tbl_input-yestockpoint

matnr = fu_h_tbl_input-matnr

kunwe = fu_h_tbl_input-kunwe

charg = fu_h_tbl_input-charg

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc <> 0.

IF sy-index = 360.

MOVE cns_on TO fc_flg_err.

fc_ctr_wlock = fc_ctr_wlock + 1.

ELSE.

CALL FUNCTION 'ENQUE_SLEEP'

EXPORTING

seconds = 5

EXCEPTIONS

system_failure = 1

OTHERS = 2.

CASE sy-subrc.

WHEN 1.

WHEN OTHERS.

ENDCASE.

ENDIF.

ELSE.

MOVE cns_off TO fc_flg_err .

EXIT.

ENDIF.

ENDDO.

ENDIF.

3 REPLIES 3

GauthamV
Active Contributor
0 Kudos

hi,

you can create a lock object for your Ztable with lock mode Exclusive but not cumulative lock.

Former Member
0 Kudos

hi

use ENQUE_SLEEP FM

check this part of code

DO 360 TIMES.

CALL FUNCTION 'ENQUEUE_EY_YTSD0091'

EXPORTING

mode_ytsd0091 = 'E'

mandt = sy-mandt

yestockpoint = fu_h_tbl_input-yestockpoint

matnr = fu_h_tbl_input-matnr

kunwe = fu_h_tbl_input-kunwe

charg = fu_h_tbl_input-charg

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc <> 0.

IF sy-index = 360.

MOVE cns_on TO fc_flg_err.

fc_ctr_wlock = fc_ctr_wlock + 1.

ELSE.

CALL FUNCTION 'ENQUE_SLEEP'

EXPORTING

seconds = 5

EXCEPTIONS

system_failure = 1

OTHERS = 2.

CASE sy-subrc.

WHEN 1.

WHEN OTHERS.

ENDCASE.

ENDIF.

ELSE.

MOVE cns_off TO fc_flg_err .

EXIT.

ENDIF.

ENDDO.

ENDIF.

0 Kudos

if I am not wrong you may take the entry from the table into your program using

 Select single for update from ztable 

If you use the FOR UPDATE addition, the selected entry is protected against parallel updates from other transactions until the next database commit