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

Issue with Program lock

Former Member
0 Likes
768

I have a requirement to lock the Program if it is already running with the same variant. My program is scheduled to run every 5 minutes for each variant. So if the program finds the Previous Job still under execution then it should throw an error saying 'The program is still Running with the same Variant xxxx".

I am using the Lock Object 'ESVARIANT' to the lock the Program using the same

variant.

CALL FUNCTION 'ENQUEUE_ESVARIANT'

EXPORTING

MODE_VARI = C_E "E

MANDT = SY-MANDT

RELID = C_RELID "VA

REPORT = SY-CPROG

VARIANT = SY-SLSET

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.

This lock object works fine most of the times but for some reason it fails sometimes, i.e It does not get locked even if it finds a Job executing with the same variant?. It is not reliable using this Lock object 'ESVARIANT'.

Can any of you suggest me any other solution for this? .

Any solutions is appreciated and rewarded.

Thanks

Sekhar

Message was edited by:

Nagasekhar Reddy.K

Message was edited by:

Nagasekhar Reddy.K

1 ACCEPTED SOLUTION
Read only

former_member199581
Active Participant
0 Likes
689

Use FM TH_WPINFO.

It will returns the work-processes of the application server, distinguished by Program name, user, etc...

Loop at the returning table searching for your program, and if found do whatever you need in the code.

Hope this helps,

Roby.

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
689

I'm wondering if you shouldn't be passing variables instead of system fields here. At least the sy-cprog may be a problem.

data: v_cprog type sy-cprog,
        v_slset type sy-slset.

v_cprog = sy-cprog.
v_slset  = sy-slset.



CALL FUNCTION 'ENQUEUE_ESVARIANT'
EXPORTING
MODE_VARI = C_E "E
MANDT = SY-MANDT
RELID = C_RELID "VA
REPORT = v_CPROG
VARIANT = v_SLSET
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.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
689

Hi,

I would suggest the following as an alternate

1) to look for the tables TBTCO and TBTCP which holds all job names and it's status.

2) Or there are lot of function modules to check the status of the batch job, refer the function group BDL3 (sample: BDL_CHECK_FOR_RUNNING_BATCHJOB).

Hope, it helps.

Thanks

Viswa

(Assign points if helpful)

Read only

0 Likes
689

In addition, check this function module also BP_JOB_SELECT_SM37C.

Thanks

Viswa

Read only

former_member199581
Active Participant
0 Likes
690

Use FM TH_WPINFO.

It will returns the work-processes of the application server, distinguished by Program name, user, etc...

Loop at the returning table searching for your program, and if found do whatever you need in the code.

Hope this helps,

Roby.