获取登录信息
获取事务代码:
REPORT Z_ABAP_SELECT_USER_BY_TCODE .
TABLES:
TSTC,
TSTCT.
DATA OPCODE TYPE X.
DATA: BEGIN OF USR_TABL OCCURS 10.
INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.
SELECT-OPTIONS: S_TCODE FOR TSTC-TCODE.
START-OF-SELECTION.
CLEAR USR_TABL.
FREE USR_TABL.
* set the function call mode
OPCODE = 2.
* get list of all users actually logging on
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
ID 'TAB' FIELD USR_TABL-*SYS*.
SORT USR_TABL BY BNAME TCODE.
LOOP AT USR_TABL WHERE TCODE IN S_TCODE.
SELECT SINGLE TTEXT FROM TSTCT INTO TSTCT-TTEXT
WHERE SPRSL = SY-LANGU AND
TCODE = USR_TABL-TCODE.
TRANSLATE TSTCT-TTEXT TO UPPER CASE.
WRITE:/
USR_TABL-BNAME,
USR_TABL-TCODE,
TSTCT-TTEXT.
ENDLOOP.
IF SY-SUBRC <> 0.
MESSAGE I001(38) WITH 'NO ENTRIES FOR YOUR SELECTION CRITERIA!'.
ENDIF.
获取本地计算机登录名和IP:
REPORT Z_BARRY_TEST.
DATA STR TYPE STRING.
DATA zip TYPE string.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_USER_NAME
CHANGING
USER_NAME = STR
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2
OTHERS = 3.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS
RECEIVING
IP_ADDRESS = ZIP
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
write zip.
WRITE STR.