Anda di halaman 1dari 10

Finding the list of all Transactions and Reports executed in an instance

Introduction I hope this wiki will be useful when the customer go for upgrade project. Once the customer has upgraded their system, they want to check whether the transactions and reports which were executed frequently in the old system are now working properly in the upgraded system. In that case, the Abaper might be in need of developing a customized report in the old system to find out the list of all transactions and reports executed in the system for the latest period.

Steps Involved The following report will be used to display the list of transactions and reports executed by each user in the given instance for the given year. It will also specify the module to which the report belong to., along with the dialog steps. The steps involved in getting the report is as follows: o The selection screen contains Object selection, Year selection, Instance selection In the object selection, the user has to select whether they want to get both standard and custom reports or only the customized reports and transactions. Then the user has to enter the year for which we need to get the report. That is, the report will fetch the transactions and reports executed in each of the month of the given year. Then in the instance selection, the user has to specify whether the report has to be retrieved only from the instance of the current host or from all the instances of the current host. The process of the report proceeds as follows: Collect the first date of each of the 12 months of the given year in an internal table. Then find the instance name of the current host from TPFID table. If the user wants to select the data from all the instances, then hard code the instance name as 'TOTAL'. Retrieve the workload user statistics for each of the 12 month from the found instance using 'SAPWL_WORKLOAD_GET_STATISTIC' BAPI. Pass the instance name, period type as 'M' and pass the first date of the month. It will return the application statistic in an internal table. From this statistic, retrieve the 'Dialog' task type details. If the user wants to view only the customized reports and transactions, then filter only the entries which start with either 'Y' or 'Z'. Based on the last character of the entry ID, we can decide whether it is a report or transaction. The application statistic internal table will also return the user who executed the object and also the dialog steps of that particular object. Collect all these details in an internal table. Then retrieve the title text of the report from TRDIRT table. If the object is a transaction, then retrieve the program name associated with the transaction from TSTC table and retrieve the title text of the transaction from TSTCT table.

Then retrieve the application type (module) of the report from TRDIR table. Then retrieve the long text of the module from TAPLT table. Then collect all these details in the final internal table. Then sort the final internal table based on the object type (Transactions and Reports). Then form the field catalog and display the final internal table in ALV output format using 'REUSE_ALV_GRID_DISPLAY' function module.

REPORT:
*&---------------------------------------------------------------------* *& Report ZLAST_EXECUTION *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZLAST_EXECUTION. ************************** Coding ************************************** ****** Type Pool Declaration for ALV Report ****** TYPE-POOLS: slis. ****************************************************** ************ Structure Declaration *************** ************ Structure for ALV output table ****** TYPES: BEGIN OF ty_usertcode, user TYPE sapwlutacc, v_id(10), tcode TYPE tcode, report TYPE program_id, prog type program_id, Des type trdirt-text, KTEXT type TAPLt-atext, count TYPE i, END OF ty_usertcode. *** Structure for collecting the first date of each month of the given year ** types: begin of ty_year, date type sy-datum, end of ty_year. *********** Structure for collecting the title text of Report ******

types: begin of ty_trdirt, name type trdirt-name, text type trdirt-text, end of ty_trdirt. * Structure for identifying the program name associated with the transaction * and the title text of the transaction ** types: begin of ty_tstc, tcode type tstc-tcode, pgmna type tstc-pgmna, ttext type tstct-ttext, end of ty_tstc. ****************************************************** ********* Internal tables and Work area declaration ******* DATA: it_usertcode TYPE STANDARD TABLE OF sapwlustcx, wa_usertcode TYPE sapwlustcx, it_result TYPE STANDARD TABLE OF ty_usertcode, wa_result TYPE ty_usertcode, it_final TYPE STANDARD TABLE OF ty_usertcode, wa_final type ty_usertcode, it_year type standard table of ty_year, wa_year type ty_year, it_trdirt type STANDARD TABLE OF ty_trdirt, wa_trdirt type ty_trdirt, it_tstc type STANDARD TABLE OF ty_tstc, wa_tstc type ty_tstc. *************************************************************** ********* Internal table declaration for ALV **************** DATA: it_field_catalog TYPE slis_t_fieldcat_alv WITH HEADER LINE, it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE. ***************************************************************** **************** Data Declaration *************************** DATA: v_pos TYPE i, v_appl type TAPLP-APPL, v_ktext type TAPLt-atext,

v_host type SY-HOST, v_apserver type TPFID-APSERVER, v_name type SAPWLSERV-NAME, v_name1 type SAPWLSERV-NAME, month TYPE dats, wa_prog_name type PROGRAM_ID. ***************************************************************** *************** Selection Screen **************************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-003. ************* Object selection (Standard/Custom) ************ SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004. PARAMETERS: p_all radiobutton group g2. PARAMETERS: p_custom radiobutton group g2. SELECTION-SCREEN END OF BLOCK b4. ***************************************************************** ************* Year selection ******************************** SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001. PARAMETER: year(4) type C obligatory default '2010'. SELECTION-SCREEN END OF BLOCK b2. ***************************************************************** ************* Instance selection **************************** SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-002. PARAMETERS: p_appl radiobutton group g1. PARAMETERS: p_total radiobutton group g1. SELECTION-SCREEN END OF BLOCK b3. ***************************************************************** SELECTION-SCREEN END OF BLOCK b1. ***************************************************************** **************** Start of Selection Event ******************* START-OF-SELECTION. *** Calling a subroutine to collect the first date of each month PERFORM MONTH TABLES IT_YEAR USING YEAR. ****************** Finding the instance name

*** Retrieving the current host name v_host = sy-host. *** Retrieving the instance name of the current host clear : v_apserver. select single APSERVER from tpfid into v_apserver where host = v_host. v_name1 = v_apserver. *** Hard code the instance name as 'TOTAL' if the user selected the instance * as 'TOTAL' in the selection screen if p_total = 'X'. v_name = 'TOTAL'. elseif p_appl = 'X'. v_name = v_name1. endif. ** Finding all transactions and reports executed in the given year ********* clear : wa_year. loop at it_year into wa_year. *** Retrieving the workload user statistics for each month CALL FUNCTION 'SAPWL_WORKLOAD_GET_STATISTIC' EXPORTING periodtype = 'M' startdate = wa_year-date instance = v_name TABLES application_statistic = it_usertcode EXCEPTIONS unknown_periodtype = 1 no_data_found =2 no_server_given =3 OTHERS = 4. if p_all = 'X'. *** Retrieving the 'Dialog' (Reports and Transactions) task type details (Both * standard and custom objects) clear : wa_usertcode, wa_result. LOOP AT it_usertcode INTO wa_usertcode where ttype = 1. *** Retrieving the user who executed the object wa_result-user = wa_usertcode-account. *** Checking if the Object is a Transaction or a Report IF wa_usertcode-entry_id+72 = 'T'. wa_result-v_id = 'TCODE'.

wa_result-tcode = wa_usertcode-entry_id. ELSE. wa_result-v_id = 'REPORT'. wa_result-report = wa_usertcode-entry_id. ENDIF. *** Retrieving the dialog count of the object execution wa_result-count = wa_usertcode-DCOUNT. collect wa_result INTO it_result. clear : wa_usertcode, wa_result. ENDLOOP. elseif p_custom = 'X'. *** Retrieving the 'Dialog' (Reports and Transactions) task type details (Only * Custom objects (Y and Z)) clear : wa_usertcode, wa_result. LOOP AT it_usertcode INTO wa_usertcode where ttype = 1 and ( entry_id CP 'Y*' or entry_id CP 'Z*' ). *** Retrieving the user who executed the object wa_result-user = wa_usertcode-account. *** Checking if the Object is a Transaction or Report IF wa_usertcode-entry_id+72 = 'T'. wa_result-v_id = 'TCODE'. wa_result-tcode = wa_usertcode-entry_id. ELSE. wa_result-v_id = 'REPORT'. wa_result-report = wa_usertcode-entry_id. ENDIF. *** Retrieving the dialog count of the object execution wa_result-count = wa_usertcode-DCOUNT. collect wa_result INTO it_result. clear : wa_usertcode, wa_result. ENDLOOP. endif. refresh it_usertcode. clear : wa_year.

endloop. *** Retrieving the title text of Report if not it_result[] is initial. refresh : it_trdirt. select name text from trdirt into table it_trdirt for all entries in it_result where name = it_result-report and sprsl = 'E'. endif. *** Identifying the program name associated with the transaction and the title * text of the Transaction if not it_result[] is initial. refresh : it_tstc. select a~tcode a~pgmna b~ttext into table it_tstc from tstc as a inner join tstct as b on a~tcode = b~tcode for all entries in it_result where a~tcode = it_result-tcode and b~sprsl = 'E'. endif. *** Appending all the details into the internal table CLEAR : wa_result, wa_final, wa_prog_name, wa_trdirt, v_appl, v_ktext, wa_tstc. loop at it_result into wa_result. wa_final-user = wa_result-user. wa_final-v_id = wa_result-v_id. wa_final-count = wa_result-count. if wa_result-v_id = 'REPORT'. wa_final-report = wa_result-report. *** Moving the program title text into the internal table read table it_trdirt into wa_trdirt with key name = wa_result-report. if sy-subrc = 0. wa_final-des = wa_trdirt-text. endif. wa_prog_name = wa_result-report. ELSEIF wa_result-v_id = 'TCODE'. wa_final-report = wa_result-tcode. *** Finding the program name associated with the transaction and its text and * moving them into the internal table

read table it_tstc into wa_tstc with key tcode = wa_result-tcode. if sy-subrc = 0. wa_final-prog = wa_tstc-pgmna. wa_final-des = wa_tstc-ttext. endif. wa_prog_name = wa_tstc-pgmna. endif. *** Retrieving the application type (Module) of the Report select single appl from trdir into v_appl where name = wa_prog_name. *** Retrieving the long text of the module if not v_appl is initial. select single atext from taplt into v_ktext where appl = v_appl and sprsl = 'E'. endif. wa_final-ktext = v_ktext. append wa_final to it_final. clear: wa_result, wa_final, v_appl, v_ktext, wa_trdirt, wa_prog_name, wa_tstc. endloop. *** Sorting the internal table SORT it_final BY report descending. *** Calling a subroutine for forming field catalog PERFORM field_catalog TABLES it_field_catalog USING: 'IT_FINAL' 'USER' ' ' v_pos 'User Id' '20' '', 'IT_FINAL' 'V_ID' ' ' v_pos 'Object' '' '', 'IT_FINAL' 'REPORT' ' ' v_pos 'Object Name' '40' '', 'IT_FINAL' 'PROG' ' ' v_pos 'TCODE Program Name' '40' '', 'IT_FINAL' 'DES' ' ' v_pos 'Object Description' '50' '', 'IT_FINAL' 'KTEXT' ' ' v_pos 'Module' '30' '', 'IT_FINAL' 'COUNT' ' ' v_pos 'Dialog steps' '15' 'X'. *** Calling a subroutine for sorting the ALV output PERFORM sort. *** Displaying the output table in ALV format if not it_final[] is initial.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid it_fieldcat = it_field_catalog[] it_sort = it_sort[] TABLES t_outtab = it_final EXCEPTIONS program_error =1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. else. write:/ 'No Record Found for the year', year. Endif.

*&------------------------------------------------------------------------* *& Subroutine for collecting the first date of each month *&------------------------------------------------------------------------* FORM MONTH TABLES P_IT_YEAR STRUCTURE wa_YEAR USING P_YEAR. data : cha(2) type c value '1'. while cha le 12. if cha le 9. concatenate p_year '0' cha '01' into p_it_year-date. else. concatenate p_year cha '01' into p_it_year-date. endif. cha = cha + 1. append p_it_year. clear p_it_year. endwhile. ENDFORM. " month *&---------------------------------------------------------------------* *& Subroutine for forming the field catalog for ALV output *&---------------------------------------------------------------------*

FORM field_catalog TABLES I_FIELD_CATALOG STRUCTURE it_field_catalog USING v_tabname TYPE any v_fieldname TYPE any v_key TYPE any v_pos TYPE any v_text TYPE any v_len TYPE any v_sum TYPE any. CLEAR i_field_catalog. i_field_catalog-tabname = v_tabname. i_field_catalog-fieldname = v_fieldname. i_field_catalog-key = v_key. i_field_catalog-col_pos = v_pos. i_field_catalog-seltext_l = v_text. i_field_catalog-outputlen = v_len. i_field_catalog-do_sum = v_sum. APPEND i_field_catalog. v_pos = v_pos + 1. ENDFORM. "field_catalog

*&---------------------------------------------------------------------------* *& Subroutine for sorting the ALV output based on the object type (Transaction/Report) *&---------------------------------------------------------------------------* FORM sort. clear it_sort. it_sort-fieldname = 'V_ID' . it_sort-down = 'X' . it_sort-subtot = 'X'. append it_sort. ENDFORM. "sort

******************************************************************************

Anda mungkin juga menyukai