*&---------------------------------------------------------------------*
*&
*&功能: 用户多次输入密码错误后,自动解锁,修改密码并自动发邮件
*&---------------------------------------------------------------------*
*&注意需要设置程序RSUSR200中变式 USERLOCK'
*&
*&---------------------------------------------------------------------*
REPORT Z_UNLOCK_USER.
PARAMETERS EX2MAIL(100) DEFAULT 'twttafku@163.com'.
PARAMETERS S2ADMIN AS CHECKBOX.
DATA:ZRETURN TYPE TABLE OF BAPIRET2 .
FIELD-SYMBOLS:<LT_DATA> TYPE ANY TABLE,
<LT_DATA_LINE> TYPE ANY TABLE.
DATA: LR_DATA TYPE REF TO DATA,
LR_DATA_LINE TYPE REF TO DATA.
DATA: LR_DATA_DESCR TYPE REF TO CL_ABAP_DATADESCR,
LR_DATA_DESCR_LINE TYPE REF TO CL_ABAP_DATADESCR.
DATA: USERNAME TYPE BAPIBNAME-BAPIBNAME,
LOGONDATA LIKE BAPILOGOND,
LOGONDATAX LIKE BAPILOGONX,
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF TYP_ITAB,
BNAME TYPE XUBNAME, "用户名
TRDAT1 TYPE XULDATE_ALV, "最后一次登录日期
USTYP TYPE XUUSTYP,
END OF TYP_ITAB.
DATA:GT_ITAB TYPE STANDARD TABLE OF TYP_ITAB,
GS_ITAB TYPE TYP_ITAB.
DATA:LV_FLAG TYPE CHAR1.
* Important to set display = abap_false so the standard program won’t display the ALV
CL_SALV_BS_RUNTIME_INFO=>SET(
EXPORTING DISPLAY = ABAP_FALSE
METADATA = ABAP_FALSE
DATA = ABAP_TRUE ).
* Submit standard program with selection table
SUBMIT RSUSR200
USING SELECTION-SET 'USERLOCK'
EXPORTING LIST TO MEMORY
AND RETURN.
CLEAR:LV_FLAG.
TRY."因ALV输出有header,list 所以要有2个参数
CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF(
IMPORTING R_DATA_DESCR = LR_DATA_DESCR
R_DATA_LINE_DESCR = LR_DATA_DESCR_LINE ).
CREATE DATA LR_DATA TYPE HANDLE LR_DATA_DESCR.
CREATE DATA LR_DATA_LINE TYPE HANDLE LR_DATA_DESCR_LINE.
ASSIGN LR_DATA->* TO <LT_DATA>.
ASSIGN LR_DATA_LINE->* TO <LT_DATA_LINE>.
CL_SALV_BS_RUNTIME_INFO=>GET_DATA(
IMPORTING
T_DATA = <LT_DATA>
* T_DATA_LINE = <LT_DATA_LINE>
).
CATCH CX_SALV_BS_SC_RUNTIME_INFO.
WRITE `Unable to retrieve ALV data` .
LV_FLAG = 'X'.
CATCH CX_SY_REF_IS_INITIAL.
WRITE 'NO DATA'.
LV_FLAG = 'X'.
ENDTRY.
CL_SALV_BS_RUNTIME_INFO=>CLEAR_ALL( ).
CHECK LV_FLAG IS INITIAL .
IF <LT_DATA> IS NOT ASSIGNED.
RETURN.
ENDIF.
MOVE-CORRESPONDING <LT_DATA> TO GT_ITAB.
DATA: L_EMAIL TYPE AD_SMTPADR.
DATA: STRINGPWD TYPE STRING.
DATA: BAPIPWD TYPE BAPIPWD.
LOOP AT GT_ITAB INTO GS_ITAB.
CLEAR L_EMAIL.
SELECT SINGLE SMTP_ADDR INTO L_EMAIL FROM ADR6
WHERE EXISTS ( SELECT BNAME FROM USR21
WHERE ADDRNUMBER = ADR6~ADDRNUMBER
AND PERSNUMBER = ADR6~PERSNUMBER
AND BNAME = GS_ITAB-BNAME ).
* READ TABLE t_p0105 WITH KEY subty = '0010' endda = '99991231'."读取有效的Email地址
* l_email = t_p0105-usrid_long.
IF S2ADMIN = 'X' OR L_EMAIL IS