REPORT z_alv_object_history.
*---------------------------------------------------------------------*
* This report displays data from table SGOSHIST (Object History) *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_ligne.
selection-screen :
begin of line, comment 10(20) v_&1 for field &2.
select-options &2 for &3.
selection-screen end of line.
END-OF-DEFINITION.
TYPE-POOLS slis. " ALV Global types
TABLES :
ust04, " Users
sgoshist. " Object History
* Select-Options / Parameters
m_ligne 1 s_sapnam ust04-bname. "#EC NEEDED
m_ligne 2 s_tcode sgoshist-tcode. "#EC NEEDED
m_ligne 3 s_objtyp sgoshist-objtype. "#EC NEEDED
m_ligne 4 s_objkey sgoshist-objkey. "#EC NEEDED
m_ligne 5 s_date sy-datum. "#EC NEEDED
SELECTION-SCREEN :
SKIP, BEGIN OF LINE, COMMENT 1(35) v_6 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(3) TYPE n DEFAULT '200' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
CONSTANTS :
c_x VALUE 'X',
c_refresh TYPE syucomm VALUE '&REFRESH'.
DATA :
BEGIN OF gt_data OCCURS 0,
sapname LIKE sgoshist-sapname, " SAP User name
name_last LIKE addr3_val-name_last, " User name
keyword LIKE swotbasdat-keyword, " Object type short text
objkey LIKE sgoshist-objkey, " Object key
objtype LIKE sgoshist-objtype, " Object type
timestamp LIKE sgoshist-timestamp, " Time stamp
tcode LIKE sgoshist-tcode, " Transaction code
ttext LIKE tstct-ttext, " Transaction text
END OF gt_data.
RANGES :
r_timestamp FOR sgoshist-timestamp.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'User name'.
v_2 = 'Transaction code'.
v_3 = 'Object type'.
v_4 = 'Object key'.
v_5 = 'Date'.
v_6 = 'Maximum number of selected entries'.
s_date-low = sy-datum.
s_date-high = sy-datum.
APPEND s_date.
CONCATENATE 'IEQ' sy-uname INTO s_sapnam.
APPEND s_sapnam.
*---------------------------------------------------------------------*
START-OF-SELECTION.
LOOP AT s_date.
CLEAR r_timestamp.
r_timestamp-sign = s_date-sign.
r_timestamp-option = s_date-option.
IF NOT s_date-low IS INITIAL.
CONVERT DATE s_date-low TIME '000000'
INTO TIME STAMP r_timestamp-low TIME ZONE sy-zonlo.
IF s_date-high EQ '00000000'.
r_timestamp-option = 'BT'.
CONVERT DATE s_date-low TIME '235959'
INTO TIME STAMP r_timestamp-high TIME ZONE sy-zonlo.
ENDIF.
ENDIF.
IF NOT s_date-high IS INITIAL.
CONVERT DATE s_date-high TIME '235959'
INTO TIME STAMP r_timestamp-high TIME ZONE sy-zonlo.
ENDIF.
APPEND r_timestamp.
ENDLOOP.
PERFORM f_read_data.
*---------------------------------------------------------------------*
END-OF-SELECTION.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form F_READ_DATA
*---------------------------------------------------------------------*
FORM f_read_data.
DATA l_adresse LIKE addr3_val.
FIELD-SYMBOLS <data> LIKE LINE OF gt_data.
* Read data from SGOSHIST
SELECT * UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM sgoshist
WHERE sapname IN s_sapnam
AND tcode IN s_tcode
AND objtype IN s_objtyp
AND objkey IN s_objkey
AND timestamp IN r_timestamp
ORDER BY TIMESTAMP descending.
* Sort to improve performance of FM SUSR_USER_ADDRESS_READ
SORT gt_data BY sapname.
LOOP AT gt_data ASSIGNING <data>.
* Get Object type short text
CALL FUNCTION 'SWO_TEXT_OBJTYPE'
EXPORTING
objtype = <data>-objtype
IMPORTING
keyword = <data>-keyword.
* Get user address data
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
user_name = <data>-sapname "#EC DOM_EQUAL
IMPORTING
user_address = l_adresse
EXCEPTIONS
user_address_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CONCATENATE l_adresse-name_last l_adresse-name_first
INTO <data>-name_last SEPARATED BY space.
ELSE.
<data>-name_last = <data>-sapname.
ENDIF.
* Read transaction code text
CALL FUNCTION 'BAL_DSP_TXT_ALTCODE_READ'
EXPORTING
i_tcode = <data>-tcode
IMPORTING
e_text = <data>-ttext.
ENDLOOP.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = &2.
ls_sort-down = &3.
ls_sort-group = &4.
append ls_sort to lt_sort.
END-OF-DEFINITION.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-no_out = &3.
ls_fieldcat-edit_mask = &4.
ls_fieldcat-no_sum = &5.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_layout TYPE slis_layout_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit,
ls_grid_settings TYPE lvc_s_glay.
ls_grid_settings-top_p_only = c_x.
ls_layout-colwidth_optimize = c_x.
ls_layout-zebra = c_x.
ls_layout-cell_merge = c_x.
* Build sort table
m_sort 'NAME_LAST' c_x '' 'UL'.
m_sort 'TIMESTAMP' '' c_x ''.
* Build field catalog table
m_fieldcat 'SAPNAME' 'SGOSHIST' c_x '' ''.
m_fieldcat 'NAME_LAST' 'ADDR3_VAL' '' '' ''.
m_fieldcat 'TIMESTAMP' 'SGOSHIST' '' '==TSTLC' c_x.
m_fieldcat 'TCODE' 'SGOSHIST' '' '' ''.
m_fieldcat 'TTEXT' 'TSTCT' '' '' ''.
m_fieldcat 'OBJKEY' 'SGOSHIST' '' '==ALPHA' ''.
m_fieldcat 'KEYWORD' 'SWOTBASDAT' '' '' ''.
m_fieldcat 'OBJTYPE' 'SGOSHIST' c_x '' ''.
* Activate refresh button
CLEAR ls_event_exit.
ls_event_exit-ucomm = c_refresh. " Refresh
ls_event_exit-after = c_x.
APPEND ls_event_exit TO lt_event_exit.
* Display data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_top_of_page = 'TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF_STATUS_SET'
is_layout = ls_layout
i_grid_settings = ls_grid_settings
it_fieldcat = lt_fieldcat
it_sort = lt_sort
it_event_exit = lt_event_exit
i_save = 'A'
TABLES
t_outtab = gt_data.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN c_refresh.
PERFORM f_read_data. " Refresh data
us_selfield-refresh = c_x.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* FORM PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED
* Display refresh button
DELETE ut_extab WHERE fcode = c_refresh.
SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.
ENDFORM. " PF_STATUS_SET
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM top_of_page. "#EC CALLED
ULINE.
WRITE : sy-title(65) CENTERED, 'Page :' , sy-pagno .
ULINE.
ENDFORM. " TOP_OF_PAGE
************ END OF PROGRAM Z_ALV_OBJECT_HISTORY **********************
유용하게 사용하겠습니다. 감사합니다^^