Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
1,361
Delete the user if the user was not logged in more than 360 days using BAPI_USER_DELETE

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.


3.Structure as per your output.


Now click on Source code write the below code
FUNCTION zuser_login_check360.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(DTRDAT) TYPE JBNTAGE DEFAULT 360
*" EXPORTING
*" REFERENCE(EX_RETURN) TYPE ZT_USER
*"----------------------------------------------------------------------
* Data declarations
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.
* **--- Getting the last 180 days dates
lv_dat = sy-datum - 360.
* Based on the last login date fetch the user details
SELECT bname,trdat FROM usr02
INTO TABLE @DATA(lt_user)
WHERE trdat LE @lv_dat.

IF lt_user IS NOT INITIAL.
* **--Fetch User details
SELECT bname, name_first, name_last FROM user_addr
INTO TABLE @DATA(lt_addr)
FOR ALL ENTRIES IN @lt_user
WHERE bname = @lt_user-bname.
LOOP AT lt_addr ASSIGNING FIELD-SYMBOL(<fs_user>).
**--Update user valid to date
CALL FUNCTION 'BAPI_USER_DELETE'
EXPORTING
username = <fs_user>-bname
tables
return = lt_return.
IF sy-subrc EQ 0.
APPEND INITIAL LINE TO ex_return ASSIGNING FIELD-SYMBOL(<ls_return>).
<ls_return>-username = <fs_user>-bname.
<ls_return>-firstname = <fs_user>-name_first.
<ls_return>-lastname = <fs_user>-name_last.
READ TABLE lt_return INTO DATA(ls_return) WITH KEY type = 'S'.
<ls_return>-status = 'User' && | | && <fs_user>-bname && | | && 'Deleted' .
ELSE.
<ls_return>-username = <fs_user>-bname.
<ls_return>-firstname = <fs_user>-name_first.
<ls_return>-lastname = <fs_user>-name_last.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
<ls_return>-status = ls_return-message .
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.

ENDFUNCTION.

 

Now execute the function module we will get the deleted users.

NOTE: While testing the code please comment the BAPI_USER_DELETE, Otherwise users would be deleted from the system.

Thank you

Siva sidda.

 

 

 
1 Comment
Labels in this area