Skip to Content
Sometime ago, I was going through a non-SDN forum where I found an interesting report program which is meant for sending mails to Basis Team or the concerned person whom has to be informed about number of Users who haven’t logged-on to the system for the past given number of days.

 

It would be icing on the cake, if program also sends individual emails to all the not-logged users informing them about their absence to the system, further more sending an excel-sheet containing list of all not-logged users to the Basis would also be a better idea.

I am going to demonstrate a report program that contains a selection-screen that inputs number of days, recipient address obviously Basis’ mail address and recipient type (SAP Logon Name type B, External Address type A, Internet Address type U, etc). But in order to send mails to external servers from SAP system, requires a little exercise; configuration of ICM – Internet Connection Manager using a couple of standard transactions.

Let our esteemed blogger Thomas Jung explain configuration of ICM; Sending E-Mail from ABAP – Version 610 and Higher – BCS Interface. Once mail sending capabilities of SAP system makes us content, further step can be taken.

Here we go; we’ll going to use USR02, USR21, ADRP, ADR6 database tables which help us get detailed information, but using Joins to get data across the tables is not a better idea to get along, ‘FOR ALL ENTRIES’ is a better substitute to it. Moreover, we’ll also going to use WS_DOWNLOAD rather GUI_DOWNLOAD, since GUI_DOWNLOAD doesn’t make header-lines appear in the excel sheet to be downloaded in the local drive as well as to send it as an attachment.

 

As a norm we’ll begin with the declaration part first;

We have to move p_days that is an integer data type to w_days character data type since character data-types can only be used in concatenate function.

Further, we begin with functionalizing subroutines;

We use ranges to get list of last-login dates of users between the date of execution of the program and the past given determined date.

 

Moreover, email has to be sent to only those users whose email-ids have been found, else sending mails to all detected users makes no ordinary sense.

Besides sending excel-sheet as an attachment to the Basis, it should also be saved on local drive; we make here a simple download in C drive, for desired location of saving CL_FRONTEND_SERVICES can be used.

 

 

Finally, once coding is finely reviewed; save, activate and execute the program;

 

 

No sooner mail is sent successfully, a status message is given as acknowledgment.

 

As soon as mail is sent; mail is found standing in the inbox.

 

The attached excel-sheet gives details of the not logged users the following way;

 

 

Besides getting excel-sheet in the mail attachment; the same copy is found resting in C drive, as specified in WS_DOWNLOAD Function Module.

Well, the Basis team email address, the number of days and recipient type could be hard-coded, but I felt to make it more dynamic so program-executer can feel easy to specify any email address, he desires. Moreover, this also helps get a quick view of the Users logged-on for the specified time, if the logic in the first select-query is bit modified.

Besides giving the above concept, I hope this blog has surely made a room to understand the mailing concept in SAP in a more reliable way.

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Michael Brenner
    Your coding selects the users that have logged on in the past 30 days.

    To correct your report replace the initial lines of FORM get_user_list with the coding below:

    FORM get_user_list .
      DATA:l_date TYPE sy-datum,
           l_lower_date like sy-datum.
      RANGES: r_date FOR sy-datum.

      l_lower_date  = ‘19000101’.
      l_date = sy-datum – p_days.

      r_date-low = l_lower_date.
      r_date-high = l_date.
      r_date-sign = ‘I’.
      r_date-option = ‘BT’.

    Regards,

    Michael

    (0) 
    1. Zahack Z Post author
      Well, I intended at providing a range user desires; for example if user enters 20 days then 20 gets subtracted from sy-datum and past 20 days’ list will be generated.

      Anyway, thanks for reviewing. 🙂

      (0) 
      1. Michael Brenner
        Well you send out the following mails to the users:

        “You have not logged on for 30 days for client 100”

        With your code those mails are sent out to users who HAVE logged on in the past 30 days. You can see that behaviour on your screenshot as well (column: “days not logged” on always below 30).

        (0) 
  2. Julius von dem Bussche
    What if the user is locked by admin and or the account is invalid because they have left the company?

    Generally, instead of selecting directly from USR tables who’s single fields might change as well as how they are to be interpreted and dependencies between them, I would recommend using BAPI_USER_GETLIST which contains the logic for you and all the correct authorization checks.

    For example, in the report there are no checks – so anyone who can run it will find out who your users are and possibly what they are doing (e.g. being idle, or on vacation, etc) or used for.

    Just an idea: If this content were in the wiki then others could add to it and tune it further.

    As an after-thought: Your code would also be a lot shorter… if you take a look at report RSUSR200… 🙂

    Cheers,
    Julius

    (0) 
  3. Jim Spath
    Email?  How quaint.

    Enterprises require a robust protocol for alert management, in my opinion.  Any breakage in the infrastructure could result in lost notifications, not to mention corporate retention requirements.

    Jim

    (0) 
    1. Julius von dem Bussche
      Hi Jim,

      I don’t think the above report can be classified as an alert – in the same way that a CCMS agent might “alert” events which are critical for the enterprize and a record might need to be kept of it.

      Thankfully the above report also does not have any auto-reaction methods implemented, at least not yet… 😉

      Cheers,
      Julius

      (0) 

Leave a Reply