
Example 2: Not Using the User Master Record
Use
This is an example of ABAP code for reading the accounting data for a specified account.
This example differs from Example 1 in that the statistics of the current day are read using the specified user account assignment. Data is cumulated from all available application servers.
Example
REPORT ZACCDEMO.
* read the accounting data for a defined account
* table with cumulated statistics
DATA BEGIN OF ACCOUNT_STATISTIC OCCURS 10.
INCLUDE STRUCTURE SAPWLACCTS.
DATA END OF ACCOUNT_STATISTIC.
* table with defined accounts
DATA BEGIN OF USER_ACCOUNT_RELATION OCCURS 10.
INCLUDE STRUCTURE USRACCNTV.
DATA END OF USER_ACCOUNT_RELATION.
* definition of three account relationships
"first relation
USER_ACCOUNT_RELATION-MANDT = '001'. "set the client
USER_ACCOUNT_RELATION-BNAME = 'USER_01'. "set the user name
USER_ACCOUNT_RELATION-ACCNT = 'ACCOUNT_01'. "set the account
"append new relationship USER_01 in client 001 <-> ACCOUNT_01
APPEND USER_ACCOUNT_RELATION.
"second relationship
USER_ACCOUNT_RELATION-BNAME = 'USER_02'.
"append new relationship USER_02 in client 001 <-> ACCOUNT_01
APPEND USER_ACCOUNT_RELATION.
"third relationship
USER_ACCOUNT_RELATION-BNAME = 'USER_03'.
USER_ACCOUNT_RELATION-ACCNT = 'ACCOUNT_02'.
"append new relationship USER_03 in client 001 <-> ACCOUNT_02
APPEND USER_ACCOUNT_RELATION.
* read the accounting data for the defined account
CALL FUNCTION 'SAPWL_ACCNT_GET_SYSTEM_USAGE'
EXPORTING
PERIODTYPE = 'D' "daily statistics
" HOSTID = "of all available servers
STARTDATE = SY-DATUM "from today
" CUMULATION_MODE = 'A' "cumulate data for accts
" CLIENT =
TABLES
STATISTIC = ACCOUNT_STATISTIC
USER_ACCOUNT_RELATION = USER_ACCOUNT_RELATION
EXCEPTIONS
UNKNOWN_PERIODTYPE = 01
UNKNOWN_CUMULATION_MODE = 02
WRONG_CLIENT_DESCRIPTION = 03
WRONG_STARTDATE = 04
NO_DATA_FOUND = 05.