Tip

Notify users to exit transaction from a batch job

There was a need to notify users to exit from a transaction from within a batch process. The following subroutine will determine what users are currently logged in transaction ZTRANS and then notify them to signed off by means of a popup window. You can then programmatically STOP the background job if desired and rerun once all users are logged out of transaction ZTRANS. This helped us out at Sodexho to prevent the locking of records by ZTRANS, which needed to be locked by our batch process.
FORM DETERMINE_ZTRANS_ACTIVE.
DATA : L_OPCODE(1)TYPE X,
L_TCODE LIKE SY-TCODE,
L_MANDT LIKE SY-MANDT,
L_MESSAGE
LIKE SM04DIC-POPUPMSG,
L_MESSAGE_LEN
LIKE SY-INDEX.

DATA :
BEGIN OF LT_ITAB OCCURS 0,
NAME LIKE SY-UNAME,
END OF LT_ITAB.
DATA :
LT_ITAB1 LIKE UINFO2
OCCURS 0
WITH HEADER LINE.
CONSTANTS:
C_OPCODE_LONG_USR_INFO
LIKE L_OPCODE
VALUE 32,
C_TCODE LIKE SY-TCODE
VALUE 'ZTRANS'.

L_TCODE = C_TCODE.
L_MANDT = SY-MANDT.

* Determine active users
* within the client that
* this
* program is running and
* load into internal table
SELECT BNAME FROM USR41
CLIENT SPECIFIED
INTO TABLE LT_ITAB
WHERE MANDT = L_MANDT.

* Remove duplicate entries
* if user has more than one
* session opened
DELETE ADJACENT

    Requires Free Membership to View

DUPLICATES FROM LT_ITAB.

* Obtain user information
* and load into a second
* internal table
LOOP AT LT_ITAB.
CALL 'ThUsrInfo'
ID 'OPCODE' FIELD
C_OPCODE_LONG_USR_INFO
ID 'USER' FIELD
LT_ITAB-NAME
ID 'TAB' FIELD
LT_ITAB1-*SYS*.
ENDLOOP.

* Determine which user(s)
* are in ZTRANS in the
* client where this program
* is running by deleting
* those entries that are
* not in ZTRANS or the
* current client
DELETE LT_ITAB1 WHERE
TCODE <> L_TCODE
OR CLIENT <> L_MANDT.

L_MESSAGE = 'Please exit
ZTRANS'.
COMPUTE L_MESSAGE_LEN =
STRLEN( L_MESSAGE ).

* Now the following
* internal table represents
* those users currently in
* transaction ZTRANS and a
* pop-up message will be
* sent to them
LOOP AT LT_ITAB1.
CALL FUNCTION 'TH_POPUP'
EXPORTING
CLIENT = L_MANDT
USER = LT_ITAB1-USER
MESSAGE = L_MESSAGE
MESSAGE_LEN
= L_MESSAGE_LEN
EXCEPTIONS
USER_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
ENDLOOP.

ENDFORM.

This was first published in April 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.