프로그래밍/SAP ABAP

SAP IP address 가져오는 함수/클래스

2021. 7. 16. 16:40

SAP IP address 가져오는 함수/클래스

 

1. IP address 가져오는 함수 

#Function 

DATA : TERMINAL  LIKE USR41-TERMINAL,
       TERMNM    TYPE CHAR20,     "Terminal name
DATA : L_ADDRESS TYPE CHAR15.
      
      CALL FUNCTION 'TERMINAL_ID_GET'
        EXPORTING
          USERNAME             = SY-UNAME
        IMPORTING
          TERMINAL             = TERMINAL
        EXCEPTIONS
          MULTIPLE_TERMINAL_ID = 1
          NO_TERMINAL_FOUND    = 2
          OTHERS               = 3.

      SPLIT TERMINAL AT '-' INTO L_ADDRESS TERMNM.

      

2. IP address 가져오는 CLASS
#CLASS

 

DATA : L_ADDRESS type char15.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS
    receiving
      IP_ADDRESS           = L_ADDRESS
    EXCEPTIONS
      CNTL_ERROR           = 1
      NOT_SUPPORTED_BY_GUI = 2
      ERROR_NO_GUI         = 3
      OTHERS               = 4.

 

 

3. Load Balancer 장비가 있을 경우 해당 장비의 IP가 나오고,

   원래 접속자의 IP는 알 수가 없을 때 사용하는 함수 

 

FUNCTION zget_ip_address.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     REFERENCE(EV_IP) TYPE  CSEQUENCE
*"----------------------------------------------------------------------

  DATA: lo_application TYPE REF TO if_wd_application,
        ls_header_fields TYPE wdr_name_value,
        lv_ip TYPE string.

  IF wdr_task=>application_name IS INITIAL.
    " SAP GUI 
    CALL METHOD cl_gui_frontend_services=>get_ip_address
      RECEIVING
        ip_address           = lv_ip
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
  ELSE.
    " WebDyn (웹딘)
    lo_application = wdr_task=>application->get_api( ).
    READ TABLE wdr_task=>client_window->if_wdr_client_info_object~header_fields INTO ls_header_fields
          WITH KEY name = 'x-forwarded-for'.

    IF sy-subrc = 0.
      lv_ip = ls_header_fields-value.        " Load balancer 통해서 접속한 경우.
    ELSE.
      lv_ip = lo_application->get_remote_address( ).        " 직접 AP 로 접속한 경우.
    ENDIF.

  ENDIF.

  ev_ip = lv_ip.

ENDFUNCTION.