原文链接:https://blog.csdn.net/JYH1999/article/details/126489974
导语:最近在做日志的东西,需要记录用户的IP,以及电脑名称,找了一下,SAP有两个类可以实现。
一、效果展示
二、代码
*&---------------------------------------------------------------------*
*& 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.