Retrieve the email address for a specific user

 

In a scenario that requires a recipient email address that is not on the form or that can be created by Floe internal process, the email address must be retrieved for the specific user.

A BAPI can be used, however, in the case where the logged on user does not have authorization to access the specified user's details, the email address cannot be retrieved.

The code below mirrors that used to create Floe email recipients for the real form user as setup by the Routing User-Exit and retrieves the users email address overriding the authorization check.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
DATA: ls_vars       TYPE /floe/vars_s,
        wa_address    TYPE bapiaddr3,
        it_return     TYPE TABLE OF bapiret2,
        lv_user       TYPE xubname,
        lv_persnumber TYPE ad_persnum,
        lv_addrnumber TYPE ad_addrnum,
        lv_smtp_addr  TYPE ad_smtpadr,
        ls_rec        TYPE /floe/rec_email_s.

*Get TXT_MAN_USER from  im_variales
  CLEAR ls_vars.
  CLEAR lv_user.
  CLEAR: lv_persnumber, lv_addrnumber, lv_smtp_addr.

  READ TABLE im_variables WITH KEY var_code = 'TXT_MAN_USER' INTO ls_vars.
  IF sy-subrc IS INITIAL.
    lv_user = ls_vars-value.

    CALL FUNCTION 'SUSR_USER_ADDRESSKEY_GET'
      EXPORTING
        bname             = lv_user
      IMPORTING
        persnumber        = lv_persnumber
        addrnumber        = lv_addrnumber
      EXCEPTIONS
        address_not_found = 1
        OTHERS            = 2.

    IF sy-subrc = 0.
      SELECT SINGLE smtp_addr FROM adr6 INTO lv_smtp_addr
                     WHERE addrnumber = lv_addrnumber AND
                           persnumber = lv_persnumber.
    ENDIF.

    ls_rec-email = lv_smtp_addr.  "Recipient email address - manager.
    ls_rec-type = '1'.
    APPEND ls_rec TO ch_recipients.
  ENDIF.

*CLEAR ch_recipients.