Notify users to exit transaction from a batch job

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.

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

Dig deeper on SAP ABAP

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close