Get IP address of the user in SAP ABAP详解编程语言

We can get IP Address of the logged in user in SAP using two ways.

Generally this kind of requirements are rare, but in some developments where we need to track user login IP.

  • Using Function module TERMINAL_ID_GET
  • Using Class method CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS

Get IP address using TERMINAL_ID_GET

REPORT ZSAPN_GET_IP. 
DATA : IP TYPE STRING. 
DATA : TEMP TYPE STRING. 
DATA : LV_TERMINAL TYPE USR41-TERMINAL. 
**Call function module to get terminal 
CALL FUNCTION 'TERMINAL_ID_GET' 
* EXPORTING 
*   USERNAME                   = SY-UNAME 
  IMPORTING 
    TERMINAL             = LV_TERMINAL 
  EXCEPTIONS 
    MULTIPLE_TERMINAL_ID = 1 
    NO_TERMINAL_FOUND    = 2 
    OTHERS               = 3. 
IF SY-SUBRC <> 0. 
  WRITE :/ 'Error in getting terminal'. 
ENDIF. 
**Terminal contains IP address and computer name ex: 127.0.0.1-USER 
SPLIT LV_TERMINAL AT '-' INTO IP TEMP. 
WRITE:/ IP. 

Get IP address uisng CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS

REPORT ZSAPN_GET_IP. 
DATA : IP TYPE STRING. 
IP = CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS( ). 
WRITE :/ IP.

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20144.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论