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¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
MAX_ROWS |
IMPORTING | BAPIUSMISC-BAPIMAXROW |
Upper limit on returned rows. 0 = unlimited. |
WITH_USERNAME |
IMPORTING | BAPIUSMISC-WITH_NAME |
Pass 'X' to populate the username field in USERLIST. Default: SPACE. |
ROWS |
EXPORTING | BAPIUSMISC-BAPIROWS |
Number of rows returned. |
SELECTION_RANGE |
TABLES | BAPIUSSRGE |
Filter by user attributes (username, user type, etc.) — see example. |
SELECTION_EXP |
TABLES | BAPIUSSEXP |
Expression-based filter (alternative to SELECTION_RANGE). |
USERLIST |
TABLES | BAPIUSNAME |
Output — list of matching user IDs. |
RETURN |
TABLES | BAPIRET2 |
Messages — always check this. |
Example¶
DATA: lt_sel TYPE STANDARD TABLE OF bapiussrge,
lt_userlist TYPE STANDARD TABLE OF bapiusname,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_rows TYPE bapiusmisc-bapirows.
" Filter: usernames starting with 'TEST'
APPEND VALUE #(
parameter = 'USERNAME'
sign = 'I'
option = 'CP'
low = 'TEST*'
) TO lt_sel.
CALL FUNCTION 'BAPI_USER_GETLIST'
EXPORTING
max_rows = 500
with_username = 'X'
IMPORTING
rows = lv_rows
TABLES
selection_range = lt_sel
userlist = lt_userlist
return = lt_return.
LOOP AT lt_return INTO DATA(ls_msg) WHERE type CA 'EAX'.
WRITE: / ls_msg-message.
ENDLOOP.
WRITE: / |{ lv_rows } users found.|.
" 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 — and if you genuinely need the full population, consider scheduling it as a background job.
No COMMIT needed
This is a read-only BAPI. Do not call BAPI_TRANSACTION_COMMIT after it.
WITH_USERNAMEis a flag, not a filter. Pass'X'to have the FM populateUSERLIST-USERNAME. Without it the output rows may be empty.- Output is user IDs only.
USERLISTcontains onlyUSERNAME. For names, emails, roles, or any other attribute make a second call toBAPI_USER_GET_DETAIL. SELECTION_RANGE-PARAMETERaccepts values like'USERNAME','USTYP','ALIAS'— check theBAPIUSSRGEstructure in SE11 for the full list.- 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