ALV report to track changes made to Y/Z programs

by Swarna S, Tata Consultancy Services

REPORT  Z_OBJECT_TRACKER                                     .
*&---------------------------------------------------------------------*
*& Report  Z_OBJECT_TRACKER                                            *
*& Author :Swarna.S.
*&---------------------------------------------------------------------*
*&
*& AS:
*& Simple ALV report -- Details of Y or Z objects
*& showing lists of all the users , date ,time and description for creation
*& or changes done on it
*&
*&---------------------------------------------------------------------*
*Type pools declaration for ALV.
TYPE-POOLS : slis.
*Structure declaration for TRDIR table
TYPES : BEGIN OF ty_trdir,
        name(120),
        cnam TYPE trdir-cnam,
        cdat TYPE trdir-cdat,
        subc TYPE trdir-subc,
        END OF ty_trdir.
*Structure declaration for E071
TYPES : BEGIN of ty_e071,
        obj_name type e071-obj_name,
        trkorr type e071-trkorr,
        END Of ty_e071.
*Structure declaration for E070
types : begin of ty_e070,
        trkorr type e070-trkorr,
        as4user type e070-as4user,
        as4date TYPE e070-as4date,     "date
        as4time TYPE e070-as4time,     "time
        end of ty_e070.
*Structure declaration for E07t
types : begin of ty_e07t,
        trkorr type e07t-trkorr,
        as4text type e07t-as4text,
        end of ty_e07t.
*Structure declaration for the output in ALV fomrat
TYPES : BEGIN OF ty_output,
        obj_name TYPE e071-obj_name,   "Object Name(Y/Z)
        trkorr  TYPE  e071-trkorr,     "Transport Request
        objtype(20) TYPE c,            "object type
        as4user TYPE e070-as4user,     "User name
        as4date TYPE e070-as4date,     "date
        as4time TYPE e070-as4time,     "time
        as4text TYPE e07t-as4text,     "Short Text Describing R/3 Repository Objects
        END OF ty_output.
*Internal table and work area declarations
*Declaration for TRDIR table
DATA : it_trdir TYPE STANDARD TABLE OF ty_trdir,
       wa_trdir TYPE ty_trdir.
*Declaration for E071
DATA : it_e071 TYPE STANDARD TABLE OF ty_e071,
       wa_e071 TYPE ty_e071.
*Declaration for E07t
DATA : it_e07t TYPE STANDARD TABLE OF ty_e07t,
       wa_e07t TYPE ty_e07t.
*Declaration for e070
DATA : it_e070 TYPE STANDARD TABLE OF ty_e070,
       wa_e070 TYPE ty_e070.
*Declaration for output table
DATA : it_output TYPE STANDARD TABLE OF ty_output,
       wa_output TYPE ty_output.
*DATA Declarations for ALV grid
DATA: c_ccont TYPE REF TO cl_gui_custom_container,
      c_alvgd         TYPE REF TO cl_gui_alv_grid,
      it_fcat            TYPE lvc_t_fcat,
      it_layout          TYPE lvc_s_layo.
* Selection screen
*here we are not defining the intervals from and to but can list several object names 
*one by one. For performance that system need not scan completely but individually 
* fetch details for every object mentioned
SELECTION-SCREEN  BEGIN OF BLOCK blk1 WITH FRAME.
select-options : s_object for wa_trdir-name  no intervals.
SELECTION-SCREEN  END OF BLOCK blk1.
*initialization event
INITIALIZATION.

*Start of selection event
START-OF-SELECTION.
*Subroutine to get the user name/date/time
  PERFORM get_object_details.
*Subroutine to print alv output
  PERFORM alv_output.
*End of selection event
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  alv_output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alv_output.
*Call the ALV screen with custom container
  CALL SCREEN '0600'.
ENDFORM.                    " alv_output
*On this statement double click  it takes you to the screen painter SE51.Enter 
*the attributes. Create a Custom container and name it C_GRID and OK code as OK_CODE.
*Save check and Activate the scren painter.
*NOw a normal screen witn number 600 is created which holds the ALV grid.
* PBO of the actual screen , Here we can give a title and customized menus
*&---------------------------------------------------------------------*
*&      Module  STATUS_0600  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0600 OUTPUT.
*  SET TITLEBAR 'XXXX'.
*
*  SET PF-STATUS 'XXXXXXX'.
ENDMODULE.                 " STATUS_0600  OUTPUT
* calling the PBO module SET_GRID.
*&---------------------------------------------------------------------*
*&      Module  SET_GRID  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_grid OUTPUT.
* Create object for custom container
  CREATE OBJECT c_ccont
       EXPORTING
          container_name = 'C_GRID'.
* Create object for ALV grid
  CREATE OBJECT c_alvgd
      EXPORTING
        i_parent = c_ccont.
* Set field for ALV
  PERFORM alv_fieldcat.
* Set ALV attributes FOR LAYOUT
  PERFORM alv_layout.
  CHECK NOT c_alvgd IS INITIAL.
* Call ALV GRID
  CALL METHOD c_alvgd->set_table_for_first_display
    EXPORTING
      is_layout                     = it_layout
    CHANGING
      it_outtab                     = it_output
      it_fieldcatalog               = it_fcat
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDMODULE.                 " SET_GRID  OUTPUT
* PAI module of the screen created. In case we use an interactive ALV or
*for additional functionalities we can create OK codes and based on the user command
*we can do the coding.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0600  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0600 INPUT.
ENDMODULE.                 " USER_COMMAND_0600  INPUT
*&---------------------------------------------------------------------*
*&      Form  get_object_details
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  Subroutine to fetch the details of the object through the necessary
*  selections in the database.
*
*----------------------------------------------------------------------*
FORM get_object_details.
*Selections from DATABASE
  SELECT name cnam cdat subc FROM trdir INTO TABLE it_trdir
  WHERE name in s_object AND
  ( name LIKE 'Z%'  OR name LIKE 'Y%' ).
if it_trdir[] is not initial.
select obj_name trkorr from e071 into corresponding fields of table it_e071
for all entries in it_trdir where obj_name eq it_trdir-name and lockflag <> ' '.
endif.
if it_e071[] is not initial.
select trkorr as4user as4date as4time from e070 into corresponding fields of table it_e070
for all entries in it_e071 where trkorr eq it_e071-trkorr.
endif.
if it_e070[] is not initial.
select trkorr as4text from e07t into corresponding fields of table it_e07t 
for all entries in it_e070
where trkorr eq it_e070-trkorr and langu = sy-langu.
endif.
*Appending selected values into the output table
loop at it_e071 into wa_e071.
wa_output-obj_name = wa_e071-obj_name.
wa_output-trkorr = wa_e071-trkorr.
read table it_e070 into wa_e070 with key trkorr = wa_e071-trkorr.
wa_output-as4user = wa_e070-as4user.
wa_output-as4time = wa_e070-as4time.
wa_output-as4date = wa_e070-as4date.
READ table it_e07t into wa_e07t with key trkorr = wa_e070-trkorr.
wa_output-as4text = wa_e07t-as4text.
append wa_output to it_output.
clear wa_output.
endloop.
* Values for object type
  LOOP AT it_output INTO wa_output.
    AT NEW obj_name.
      READ TABLE it_trdir INTO wa_trdir WITH KEY name = wa_output-obj_name.
      CASE wa_trdir-subc.
        WHEN '1'.
          wa_output-objtype = 'Executable Program'.
        WHEN 'I'.
          wa_output-objtype = 'Include Program'.
        WHEN 'M'.
          wa_output-objtype = 'Module Pool'.
        WHEN 'F'.
          wa_output-objtype = 'Function group'.
        WHEN 'S'.
          wa_output-objtype = 'Subroutine Pool'.
        WHEN 'J'.
          wa_output-objtype = 'Interface'.
        WHEN 'K'.
          wa_output-objtype = 'Class'.
      ENDCASE.
      MODIFY it_output FROM wa_output
      TRANSPORTING objtype
      WHERE obj_name EQ wa_output-obj_name.
      CLEAR : wa_output , wa_trdir.
    ENDAT.
  ENDLOOP.
  SORT it_output BY obj_name as4date as4time.
ENDFORM.                    "get_object_details
*&--------------------------------------------------------------------*
*&      Form  alv_fieldcat
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM alv_fieldcat.
  DATA lv_fldcat TYPE lvc_s_fcat.
  CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '1'.
  lv_fldcat-fieldname = 'OBJ_NAME'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 25.
  lv_fldcat-scrtext_m = 'ObjectName'.
  APPEND lv_fldcat TO it_fcat.
 CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '2'.
  lv_fldcat-fieldname = 'OBJTYPE'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 20.
  lv_fldcat-scrtext_m = 'Object type'.
  APPEND lv_fldcat TO it_fcat.
  CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '2'.
  lv_fldcat-fieldname = 'AS4DATE'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 12.
  lv_fldcat-scrtext_m = 'Date'.
  APPEND lv_fldcat TO it_fcat.
  CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '3'.
  lv_fldcat-fieldname = 'AS4TIME'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 12.
  lv_fldcat-scrtext_m = 'Time'.
  APPEND lv_fldcat TO it_fcat.
  CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '4'.
  lv_fldcat-fieldname = 'AS4USER'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 10.
  lv_fldcat-scrtext_m = 'Developer'.
  APPEND lv_fldcat TO it_fcat.
  CLEAR lv_fldcat.
  lv_fldcat-row_pos   = '1'.
  lv_fldcat-col_pos   = '5'.
  lv_fldcat-fieldname = 'AS4TEXT'.
  lv_fldcat-tabname   = 'IT_OUTPUT'.
  lv_fldcat-outputlen = 40.
  lv_fldcat-scrtext_m = 'Object Desc'.
  APPEND lv_fldcat TO it_fcat.
  CLEAR lv_fldcat.
ENDFORM.                    "ALV_FIELDCAT
*&--------------------------------------------------------------------*
*&      Form  alv_layout
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM alv_layout.
  it_layout-cwidth_opt = 'X'.
  it_layout-zebra = 'X'.
ENDFORM.                    "ALV_LAYOUT

Create the screen 0600 for the above program and place a custom container on the same:

 

Create a Custom container and name it C_GRID and OK code as OK_CODE. 

Name the custom container C_GRID and give ok code as OK_CODE. 

 

Also in the Flow Logic enter a PBO Module as SET_GRID.

 

Activate and Execute the Code. 

Selection screen for entering the Y/Z Object name.

 

 

Execute . 

ALV output.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image