Monday, April 14, 2008

ALV - Details of Y/Z objects with lists of users/date/time/description during creation or change

A simple ALV - Details of Y/Z objects with lists of users/date/time/description during creation or change of the object.

*&---------------------------------------------------------------------*
*& 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
*&
*&---------------------------------------------------------------------*
REPORT z_object_tracker NO STANDARD PAGE HEADING.

*Type pools declaration for ALV.
TYPE-POOLS : slis.

*Structure declaration for TRDIR table
TYPES : BEGIN OF ty_trdir,
name(120), "Name of the the Y/Z program
cnam TYPE trdir-cnam, "Author

cdat TYPE trdir-cdat, "Created on
subc TYPE trdir-subc, "Program type
END OF ty_trdir.

*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 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.

* For grid title
DATA : txt1 TYPE string.

DATA : txt2 TYPE string.

DATA : txt3 TYPE string.
DATA : txt4 TYPE string.
DATA : titletext TYPE string.

* Selection screen
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
PARAMETERS : p_object LIKE wa_trdir-name.
SELECTION-SCREEN END OF BLOCK blk1.

*initialization event
INITIALIZATION.
txt1 = 'Object tracker for'.

txt3 = 'Type'.

*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.

*Select values from TRDIR

SELECT name cnam cdat subc FROM trdir INTO TABLE it_trdir
WHERE name EQ p_object AND ( name LIKE 'Z%' OR name LIKE 'Y%' ).

*Select values from CTS tables
IF sy-subrc IS INITIAL.
SELECT a~obj_name a~trkorr b~as4user b~as4date b~as4time c~as4text
INTO CORRESPONDING FIELDS OF TABLE it_output
FROM e071 AS a INNER JOIN e070 AS b
ON a~trkorr = b~trkorr
INNER JOIN e07t AS c

ON a~trkorr = c~trkorr

FOR ALL ENTRIES IN it_trdir
WHERE a~obj_name = it_trdir-name
AND c~langu = sy-langu AND

a~lockflag <> ' '.

ENDIF.

* Appending the selected values to our output internal table
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.

*FOR grid TITLE
TXT4 = wa_output-objTYPE.
txt2 = wa_output-obj_name.

CONCATENATE txt1 txt2 TXT3 TXT4 INTO titletext SEPARATED BY space.
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 = 'AS4DATE'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Date'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '2'.
lv_fldcat-fieldname = 'AS4TIME'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Time'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '3'.
lv_fldcat-fieldname = 'AS4USER'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Developer'.

APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '4'.
lv_fldcat-fieldname = 'AS4TEXT'.

lv_fldcat-tabname = 'IT_OUTPUT'.

lv_fldcat-outputlen = '20'.

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'.
it_layout-grid_title = titletext.
ENDFORM. "ALV_LAYOUT

Steps to be done for creation of a screen 0600 with custom container.

  1. Create the screen 0600 for the above program and place a custom container on the same.
  2. Create a Custom container and name it C_GRID and OK code as OK_CODE.
  3. Name the custom container C_GRID and give ok code as OK_CODE.
  4. In the Flow Logic enter a PBO Module as SET_GRID.
  5. Activate and Execute the Code.

No comments:

Blog Archive