Skip to content

BAPI_USER_CHANGE

Modify an existing SAP user's master data.

Purpose

Updates one or more fields on an existing user master record. Works like a PATCH: only fields explicitly flagged in the companion "X structure" are written. Everything else is left untouched. This is the standard RFC-enabled way to modify SU01 data from code or an external system.

Signature (the parts you'll actually use)

Parameter Direction Type Notes
USERNAME IMPORTING XUBNAME The user ID to change. Required.
LOGONDATA IMPORTING BAPILOGOND New values for validity, user type, time zone
LOGONDATAX IMPORTING BAPILOGONX Checkbox struct — set field to 'X' to activate change
ADDRESS IMPORTING BAPIADDR3 New address values
ADDRESSX IMPORTING BAPIADDR3X Checkbox struct for ADDRESS fields
PROFILES TABLES BAPIPROF Full replacement list of profiles (when X flag set)
PROFILESX IMPORTING BAPIPROFX Flag to replace profiles entirely
ACTIVITYGROUPS TABLES BAPIAGR Full replacement list of roles
ACTIVITYGROUPSX IMPORTING BAPIAGRX Flag to replace roles entirely
RETURN TABLES BAPIRET2 Messages — always check this

Example

DATA: lv_user    TYPE xubname VALUE 'TESTUSER',
      ls_logon   TYPE bapilogond,
      ls_logonx  TYPE BAPILOGONX,
      ls_addr    TYPE bapiaddr3,
      ls_addrx   TYPE bapiaddr3x,
      lt_return  TYPE STANDARD TABLE OF bapiret2.

" Extend validity and change email — nothing else
ls_logon-gltgb   = '20261231'.
ls_logonx-gltgb  = 'X'.        " <-- must match every field you set

ls_addr-e_mail   = 'new.email@example.com'.
ls_addrx-e_mail  = 'X'.

CALL FUNCTION 'BAPI_USER_CHANGE'
  EXPORTING
    username   = lv_user
    logondata  = ls_logon
    logondatax = ls_logonx
    address    = ls_addr
    addressx   = ls_addrx
  TABLES
    return     = lt_return.

IF NOT line_exists( lt_return[ type = 'E' ] ) AND
   NOT line_exists( lt_return[ type = 'A' ] ).
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING wait = 'X'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  LOOP AT lt_return INTO DATA(ls_msg) WHERE type CA 'EAX'.
    WRITE: / ls_msg-message.
  ENDLOOP.
ENDIF.

Common pitfalls

Forgetting the X structure is a silent no-op

This is the single most common mistake. If you populate LOGONDATA-GLTGB but do not set LOGONDATAX-GLTGB = 'X', the BAPI silently ignores your value. No error is returned. The field is not updated. Double-check that every data field you fill has its corresponding X flag set.

COMMIT WORK is mandatory

Changes are not persisted until you call BAPI_TRANSACTION_COMMIT (or COMMIT WORK). Always check RETURN first — never commit blind.

  • Profiles and roles are full replacement, not append. If you pass a PROFILES table and set the PROFILESX flag, the existing profiles are replaced entirely. Merge the existing list (read with BAPI_USER_GET_DETAIL) before passing if you want to add only one entry.
  • Authorisation required: S_USER_GRP with activity 02 (change) for the user's group.
  • Always check the RETURN table — never assume success.

See also

  • Transactions: SU01, SU10 (mass change)
  • Related types: BAPILOGONX, BAPIADDR3X, BAPIAGRX

Comments