ABAP 获取用户计算机名的方法

文摘   2024-11-01 06:06   上海  
   REPORT Z_GET_FRONTEND_HOSTNAME.
DATA: OPCODE(1) TYPE X VALUE 5, COMPUTER_NAME TYPE USR41-TERMINAL.
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE ID'TERMINAL' FIELD COMPUTER_NAME. WRITE COMPUTER_NAME. DATA(IP_ADDRESS) = CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS( ). WRITE IP_ADDRESS.

ABAP中如何获取登录电脑的帐号名字

   DATA WINUSER TYPE STRING.***Get Windows User Name   CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_USER_NAME     CHANGING       USER_NAME            = WINUSER     EXCEPTIONS       CNTL_ERROR           = 1       ERROR_NO_GUI         = 2       NOT_SUPPORTED_BY_GUI = 3       OTHERS               = 4.
CALL METHOD CL_GUI_CFW=>FLUSH EXCEPTIONS CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2 OTHERS = 3.
WRITE : WINUSER.


获取计算机名称

 CL_GUI_FRONTEND_SERVICES=>GET_COMPUTER_NAME(  CHANGING    COMPUTER_NAME        = COMPUTER_NAME_01 ).*  EXCEPTIONS*    cntl_error           = 1*    error_no_gui         = 2*    not_supported_by_gui = 3*    others               = 4*       ).   CALL METHOD CL_GUI_CFW=>UPDATE_VIEW.
WRITE / COMPUTER_NAME.


在新增/刪除/修改資料時,常需要log使用者的基本資料,但使用者的IP Address、Windows帳號及電腦名稱在syst中又找不到。

FUNCTION zbc_get_user_info.*"----------------------------------------------------------------------*"*"區域介面:*"  EXPORTING*"     REFERENCE(R_IPADD) TYPE EWAWA_IPADDRESS               User IP Address*"     REFERENCE(R_STAMP) TYPE ZTIMESTAMP Time Stamp         Time Stamp*"     REFERENCE(R_OSUSER) TYPE /BEV2/ED_GEN_TABLEDATA       OS User Name*"     REFERENCE(R_DOMAIN) TYPE /BEV2/ED_GEN_TABLEDATA       Domain*"     REFERENCE(R_DNSDOMAIN) TYPE /BEV2/ED_GEN_TABLEDATA    DNS Domain*"     REFERENCE(R_COMPUTERNAME) TYPE /BEV2/ED_GEN_TABLEDATA Computer Name*"----------------------------------------------------------------------  DATA: l_hostaddr1    TYPE  msxxlist-hostadr,        l_hostaddr2(8) TYPE c,        itimes         TYPE i,        itimes1        TYPE i,        hx(2),        result         TYPE i,        resulttxt(3),        iptxt(15),        l_time         TYPE timestampl,        l_timestamp(9) TYPE c.
GET TIME STAMP FIELD l_time. l_timestamp = FRAC( l_time )."l_time. l_timestamp = l_timestamp+2(7). REPLACE ALL OCCURRENCES OF '.' IN l_timestamp WITH ''. r_stamp = l_timestamp. "時間戳記
*Get Computer name CALL METHOD cl_gui_frontend_services=>get_computer_name CHANGING computer_name = r_computername EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
* Get IP Address CALL METHOD cl_gui_frontend_services=>get_ip_address RECEIVING ip_address = r_ipadd EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 99. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
*Get OS User name CALL METHOD cl_gui_frontend_services=>get_user_name CHANGING user_name = r_osuser EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
*因為Get Domain及Get DNS Domain需要SAP GUI端另放行權限,
*若沒有需求,可以將該兩段Mark.
**Get Domain* CALL METHOD cl_gui_frontend_services=>environment_get_variable* EXPORTING* variable = 'USERDOMAIN'* CHANGING* value = r_domain* EXCEPTIONS* cntl_error = 1* error_no_gui = 2* not_supported_by_gui = 3* OTHERS = 4.** IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* ENDIF.***Get DNS Domain* CALL METHOD cl_gui_frontend_services=>environment_get_variable* EXPORTING* variable = 'USERDNSDOMAIN'* CHANGING* value = r_dnsdomain* EXCEPTIONS* cntl_error = 1* error_no_gui = 2* not_supported_by_gui = 3* OTHERS = 4.** IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* ENDIF.

*Flush CALL METHOD cl_gui_cfw=>flush EXCEPTIONS cntl_system_error = 1 cntl_error = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.ENDFUNCTION.

SAP 获取本机信息(IP及电脑名称)

*&---------------------------------------------------------------------**& 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.
   REPORT Z_GET_FRONTEND_HOSTNAME.
DATA: OPCODE(1) TYPE X VALUE 5, COMPUTER_NAME TYPE USR41-TERMINAL.
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE ID'TERMINAL' FIELD COMPUTER_NAME. WRITE / COMPUTER_NAME. DATA(IP_ADDRESS) = CL_GUI_FRONTEND_SERVICES=>GET_IP_ADDRESS( ). WRITE / IP_ADDRESS.
DATA WINUSER TYPE STRING.***Get Windows User Name CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_USER_NAME CHANGING USER_NAME = WINUSER EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 NOT_SUPPORTED_BY_GUI = 3 OTHERS = 4.
CL_GUI_CFW=>FLUSH( ).
WRITE /: WINUSER.
DATA:COMPUTER_NAME_01 TYPE STRING.
CL_GUI_FRONTEND_SERVICES=>GET_COMPUTER_NAME( CHANGING COMPUTER_NAME = COMPUTER_NAME_01 ).* EXCEPTIONS* cntl_error = 1* error_no_gui = 2* not_supported_by_gui = 3* others = 4* ). CL_GUI_CFW=>UPDATE_VIEW( ).
WRITE / COMPUTER_NAME.



是老周,如果你喜欢我的文字,请记得点击⬇️关注我。


码字不易,文章下拉,右边点个【赞】和【在看】吧!!

猜您还喜欢合集:


解决方案

SAP优化

ABAP新语法

SAP Note

SAP

ABAP

懒人鱼


猜您还喜欢文章:

聊聊ABAP动态编程

SAP这样优化:乙方开心,甲方放心!

浅谈SAP/SSO介绍及应用

浅谈SAP/ 文档管理解决方案

浅谈SAP/某化学纤维行业客户-优化案例


曰天曰地
我要到哪里去↔️ 灵台方寸山,斜月三星洞。假如有一天全人类不存在,怎么证明人类存在过。AI怎么考古?会怎么考古⚠️
 最新文章