Skip to content

CL_USER_MASTER_DATA

OO wrapper for reading and writing SAP user master data (SU01).

Purpose

CL_USER_MASTER_DATA is a class-based alternative to BAPI_USER_GET_DETAIL and BAPI_USER_CHANGE. It provides a cleaner API for reading and updating user address, logon data, roles, and profiles without manually assembling BAPI parameter structures.

Availability varies by release and SP level

This class was introduced in newer ABAP releases and is not available on older ECC systems. Before using it, verify its existence in SE24. Always implement a BAPI_USER_GET_DETAIL fallback for portability. See BAPI_USER_GET_DETAIL.

Key methods

Method Type Signature Effect
get_user_data Static (factory) ( username ) → instance Creates and loads an instance for the given user
get_address Instance ( ) → address structure Returns the user's SU01 address data
get_logondata Instance ( ) → logondata structure Returns logon settings (validity, password policy, etc.)
get_roles Instance ( ) → roles table Returns assigned roles (AGR_NAME)
get_profiles Instance ( ) → profiles table Returns assigned profiles
set_address Instance ( address ) Stages address changes
set_logondata Instance ( logondata ) Stages logon data changes
save Instance ( ) Commits all staged changes to the database

Example

Read a user's address and validity dates:

REPORT z_user_master_demo.

PARAMETERS p_user TYPE xubname DEFAULT sy-uname.

START-OF-SELECTION.

  TRY.
      " factory method loads user data from the database
      DATA(lo_user) = cl_user_master_data=>get_user_data(
                        username = p_user ).

      " read address
      DATA(ls_address) = lo_user->get_address( ).
      WRITE: / 'First name:', ls_address-firstname,
             / 'Last name: ', ls_address-lastname,
             / 'Email:     ', ls_address-e_mail.

      " read logon data (validity dates)
      DATA(ls_logon) = lo_user->get_logondata( ).
      WRITE: / 'Valid from:', ls_logon-gltgv,
             / 'Valid to:  ', ls_logon-gltgb.

    CATCH cx_user_master_data INTO DATA(lx).
      MESSAGE lx->get_text( ) TYPE 'E'.
  ENDTRY.

To update the validity end-date and save:

  TRY.
      DATA(lo_user) = cl_user_master_data=>get_user_data(
                        username = p_user ).

      DATA(ls_logon) = lo_user->get_logondata( ).
      ls_logon-gltgb = '20991231'.            " extend validity
      lo_user->set_logondata( ls_logon ).
      lo_user->save( ).

      WRITE: / 'User', p_user, 'updated.'.

    CATCH cx_user_master_data INTO DATA(lx).
      MESSAGE lx->get_text( ) TYPE 'E'.
  ENDTRY.

Common pitfalls

No fallback = hard failure on older systems

CL_USER_MASTER_DATA does not exist in older ECC releases. A CREATE OBJECT or static call on a missing class raises CX_SY_CREATE_OBJECT_ERROR. Always wrap usage in a release check or provide a BAPI-based alternative path.

save( ) requires S_USER_GRP authorisation

Writing user master data requires the S_USER_GRP object with activity 02. If your program runs in a background job or under a service user, ensure the authorisation is assigned. Missing it causes a CX_USER_MASTER_DATA exception with an auth-check message.

Staged changes are lost without save( )

set_address, set_logondata, and similar methods stage changes in memory only. Nothing is written to the database until save( ) is called explicitly. If the program ends without save( ), all changes are discarded silently.

  • The exception class is CX_USER_MASTER_DATA (check SE24 for the exact name in your system — it may differ by release).
  • get_roles and get_profiles return the currently assigned roles/profiles. To add or remove, modify the returned table and pass it back via the corresponding set_* method before calling save( ).
  • For mass user processing, BAPI_USER_GET_DETAIL with CALL FUNCTION IN BACKGROUND TASK is often more efficient than calling save( ) in a loop.

See also

  • CL_SALV_TABLE — display user data in an ALV grid
  • BAPI_USER_GET_DETAIL — BAPI fallback for older systems
  • Transaction SE24 — verify class existence and method signatures in your system
  • Transaction SU01 — manual user maintenance reference

Comments