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: 

Dead Lock With Update Statemet Updating a SAP Standard Table

Former Member
0 Kudos
114

Hi All,

I'm updating a field in User profile NDR from a ZPROGRAM to avoid printing MM Document

DATA : olg_prflag LIKE usr05-parva.

SELECT SINGLE * FROM usr05 WHERE bname = sy-uname

AND parid = 'NDR'.

CLEAR olg_prflag.

olg_prflag = usr05-parva.

UPDATE usr05 SET parva = ' '

WHERE bname = sy-uname

AND parid = 'NDR'.

BAPI_GOODSMVT_CREATE

UPDATE usr05 SET parva = olg_prflag

WHERE bname = sy-uname

AND parid = 'NDR'.

This is an interface program and gets executed whenever a file is avialable at application server.

This program usually runs for a particular sy-uname because its scheduled background for that particular user.

Recently there were 2 files and the program was triggered twice with in span of sec and as a result there was

a dead lock

SO i created a lock object

CALL FUNCTION 'ENQUEUE_EZTEST'

EXPORTING

MODE_USR05 = 'E'

MANDT = SY-MANDT

BNAME = sy-uname

PARID = 'NDR'

X_BNAME = ' '

X_PARID = ' '

_SCOPE = '2'

_WAIT = 'X'

_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.

UPDATE usr05 SET parva = ' '

WHERE bname = sy-uname

AND parid = 'NDR'.

BAPI_GOODSMVT_CREATE

UPDATE usr05 SET parva = olg_prflag

WHERE bname = sy-uname

AND parid = 'NDR'.

CALL FUNCTION 'DEQUEUE_EZTEST'

EXPORTING

MODE_USR05 = 'E'

MANDT = SY-MANDT

BNAME = SY-UNAME

PARID = 'NDR'

X_BNAME = ' '

X_PARID = ' '

_SCOPE = '3'

_SYNCHRON = ' '

_COLLECT = ' '

.

and simultaneously i ran the old program

the update statemnt was succesfully

Is there any thing else that i'm missing here

Thanks

Venki

1 REPLY 1

Former Member
0 Kudos
43

I usually try the lock at least 5 times. You can also get the time and run it for 20 seconds before you give up and create an error message.

See Below:

do.

CALL FUNCTION 'ENQUEUE_EZTEST'

EXPORTING

MODE_USR05 = 'E'

MANDT = SY-MANDT

BNAME = sy-uname

PARID = 'NDR'

X_BNAME = ' '

X_PARID = ' '

_SCOPE = '2'

_WAIT = 'X'

_COLLECT = ' '

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

if sy-subrc = 0. "Record is successfully locked

UPDATE usr05 SET parva = ' '

WHERE bname = sy-uname

AND parid = 'NDR'.

BAPI_GOODSMVT_CREATE

w_update = 'Y'

exit.

endif.

else.

c_cnt = c_cnt + 1.

if c_cnt > 5.

exit.

endif.

enddo.

If w_update = 'N'.

*Here you can put an error routine.

endif.