SAP ABAP编程 取得用户中文名称
有时候我们知道SAP当前用户登录的ID,也就是SY-UNAME。能够取得用户中文名称。例如以下:
***取得用户中文名称
DATA: g_sheet_jsr TYPE string. "用户中文名称
DATA: L_DEPARTMENT TYPE AD_DPRTMNT,
L_ADDRNUMBER TYPE AD_ADDRNUM,
L_PERSNUMBER TYPE AD_PERSNUM,
L_UNAME TYPE SY-UNAME,
L_NAME_FIRST TYPE AD_NAMEFIR,
L_NAME_LAST TYPE AD_NAMELAS.
***取得用户中文名称
SELECT SINGLE persnumber addrnumber INTO
(l_persnumber, l_addrnumber)
FROM usr21
WHERE bname = SY-UNAME.
IF sy-subrc = 0.
SELECT SINGLE name_first name_last INTO (l_name_first,l_name_last)
FROM adrp
WHERE persnumber = l_persnumber.
IF sy-subrc = 0.
CONCATENATE l_name_last l_name_first INTO g_sheet_jsr.
CONDENSE g_sheet_jsr NO-GAPS. "去掉空格字符
ENDIF.
ENDIF.
write: g_sheet_jsr.
另一种更加简便的方法就是调用PABI
DATA: G_FULL_NAME TYPE AD_NAMTEXT, "用户中文名称
G_NAME_FIRST TYPE AD_NAMEFIR,
G_NAME_LAST TYPE AD_NAMELAS.
CALL FUNCTION 'FDM_CUST_USER_NAME_READ_SINGLE'
EXPORTING
I_USER_ID = SY-UNAME
IMPORTING
E_FIRSTNAME = G_NAME_FIRST
E_LASTNAME = G_NAME_LAST
* E_FULLNAME =
.
IF SY-SUBRC = 0.
CONCATENATE G_NAME_LAST G_NAME_FIRST INTO G_FULL_NAME .
CONDENSE G_FULL_NAME NO-GAPS. "去掉空格字符
ENDIF.
write: G_FULL_NAME .