SAP obtains local information (IP and computer name)

Introduction: I have been doing logging recently, and I need to record the user's IP and computer name. I found out that SAP has two classes that can be implemented.


1. Effect display

insert image description here

Two, the code

*&---------------------------------------------------------------------*
*& Report Z_JYH_TEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_jyh_test.

DATA : ip            TYPE char20.
DATA : computer_name TYPE string.

"获取IP地址
CALL METHOD cl_gui_frontend_services=>get_ip_address
  RECEIVING
    ip_address           = ip
  EXCEPTIONS
    cntl_error           = 1
    error_no_gui         = 2
    not_supported_by_gui = 3
    OTHERS               = 4.
    
CALL METHOD cl_gui_cfw=>flush.
WRITE: / '本机IP:', ip.

"获取电脑名称
CALL METHOD cl_gui_frontend_services=>get_computer_name
  CHANGING
    computer_name        = computer_name
  EXCEPTIONS
    cntl_error           = 1
    error_no_gui         = 2
    not_supported_by_gui = 3
    OTHERS               = 4.

CALL METHOD cl_gui_cfw=>flush.
CALL METHOD cl_gui_cfw=>update_view.
CONDENSE computer_name.

WRITE: / '电脑名称:', computer_name.

Author: Little Flying Pig Pig Pig Pig Pig Pig Pig – CSDN

Guess you like

Origin blog.csdn.net/JYH1999/article/details/126489974