ADDR_PERS_COMP_COMM_MAINTAIN to Update sap users email address plus other details (own data)

The below SAP ABAP code shows how update a sap users emails address within their user profile data(see menu option System->User Profile->Own Data). This is performed via the use of function module ADDR_PERS_COMP_COMM_MAINTAIN.

First the ABAP code uses FM's SUSR_USER_ADDRESS_READ and ADDR_PERS_COMP_COMM_GET to get the users current own data. It then changes the email address to [email protected] using ADDR_PERS_COMP_COMM_MAINTAIN. Make sure you also execute the FM ADDR_MEMORY_SAVE at the end otherwise changes will not be written back to the SAP database.


  DATA: ld_address LIKE  addr3_val,
        ld_usr03   LIKE  usr03,
        ld_userid  type sy-uname,
        ld_smtp LIKE adsmtp OCCURS 0 WITH HEADER LINE.
  DATA: RETURNCODE type c,
        it_error type standard table of ADDR_ERROR.
  ld_userid = sy-uname.
  CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
    EXPORTING
      user_name                    = ld_userid
*   READ_DB_DIRECTLY             = ' '
    IMPORTING
      user_address                 = ld_address
      user_usr03                   = ld_usr03
    EXCEPTIONS
      user_address_not_found       = 1
      OTHERS                       = 2.
* Get additional user address details (i.e. email) 
  CALL FUNCTION 'ADDR_PERS_COMP_COMM_GET'
    EXPORTING
     ADDRESS_NUMBER          = ld_address-addrnumber
     PERSON_NUMBER           = ld_address-persnumber
      table_type              = 'ADSMTP'   "email details
*                   Other valid entries for table_type include:
*                       ADFAX for fax details
*                       ADTEL for telephone details  
*   IMPORTING
*     RETURNCODE              =
    tables
      comm_table              =  ld_smtp
*     ERROR_TABLE             =
   EXCEPTIONS
     PARAMETER_ERROR         = 1
     ADDRESS_NOT_EXIST       = 2
     PERSON_NOT_EXIST        = 3
     INTERNAL_ERROR          = 4
     OTHERS                  = 5.
if sy-subrc eq 0.
  loop at ld_smtp.
    ld_smtp-UPDATEFLAG = 'U'.
    ld_smtp-SMTP_ADDR = '[email protected]'.
    modify ld_smtp.
  endloop.
  CALL FUNCTION 'ADDR_PERS_COMP_COMM_MAINTAIN'
    EXPORTING
      ADDRESS_NUMBER    = ld_address-addrnumber
      PERSON_NUMBER     = ld_address-persnumber
      TABLE_TYPE        = 'ADSMTP'
    IMPORTING
      RETURNCODE        = RETURNCODE
    TABLES
      COMM_TABLE        = ld_smtp
      ERROR_TABLE       = it_error
    EXCEPTIONS
      PARAMETER_ERROR   = 1
      ADDRESS_NOT_EXIST = 2
      PERSON_NOT_EXIST  = 3
      INTERNAL_ERROR    = 4
      OTHERS            = 5.
  CALL FUNCTION 'ADDR_MEMORY_SAVE'
    EXCEPTIONS
      address_number_missing = 1
      person_number_missing  = 2
      internal_error         = 3
      database_error         = 4
      reference_missing      = 5
      OTHERS                 = 6.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.
endif.

Related Articles

ABAP4_CALL_TRANSACTION sap function module
BAPI_ALM_ORDER_MAINTAIN sap BAPI / Function Module to create a work order
Function module BAPI_EMPLCOMM_CREATE to maintain the SAP HR communication infotype 0105
CLPB_EXPORT sap function module
CLPB_IMPORT sap function module
CONVERT_DATE_TO_EXTERNAL sap function module
CREATE_TEXT sap function module
CURRENCY_AMOUNT_DISPLAY_TO_SAP sap function module to Convert currency value from display to SAP
CURRENCY_AMOUNT_SAP_TO_DISPLAY FM to Convert currency value from SAP to display
DATE_COMPUTE_DAY sap function module
DATE_TO_DAY sap function module
DOCU_READ sap function module
ENQUEUE_READ sap function module
F4IF_INT_TABLE_VALUE_REQUEST sap function module
FILE_GET_NAME sap function module
SAP Application specific function modules
SAP Custom function modules
SAP field conversion function modules
SAP HR specific function modules
SAP development function modules
Retrieve employees address details (own data)
Function Module DYNP_VALUES_UPDATE to Change screen field contents
sxpg_command_execute FM to Execute external commands (FTP Scripts)
DETERMINE_PERIOD FM to Retrieve fiscal year and period
Function module HR_INFOTYPE_OPERATION to maintain SAP HR infotypes
RH_PM_GET_STRUCTURE FM to retrieve HR Organisation Structure
Validate WBS (code used in ME21)
HR_READ_INFOTYPE SAP FM to Read infotype data
READ_TEXT FM to Read SAP texts
HR_PERSONAL_WORK_SCHEDULE to Retrieve employees work schedule
NUMBER_GET_NEXT to get next number in number range sap function module
Generate random number using QF05_RANDOM_INTEGER SAP function module within your ABAP code
RSEC_GENERATE_PASSWORD SAP FM to generate user password
The SAP internet user functionality and Password BAPIs
SAPGUI_SET_FUNCTIONCODE sap function module to execute function code
SX_INTERNET_ADDRESS_TO_NORMAL SAP function module to check email format is correct