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

Only one user can use my tcode at one time. How to code it?

Former Member
0 Likes
1,453

I have a zprogram. I only want one user to access my tcode at one time. When user A using my tcode, user B cannot use it by prompting something like "This program is being use by another user". How to code it?

Thanks.

I have a zprogram. I only want one user to access my tcode at one time. When user A using my tcode, user B cannot use it by prompting something like "This program is being use by another user". How to code it?

Thanks.

3 REPLIES 3
Read only

Former Member
0 Likes
935

Hi,

Use FM ENQUEUE_EZSTOPRN.

Read only

Sougata
Active Contributor
0 Likes
935

Hello Paul,

I could not find the FM suggested and I'm not sure if there is any standard way to check this ( I don't imagine it would be simple if there is one) but here's my two cents - build a Z transparent table with a "status" field. Update the status field at the very end of your program i.e. just before it finish running. Say, update it with value 'C' (complete) and Commit Work.

At start-of-selection event of your program read the latest entry of your Z table and check if the status field equals 'C'. If its blank (space) then a user is currently running the program and you can produce an error message but if its 'C' then its not currently being run, so OK to go ahead. In the Z table its good idea to put other user info like username, date, time, program name etc. so that it becomes kind of a log for this program.

Hope this helps and please don't forget to reward points.

Cheers,

Sougata.

Read only

Former Member
0 Likes
935

Hello Paul,

Try SPA/GPA parameter. E.g.

DATA: lock like sy-uname.   "user name is used as a lock criteria, i.e. lock == SPACE -> nobody 
                                         "is running the program
...
...

AT SELECTION-SCREEN OUTPUT.
  GET PARAMETER ID 'USE' FIELD lock.
  IF lock <> SPACE.
    MESSAGE E999 with 'Currently used by' lock.
  ENDIF.
  SET PARAMETER ID 'USE' FIELD sy-uname.
  
START-OF-SELECTION.
....
....
END-OF-SELECTION.
.....
.....

  SET PARAMETER ID 'USE' FIELD space.

The parameter id 'USE' (or your own) is maintained in the table TPARA. This prevents duplicates of e.g. 'USE'.

That's another alternative than using ENQUEUE Function modules.

Hope this helps,

Heinz