BAPI_USER_GETLIST¶
Search for SAP users matching filter criteria — returns a list of user IDs.
Purpose¶
Queries the user master for IDs that match one or more filter criteria. Useful for building bulk-action loops (lock all users of a given type, audit roles for a department, etc.). Returns only user IDs — call BAPI_USER_GET_DETAIL in a loop to fetch full records.
Signature (the parts you'll actually use)¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
MAX_ROWS |
IMPORTING | SY-TABIX |
Upper limit on returned rows. 0 = unlimited. |
WITH_USERNAME |
TABLES | SUSR_RFC_BAPIUSNAME |
Range table to filter by user ID (LIKE, EQ, BT, etc.) |
WITH_USTYP |
TABLES | SUSR_RFC_USTYP |
Range table to filter by user type (A, B, C, L, S) |
WITH_ALIAS |
TABLES | SUSR_RFC_XUBNAME |
Range table to filter by alias |
USERLIST |
TABLES | BAPIUSNAME |
Output — list of matching user IDs |
RETURN |
TABLES | BAPIRET2 |
Messages — always check this |
Example¶
DATA: lt_filter TYPE STANDARD TABLE OF susr_rfc_bapiusname,
lt_userlist TYPE STANDARD TABLE OF bapiusname,
lt_return TYPE STANDARD TABLE OF bapiret2.
" Find all dialog users whose ID starts with 'TEST'
APPEND VALUE #(
sign = 'I'
option = 'CP'
low = 'TEST*'
) TO lt_filter.
CALL FUNCTION 'BAPI_USER_GETLIST'
EXPORTING
max_rows = 500
TABLES
with_username = lt_filter
userlist = lt_userlist
return = lt_return.
LOOP AT lt_return INTO DATA(ls_msg) WHERE type CA 'EAX'.
WRITE: / ls_msg-message.
ENDLOOP.
" Enrich results — one call per user
LOOP AT lt_userlist INTO DATA(ls_user).
DATA: ls_address TYPE bapiaddr3,
lt_detail_r TYPE STANDARD TABLE OF bapiret2.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING username = ls_user-username
IMPORTING address = ls_address
TABLES return = lt_detail_r.
WRITE: / ls_user-username, ls_address-e_mail.
ENDLOOP.
Common pitfalls¶
MAX_ROWS = 0 means unlimited
On a system with tens of thousands of users, an unrestricted call can run for a very long time and place heavy load on the database. Always set a sensible MAX_ROWS in production unless you genuinely need the full population — and if you do, consider scheduling it as a background job.
No COMMIT needed
This is a read-only BAPI. Do not call BAPI_TRANSACTION_COMMIT after it.
- Output is user IDs only.
USERLISTcontains only theUSERNAMEfield (BAPIUSNAME-USERNAME). For names, emails, roles, or any other attribute you must make a second call toBAPI_USER_GET_DETAIL. - Range tables support full SELECT-OPTIONS syntax —
EQ,NE,BT,CP(contains pattern with*) all work. - Always check the RETURN table — never assume success.
Related¶
BAPI_USER_GET_DETAIL— fetch full data for each ID in USERLISTBAPI_USER_LOCK/BAPI_USER_UNLOCK— act on the result setBAPI_USER_CHANGE— bulk-change users from the result set
See also¶
- Transactions: SUIM (user information system — same data, GUI-driven)
- User type values:
ADialog,BSystem,CCommunication,LReference,SService