SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Вisplays data from table SGOSHIST (Object History)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Objects
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Jan 26, 2008 4:55 pm    Post subject: Вisplays data from table SGOSHIST (Object History) Reply with quote

Code:
REPORT z_alv_object_history.
*---------------------------------------------------------------------*
* This report displays data from table SGOSHIST (Object History)      *
*---------------------------------------------------------------------*
* Author : Michel PIOUD - Updated 16-Nov-07                           *
* 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.

CONSTANTS :
  c_x VALUE 'X',
  c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------*
TYPE-POOLS slis.                       " ALV Global types

TYPES :
  BEGIN OF ty_data,
    sapname   TYPE sgoshist-sapname,    " SAP User name
    name_last TYPE addr3_val-name_last, " User name
    keyword   TYPE swotbasdat-keyword,  " Object type short text
    objkey    TYPE sgoshist-objkey,     " Object key
    objtype   TYPE sgoshist-objtype,    " Object type
    timestamp TYPE sgoshist-timestamp,  " Time stamp
    tcode     TYPE sgoshist-tcode,      " Transaction code
    ttext     TYPE tstct-ttext,         " Transaction text
  END OF ty_data.

DATA :
  g_bname      TYPE ust04-bname,        " Users
  gs_sgoshist  TYPE sgoshist,           " Object History
  gs_date      TYPE range_s_dats,
  gr_timestamp TYPE RANGE OF tzntstmps,
  gs_timestamp LIKE LINE OF gr_timestamp,
  gt_data      TYPE STANDARD TABLE OF ty_data.

*---------------------------------------------------------------------*
* Select-Options / Parameters
m_ligne 1 s_sapnam g_bname.                                 "#EC NEEDED
m_ligne 2 s_tcode  gs_sgoshist-tcode.                       "#EC NEEDED
m_ligne 3 s_objtyp gs_sgoshist-objtype.                     "#EC NEEDED
m_ligne 4 s_objkey gs_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.

*---------------------------------------------------------------------*
INITIALIZATION.

  PERFORM f_initialization.

*---------------------------------------------------------------------*
START-OF-SELECTION.

  LOOP AT s_date INTO gs_date.
    CLEAR gs_timestamp.
    gs_timestamp-sign   = gs_date-sign.
    gs_timestamp-option = gs_date-option.

    IF NOT gs_date-low IS INITIAL.
      CONVERT DATE gs_date-low  TIME '000000'
         INTO TIME STAMP gs_timestamp-low TIME ZONE sy-zonlo.
      IF gs_date-high EQ '00000000'.
        gs_timestamp-option = 'BT'.
        CONVERT DATE gs_date-low TIME '235959'
           INTO TIME STAMP gs_timestamp-high TIME ZONE sy-zonlo.
      ENDIF.
    ENDIF.

    IF NOT gs_date-high IS INITIAL.
      CONVERT DATE gs_date-high TIME '235959'
         INTO TIME STAMP gs_timestamp-high TIME ZONE sy-zonlo.
    ENDIF.

    APPEND gs_timestamp TO gr_timestamp.
  ENDLOOP.

  PERFORM f_read_data.

*---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*       Form  F_READ_DATA
*---------------------------------------------------------------------*
FORM f_read_data.

  DATA l_adresse TYPE addr3_val.

  FIELD-SYMBOLS <data> TYPE ty_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 gr_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
*---------------------------------------------------------------------*
*      Form  f_initialization
*---------------------------------------------------------------------*
FORM f_initialization .

  DATA:
    ls_sapnam LIKE LINE OF s_sapnam.

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

  gs_date-low  = sy-datum.
  gs_date-high = sy-datum.
  APPEND gs_date TO s_date.

  CONCATENATE 'IEQ' sy-uname INTO ls_sapnam.
  APPEND ls_sapnam TO s_sapnam.

ENDFORM.                    " f_initialization
************ END OF PROGRAM Z_ALV_OBJECT_HISTORY **********************
 
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Objects All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.