Member-only story
Retrieving SAP User Details

For SAP ABAP developers, obtaining details of a logged-in user is often a crucial requirement. Information such as the user’s name, surname, department, and the factory they work at can be retrieved using a standard function module provided by SAP: BAPI_USER_GET_DETAIL. In this post, we will explain in detail how to use this function module.
What is BAPI_USER_GET_DETAIL?
BAPI_USER_GET_DETAIL is a standard function module used to retrieve detailed information about an existing user in the SAP system. Through this function, you can access:
- The user’s full name (first name and last name)
- The company or factory where the user works
- Department information
The function takes the USERNAME as input and returns the required details.
Usage of the Function
Below is an example of how to use the BAPI_USER_GET_DETAIL function. This code retrieves and displays the details of a logged-in SAP user:
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
USERNAME = USERNAME
IMPORTING
ADDRESS = INFOS
COMPANY = COMP
TABLES
RETURN = BRETURN.
IF INFOS IS INITIAL.
WRITE: 'User Not Found.'.
ELSE.
WRITE: 'Full Name: ' , INFOS-FULLNAME.
WRITE:/ 'Factory: ' , COMP-COMPANY.
WRITE:/ 'Department: ', INFOS-DEPARTMENT.
ENDIF.
Detailed Explanation of the Code
EXPORTING Parameter:
- USERNAME: Specifies the SAP username for which details are to be retrieved.
IMPORTING Parameters:
- ADDRESS (INFOS): Returns the user’s address details. This structure contains fields such as the user’s full name and department.
- COMPANY (COMP): Stores information about the factory or company where the user works.
TABLES Parameter:
- RETURN (BRETURN): A table that returns the status of the function execution, including success or error messages.
Error Handling:
- If INFOS is empty, it means the user details could not be retrieved, and a message “User Not Found” is displayed.
- If the details are successfully retrieved, the user’s full name, company, and department are displayed.
This function module is highly useful for managing user details in an SAP system and can be effectively utilized in various business scenarios.