Tutorial Name

Get IP address of the user in SAP ABAP

Tutorial Description

Get IP address of the logged in user using SAP ABAP function module TERMINAL_ID_GET and class CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS

Tutorial Area Core ABAP
Prerequisites ABAP
Learning Level Basic
Estimated Time to learn 5
Save to Learning List Save to your Learning List
+ -

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.

Author | Last Updated| | 0 Comments | F Share

Tutorial Comments

Total Comments: Add your Comment

Leave a Comment

Enter Comment Text