Block the user if the user not logged more than 90 days using BAPI_USER_CHANGE

Block the user if the user not logged more than 90 days using BAPI_USER_CHANGE and validity date will updated with current date.

1.Give the import parameters as number of days and test flag

2.Create the structure as per output pass into the export parameters ET_RETURN.

Structure as per your output.

 DATA: lv_last_logon_date TYPE xuldate, lv_days TYPE vtbbewe-atage, ls_date TYPE bapilogond, ls_flag TYPE bapilogonx, lt_return TYPE bapiret2_t, lv_dat TYPE dats, lv_sysid LIKE sy-sysid. *DATA: lt_task_type type ty_task_type occurs 0 with header line,
* task_text LIKE swwvpublic-wi_rhtext. * Getting the last 90 days date lv_dat = sy-datum - im_dtrdat.
* Based on the last login date fetch the user details SELECT bname,trdat,ustyp,class FROM usr02 INTO TABLE @DATA(lt_user) WHERE ( trdat LE @lv_dat AND ustyp = 'A' AND CLASS LIKE 'GRC%'). delete lt_user WHERE trdat is INITIAL.
** Function module to get the SYSTEMID CALL FUNCTION 'MSS_GET_SY_SYSID' IMPORTING sapsysid = lv_sysid. IF lt_user IS NOT INITIAL. LOOP AT lt_user ASSIGNING FIELD-SYMBOL(<fs_user>). APPEND INITIAL LINE TO et_return ASSIGNING FIELD-SYMBOL(<ls_return>).
***--Update user valid to date ls_date-gltgb = sy-datum. ls_flag-gltgb = 'X'. CALL FUNCTION 'BAPI_USER_CHANGE' EXPORTING username = <fs_user>-bname logondata = ls_date logondatax = ls_flag TABLES return = lt_return. IF sy-subrc EQ 0. <ls_return>-userid = <fs_user>-bname. <ls_return>-last_logon = <fs_user>-trdat. <ls_return>-ustyp = <fs_user>-ustyp. <ls_return>-class = <fs_user>-class. <ls_return>-systemid = lv_sysid. <ls_return>-status = 'User' && | | && <fs_user>-bname && | | && 'Expried-Contact system Administator For Logon'. ELSE. <ls_return>-userid = <fs_user>-bname. <ls_return>-last_logon = <fs_user>-trdat. <ls_return>-ustyp = <fs_user>-ustyp. <ls_return>-systemid = lv_sysid. READ TABLE lt_return INTO DATA(ls_return) WITH KEY type = 'E'. IF sy-subrc = 0. <ls_return>-status = ls_return-message . ENDIF. ENDIF. ENDLOOP. ENDIF. ENDFUNCTION.

Finally execute the function module, we will get the list of blocked users, updated validity date with current date.

Note: Before you run this code please comment the BAPI_USER_CHANGE function module other wise users will effect with their logins.

Hope it will useful.

Thank you

Siva sidda.