Unlock SAP Users

1-) Getting blocked user list

2-) Unblock user accounts.

Selection Screen:

 1

Codes:

 

report  zanil.

* This Program Unblocks Users SAP Accounts

* Block values:

* 1. 32   – Locked Globally By Administrator

* 2. 64   – Locked Locally By Administrator

* 3. 128 – Locked Due To Incorrect Logons (Limited Term)

tablesusr02.

selectoptionss_bname for usr02bname.

parametersp_32  as checkbox.

parametersp_64  as checkbox.

parametersp_128 as checkbox.

startofselection.

data lt_return  type table of bapiret2.

data lt_usr02   type table of usr02.

data ls_usr02   type          usr02.

data ls_return  type          bapiret2.

data lv_message type          string.

* Getting all blocked user list

select from usr02

  into corresponding fields of table lt_usr02

  where bname in s_bname

    and uflag ne ‘0’.

* Deleting globally data if not checked.

if p_32 is initial.

   delete lt_usr02 where uflag eq ’32’.

endif.

* Deleting locally data if not checked.

if p_64 is initial.

   delete lt_usr02 where uflag eq ’64’.

endif.

* Deleting incorrect data if not checked.

if p_128 is initial.

   delete lt_usr02 where uflag eq ‘128’.

endif.

if lt_usr02[] is initial.

   message ‘No data found!’ type ‘W’.

   exit.

endif.

loop at lt_usr02 into ls_usr02.

 clearlt_returnls_returnlv_message.

 call function ‘BAPI_USER_UNLOCK’

   exporting

     username  ls_usr02bname

   tables

     return    lt_return.

 read table lt_return into ls_return

   with key type ‘S’.

 if sysubrc eq 0.

    concatenate ls_usr02bname

                ‘unblocked succesfully’

           into lv_message.

  else.

    concatenate ls_usr02bname

                ‘failed’

           into lv_message.

  endif.

  write :/ lv_message.

endloop.

FM to create background job

FM to create a background job:

Imports:

 

imports

Result:

result

Source Code:

FUNCTION ZTB_CREATE_JOB.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     REFERENCE(I_JOBNAME) TYPE  STRING

*”     REFERENCE(I_REPORT) TYPE  STRING

*”     REFERENCE(I_VARIANT) TYPE  STRING OPTIONAL

*”     REFERENCE(I_UNAME) TYPE  STRING OPTIONAL

*”  EXPORTING

*”     REFERENCE(E_RETURN) TYPE  BAPIRET2

*”———————————————————————-

data:

lv_jobname  like tbtcjobjobname,

lv_report   like syrepid,

lv_variant  like raldbvariant,

lv_uname    like syuname,

lv_jobcount like tbtcjobjobcount,

lv_released type c.

lv_jobname i_jobname.

lv_report  i_report.

lv_variant i_variant.

lv_uname   i_uname.

if lv_uname is initial.

   lv_uname syuname.

endif.

* Step 1

call function ‘JOB_OPEN’

  exporting

    jobname         lv_jobname

  importing

    jobcount        lv_jobcount

 exceptions

   cant_create_job  1

   invalid_job_data 2

   jobname_missing  3

   others           4

          .

if sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

* Step 2

call function ‘JOB_SUBMIT’

  exporting

    authcknam              lv_uname

    jobcount               lv_jobcount

    jobname                lv_jobname

    report                 lv_report

    variant                lv_variant

 exceptions

   bad_priparams           1

   bad_xpgflags            2

   invalid_jobdata         3

   jobname_missing         4

   job_notex               5

   job_submit_failed       6

   lock_failed             7

   program_missing         8

   prog_abap_and_extpg_set 9

   others                  10          .

if sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

* Step 3

call function ‘JOB_CLOSE’

  exporting

    jobcount            lv_jobcount

    jobname             lv_jobname

    strtimmed           ‘X’

 importing

   job_was_released     lv_released

 exceptions

   cant_start_immediate 1

   invalid_startdate    2

   jobname_missing      3

   job_close_failed     4

   job_nosteps          5

   job_notex            6

   lock_failed          7

   invalid_target       8

   others               9.

if sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

ENDFUNCTION.