Google Search - Blog...........

ABAP - Sample Prgarm To Fetch List Of ZReports Used In A Month

Have you ever asked the question "Who uses all these Z* reports? Are they used at all by anyone?"
Well, this small program may answer this question. You can implement this in NetWeaver 2004s (SAP_BASIS 700) and following releases. If you execute this program you have to specify a month (by specifying a day). The program will then print out a list of Z* report names together with the number of users using this report during the given month.
The interesting part is of course the function SWNC_COLLECTOR_GET_AGGREGATES, which reads aggregated data from the DB. It is the same data that is used in the Tcode profile of ST03N.
*&---------------------------------------------------------------------*
*& Report Z_REPORT_USAGE
*&
*&---------------------------------------------------------------------*
*& List all Z* reports executed during a month.
*& Show the number of users executing a particular report.
*&---------------------------------------------------------------------*

REPORT z_report_usage.
PARAMETER: month TYPE dats DEFAULT sy-datum.

TYPES: BEGIN OF zusertcode,
date TYPE swncdatum,
user TYPE swncuname,
mandt TYPE swncmandt,
tcode TYPE swnctcode,
report TYPE swncreportname,
count TYPE swncshcnt,
END OF zusertcode.

DATA: t_usertcode TYPE swnc_t_aggusertcode,
wa_usertcode TYPE swncaggusertcode,
wa TYPE zusertcode,
t_ut TYPE STANDARD TABLE OF zusertcode,
wa_result TYPE zusertcode,
t_result TYPE STANDARD TABLE OF zusertcode.

START-OF-SELECTION.

* Set date to the first day of the month
month+6(2) = '01'.

CALL FUNCTION 'SWNC_COLLECTOR_GET_AGGREGATES'
EXPORTING
component = 'TOTAL'
periodtype = 'M'
periodstrt = month
TABLES
usertcode = t_usertcode
EXCEPTIONS
no_data_found = 1
OTHERS = 2.

wa-date = month.
wa-mandt = sy-mandt.

LOOP AT t_usertcode INTO wa_usertcode.
wa-user = wa_usertcode-account.

* Activate the following line for SAP_BASIS 710
* wa-mandt = wa_usertcode-mandt.

IF wa_usertcode-entry_id+72 = 'T'.
wa-tcode = wa_usertcode-entry_id.
wa-report = space.
ELSE.
wa-tcode = space.
wa-report = wa_usertcode-entry_id.
ENDIF.
COLLECT wa INTO t_ut.
ENDLOOP.

SORT t_ut BY report ASCENDING.
CLEAR: wa, wa_result.


LOOP AT t_ut INTO wa WHERE report IS NOT INITIAL.
IF wa-report NE wa_result-report.
* new report detected; store previous report
IF wa_result-report IS NOT INITIAL.
wa_result-date = month.
APPEND wa_result TO t_result.
CLEAR wa_result.
ENDIF.
* initialize new report
wa_result-count = 1.
wa_result-report = wa-report.
ELSE.
* same report; just count it.
ADD 1 TO wa_result-count.
ENDIF.
ENDLOOP.

* Print to screen
SORT t_result BY count DESCENDING.

LOOP AT t_result INTO wa_result WHERE report CP 'Z*'.
WRITE:/ wa_result-report, wa_result-count.
ENDLOOP.
WRITE: / 'Ready.'.

No comments:

Post a Comment