* _______ _______ _______ _______ _______ _______ ______ _______ _______ ______ _______ * | _ | _ | _ | | | _ | || _ | _ | _ | | _ | * | |_| | |_| | |_| | _ | | |_| | _ | |_| | |_| | | || | |_| | * | | | | |_| | | | | | | | | |_||_| | * | | _ || | ___| _| | |_| | | _ || __ | | * | _ | |_| | _ | | | |_| _ | | _ | |_| | | | | _ | * |__| |__|_______|__| |__|___| |_______|__| |__|______||__| |__|_______|___| |_|__| |__| * www.abapcadabra.com * *------------------------------------------------------------------------------------------- * program : ZABAPCADABRA_BIG_BROTHER * title : Big Brother - who's in the house ? * functional area : Cross modules * environment : 4.7 * program Function : List the users on the system and focus on the sessions * they are working on. * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 19/04/2017 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 19/04/2017 Initial release * 03/10/2019 Support for WEBgui users, which don't show in table * USR41. Report reveals all activity for users that have * a last login date of today (on USR02). *--------------------------------------------------------------------- REPORT zabapcadabra_big_brother. TABLES: usr41. "Selection screen purpose only *--------------------------------------------------------------------- * S E L E C T I O N - S C R E E N *--------------------------------------------------------------------- SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(16) lbl_01 FOR FIELD so_bname. SELECT-OPTIONS so_bname FOR usr41-bname. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. PARAMETERS pa_timer AS CHECKBOX DEFAULT space. SELECTION-SCREEN COMMENT 3(60) lbl_02 FOR FIELD pa_timer. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(16) lbl_03 FOR FIELD pa_mins. PARAMETERS pa_mins type i default 120. SELECTION-SCREEN COMMENT 34(10) lbl_04. SELECTION-SCREEN END OF LINE. *----------------------------------------------------------------------* * CLASS lcl_event_manager DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_event_manager DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING r_object TYPE REF TO cl_salv_table, on_user_command FOR EVENT added_function OF cl_salv_events IMPORTING e_salv_function, on_link_click FOR EVENT link_click OF cl_salv_events_table IMPORTING row column. PRIVATE SECTION. DATA: go_salv TYPE REF TO cl_salv_table. ENDCLASS. "lcl_event_manager DEFINITION CLASS lcl_timer_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer IMPORTING sender. ENDCLASS. *----------------------------------------------------------------------* * CLASS lcl_big_brother DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_big_brother DEFINITION. PUBLIC SECTION. TYPES: BEGIN OF ty_report, bname TYPE usr41-bname, name_textc TYPE user_addr-name_textc, sm12_icon type icon-id, alert_icon type icon-id, server TYPE usr41-server, termid TYPE usr41-termid, sprache TYPE usr41-sprache, logon_date TYPE usr41-logon_date, logon_time TYPE usr41-logon_time, client TYPE uinfo2-client, "Mandant user TYPE uinfo2-user, "Gebruikersnaam terminal2 TYPE uinfo2-terminal, "Terminal-identificatie mode TYPE uinfo2-mode, "Externe modus session TYPE uinfo2-session, "Sessie van een gebruiker time TYPE t, "Laatste dialoogtijd van de modus lapse TYPE t, lang TYPE uinfo2-lang, "Aanmeldtaal tcode TYPE uinfo2-tcode, "Transactiecode ttext type tstct-ttext, terminal1 TYPE usr41-terminal, colors TYPE lvc_t_scol, END OF ty_report. CLASS-DATA: gr_bname TYPE RANGE OF usr41-bname, gv_correction_time type sy-uzeit, gv_correction_backwards type boolean, go_salv TYPE REF TO cl_salv_table, go_event_man TYPE REF TO lcl_event_manager, gt_report TYPE STANDARD TABLE OF ty_report, go_timer TYPE REF TO cl_gui_timer, go_timer_handler TYPE REF TO lcl_timer_handler. CLASS-METHODS: selection, prepare_alv, start_timer, popup_alert importing username type usr01-bname. ENDCLASS. "lcl_big_brother DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_manager IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_event_manager IMPLEMENTATION. METHOD constructor. DATA: lo_events TYPE REF TO cl_salv_events_table. go_salv = r_object. lo_events = go_salv->get_event( ). SET HANDLER on_user_command FOR lo_events. SET HANDLER on_link_click FOR lo_events. ENDMETHOD. "constructor METHOD on_user_command. data: lv_message type c length 100, lv_current_time type sy-uzeit. CASE e_salv_function. when 'REFRESH' or 'R'. lcl_big_brother=>selection( ). lcl_big_brother=>go_salv->refresh( exporting refresh_mode = IF_SALV_C_REFRESH=>FULL ). cl_gui_cfw=>flush( ). lv_current_time = sy-uzeit. if not lcl_big_brother=>gv_correction_time is initial. if lcl_big_brother=>gv_correction_backwards = abap_true. subtract lcl_big_brother=>gv_correction_time from lv_current_time. else. add lcl_big_brother=>gv_correction_time to lv_current_time. endif. endif. write lv_current_time to lv_message using edit mask '__:__:__'. concatenate 'Refreshed @' lv_message into lv_message SEPARATED BY space. message lv_message type 'S'. ENDCASE. ENDMETHOD. METHOD on_link_click. data: lw_reportline type lcl_big_brother=>ty_report, lt_bdcdata type standard table of bdcdata, lw_bdcdata type bdcdata. * bdc_add 'X' 'PROGRAM_NAME' 'SCREEN NUMBER'. * bdc_add ' ' 'FIELDNAME' 'FIELDVALUE'. define bdc_add. clear lw_bdcdata. lw_bdcdata-dynbegin = &1. if &1 eq 'X'. lw_bdcdata-program = &2. lw_bdcdata-dynpro = &3. else. lw_bdcdata-fnam = &2. lw_bdcdata-fval = &3. endif. append lw_bdcdata to lt_bdcdata. end-of-definition. read table lcl_big_brother=>gt_report index row into lw_reportline. if sy-subrc = 0. case column. when 'SM12_ICON'. clear lt_bdcdata. bdc_add: 'X' 'RSENQRR2' '1100', ' ' 'SEQG3-GUNAME' lw_reportline-bname. call transaction 'SM12' using lt_bdcdata mode 'E'. when 'ALERT_ICON'. lcl_big_brother=>popup_alert( lw_reportline-bname ). endcase. endif. ENDMETHOD. "on_link_click ENDCLASS. "lcl_event_manager IMPLEMENTATION CLASS lcl_timer_handler IMPLEMENTATION. METHOD: on_finished. sender->run( ). cl_gui_cfw=>set_new_ok_code( new_code = 'REFRESH' ). ENDMETHOD. "on_finished ENDCLASS. *----------------------------------------------------------------------* * CLASS lcl_big_brother IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_big_brother IMPLEMENTATION. METHOD selection. DATA: lt_usr02 TYPE STANDARD TABLE OF USR02, lw_usr02 TYPE USR02, lt_usr41 TYPE STANDARD TABLE OF usr41, lw_usr41 TYPE usr41, lt_user_addr TYPE STANDARD TABLE OF user_addr, lw_user_addr TYPE user_addr, lt_uinfo2 TYPE STANDARD TABLE OF uinfo2, lw_uinfo2 TYPE uinfo2, lt_tstct type standard table of tstct, lw_tstct type tstct, lw_report TYPE ty_report, lv_uname type sy-uname, lw_color_field type lvc_s_scol. field-symbols: type ty_report. clear: gt_report[]. SELECT * FROM usr02 INTO TABLE lt_usr02 WHERE trdat = sy-datum and ustyp = 'A' and "Dialog users only bname IN gr_bname. if sy-subrc = 0. SELECT * FROM user_addr INTO TABLE lt_user_addr FOR ALL ENTRIES IN lt_usr02 WHERE bname = lt_usr02-bname. SELECT * FROM usr41 INTO TABLE lt_usr41 WHERE bname IN gr_bname. get time. "Refresh the SY-UZEIT * Main LOOP: users that logged in today LOOP AT lt_usr02 INTO lw_usr02. READ TABLE lt_user_addr INTO lw_user_addr WITH KEY bname = lw_usr02-bname. IF sy-subrc <> 0. CLEAR lw_user_addr. ENDIF. CLEAR: lt_uinfo2[]. CALL FUNCTION 'TH_LONG_USR_INFO' EXPORTING user = lw_usr02-bname TABLES user_info = lt_uinfo2. READ TABLE lt_usr41 INTO lw_usr41 WITH KEY bname = lw_usr02-bname. * Compose ALV report output - with USR41 info: if sy-subrc = 0. clear lv_uname. LOOP AT lt_uinfo2 INTO lw_uinfo2. CLEAR: lw_report. MOVE-CORRESPONDING lw_usr02 TO lw_report. MOVE-CORRESPONDING lw_user_addr TO lw_report. check lw_usr41-terminal cs lw_uinfo2-terminal. MOVE-CORRESPONDING lw_usr41 TO lw_report. lw_report-terminal1 = lw_usr41-terminal. MOVE-CORRESPONDING lw_uinfo2 TO lw_report. lw_report-terminal2 = lw_uinfo2-terminal. lw_report-lapse = sy-uzeit - lw_report-time. * Set the color for the LAPSE field: lw_color_field-fname = 'LAPSE'. lw_color_field-color-int = 0. lw_color_field-color-inv = 0. * Transparent to red, (up to) 5 minutes, 10 minutes, 30 minutes, 1 hour and over 1 hour if lw_report-lapse between '000000' and '000500'. lw_color_field-color-col = 2. elseif lw_report-lapse between '000500' and '001000'. lw_color_field-color-col = 0. elseif lw_report-lapse between '001000' and '003000'. lw_color_field-color-col = 7. elseif lw_report-lapse between '003000' and '010000'. lw_color_field-color-col = 6. else. lw_color_field-color-int = 1. lw_color_field-color-col = 6. endif. append lw_color_field to lw_report-colors. if lv_uname <> lw_uinfo2-USER. lw_report-sm12_icon = '@M1@'. lw_report-alert_icon = '@5L@'. lv_uname = lw_uinfo2-USER. endif. APPEND lw_report TO gt_report. ENDLOOP. else. LOOP AT lt_uinfo2 INTO lw_uinfo2. CLEAR: lw_report. lw_report-terminal1 = |WebGUI (Not on USR41)|. lw_report-logon_date = lw_usr02-trdat. lw_report-logon_time = lw_usr02-ltime. MOVE-CORRESPONDING lw_usr02 TO lw_report. MOVE-CORRESPONDING lw_user_addr TO lw_report. MOVE-CORRESPONDING lw_uinfo2 TO lw_report. lw_report-terminal2 = lw_uinfo2-terminal. lw_report-lapse = sy-uzeit - lw_report-time. * Set the color for the LAPSE field: lw_color_field-fname = 'LAPSE'. lw_color_field-color-int = 0. lw_color_field-color-inv = 0. * Transparent to red, (up to) 5 minutes, 10 minutes, 30 minutes, 1 hour and over 1 hour if lw_report-lapse between '000000' and '000500'. lw_color_field-color-col = 2. elseif lw_report-lapse between '000500' and '001000'. lw_color_field-color-col = 0. elseif lw_report-lapse between '001000' and '003000'. lw_color_field-color-col = 7. elseif lw_report-lapse between '003000' and '010000'. lw_color_field-color-col = 6. else. lw_color_field-color-int = 1. lw_color_field-color-col = 6. endif. append lw_color_field to lw_report-colors. if lv_uname <> lw_uinfo2-USER. lw_report-sm12_icon = '@M1@'. lw_report-alert_icon = '@5L@'. lv_uname = lw_uinfo2-USER. endif. APPEND lw_report TO gt_report. ENDLOOP. endif. ENDLOOP. if not gt_report[] is initial. select * from tstct into table lt_tstct for all entries in gt_report where sprsl = sy-langu and tcode = gt_report-tcode. * Fetch transaction code descriptions * Apply the time-correction on all time fields: loop at gt_report assigning . read table lt_tstct into lw_tstct with key tcode = -tcode. if sy-subrc = 0. -ttext = lw_tstct-ttext. endif. if not gv_correction_time is initial. if gv_correction_backwards = abap_true. subtract gv_correction_time from -LOGON_TIME. subtract gv_correction_time from -TIME. else. add gv_correction_time to -LOGON_TIME. add gv_correction_time to -TIME. endif. endif. endloop. endif. ENDIF. ENDMETHOD. "selection METHOD prepare_alv. DATA: lo_columns_table TYPE REF TO cl_salv_columns_table, lw_color_field TYPE lvc_s_scol, lv_is_unavailable TYPE boolean, lw_report TYPE ty_report, lo_rf_display_settings TYPE REF TO cl_salv_display_settings, lo_rf_columns_table TYPE REF TO cl_salv_columns_table, lo_rf_functions_list TYPE REF TO cl_salv_functions_list, lo_rf_layout TYPE REF TO cl_salv_layout, lw_layout_key TYPE salv_s_layout_key, lo_rf_column_table TYPE REF TO cl_salv_column_table, lv_scrtext_s TYPE scrtext_s, lv_scrtext_m TYPE scrtext_m, lv_scrtext_l TYPE scrtext_l, lv_columnname TYPE lvc_fname, lo_rf_sorts type ref to CL_SALV_SORTS. DEFINE alv_field. try. lv_columnname = &1. lo_rf_column_table ?= lo_rf_columns_table->get_column( lv_columnname ). case &2. when 'HIDE'. lo_rf_column_table->set_visible( abap_false ). when 'ICON'. lv_scrtext_s = lv_scrtext_m = lv_scrtext_l = '____'. lo_rf_column_table->set_short_text( lv_scrtext_s ). lo_rf_column_table->set_medium_text( lv_scrtext_m ). lo_rf_column_table->set_long_text( lv_scrtext_l ). lo_rf_column_table->set_cell_type( if_salv_c_cell_type=>hotspot ). lo_rf_column_table->set_icon( abap_true ). when 'HOT'. lo_rf_column_table->set_cell_type( if_salv_c_cell_type=>hotspot ). when 'CHECKBOX'. lo_rf_column_table->set_cell_type( if_salv_c_cell_type=>checkbox ). when 'UNAVAILABLE'. lo_rf_column_table->set_technical( abap_true ). when others. "Anything else is the description of the column lv_scrtext_s = lv_scrtext_m = lv_scrtext_l = &2. lo_rf_column_table->set_short_text( lv_scrtext_s ). lo_rf_column_table->set_medium_text( lv_scrtext_m ). lo_rf_column_table->set_long_text( lv_scrtext_l ). endcase. catch cx_salv_not_found cx_salv_data_error. endtry. END-OF-DEFINITION. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = go_salv CHANGING t_table = gt_report ). CATCH cx_salv_msg. * The wrapper class does not raise the exception, to avoid having to * catch it. ENDTRY. lo_rf_display_settings = go_salv->get_display_settings( ). lo_rf_display_settings->set_striped_pattern( abap_false ). lo_rf_columns_table = go_salv->get_columns( ). lo_rf_columns_table->set_optimize( abap_true ). lo_rf_functions_list = go_salv->get_functions( ). lo_rf_functions_list->set_all( ). * Layout's are available for the end user to control lo_rf_layout = go_salv->get_layout( ). lw_layout_key-report = sy-cprog. lw_layout_key-logical_group = 'A69A'. * The key for layouts needs to be set to enable it's functionality. lo_rf_layout->set_key( lw_layout_key ). lo_rf_layout->set_default( abap_true ). lo_rf_layout->set_save_restriction( if_salv_c_layout=>restrict_user_dependant ). * Field specifics: alv_field: 'BNAME' 'User-ID', 'NAME_TEXTC' 'Name', 'TERMID' 'Terminal-ID', 'TERMID' 'HIDE', 'TERMINAL1' 'Terminal', 'SM12_ICON' 'ICON', 'ALERT_ICON' 'ICON', 'SERVER' 'Server', 'SERVER' 'HIDE', 'MODE' 'HIDE', 'SESSION' 'UNAVAILABLE', 'TERMINAL' 'Terminal', 'SPRACHE' 'Language', 'SPRACHE' 'HIDE', 'LOGON_DATE' 'Logon', 'LOGON_DATE' 'HIDE', 'LOGON_TIME' 'Logon', 'TERMINAL2' 'Terminal', 'TERMINAL2' 'HIDE', 'TIME' 'Since', 'LAPSE' 'Idle', 'LANG' 'Language', 'LANG' 'HIDE', 'USER' 'UNAVAILABLE'. * a bit of logic to inform the alv object which column is to be * used for color settings: TRY. lo_columns_table = go_salv->get_columns( ). lo_columns_table->set_color_column( value = 'COLORS' ). CATCH cx_salv_data_error. ENDTRY. lo_rf_sorts = go_salv->get_sorts( ). lo_rf_sorts->add_sort( columnname = 'BNAME' ). lo_rf_sorts->add_sort( columnname = 'NAME_TEXTC' ). lo_rf_sorts->add_sort( columnname = 'SPRACHE' ). lo_rf_sorts->add_sort( columnname = 'LOGON_DATE' ). lo_rf_sorts->add_sort( columnname = 'LOGON_TIME' ). lo_rf_sorts->add_sort( columnname = 'CLIENT' ). lo_rf_sorts->add_sort( columnname = 'TERMINAL1' ). CREATE OBJECT go_event_man EXPORTING r_object = go_salv. ENDMETHOD. "report_alv METHOD start_timer. * Create an instance of the Timer CREATE OBJECT go_timer. CREATE OBJECT go_timer_handler. * Set an event handler to capture the timer-signal SET HANDLER go_timer_handler->on_finished FOR go_timer. * Set the interval in seconds go_timer->interval = 29. * Start the times go_timer->run( ). ENDMETHOD. METHOD popup_alert. data: lt_SVAL type STANDARD TABLE OF SVAL, lw_SVAL type SVAL, lv_returncode type c, lv_message type SM04DIC-POPUPMSG. clear: lt_SVAL[], lw_SVAL. lw_SVAL-TABNAME = 'TLINE'. lw_SVAL-FIELDNAME = 'TDLINE'. lw_SVAL-FIELDTEXT = 'Message'. lw_SVAL-VALUE = 'Your message...'. append lw_SVAL to lt_SVAL. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING POPUP_TITLE = 'Hej you !' IMPORTING RETURNCODE = lv_returncode TABLES FIELDS = lt_SVAL EXCEPTIONS OTHERS = 0. IF LV_RETURNCODE IS INITIAL. read table lt_SVAL into lw_sval index 1. lv_message = lw_sval-value. CALL FUNCTION 'TH_POPUP' EXPORTING CLIENT = sy-mandt USER = username MESSAGE = lv_message EXCEPTIONS OTHERS = 0. ELSE. message 'No message sent' type 'S'. ENDIF. ENDMETHOD. ENDCLASS. "lcl_big_brother IMPLEMENTATION *--------------------------------------------------------------------- * I N I T I A L I Z A T I O N *--------------------------------------------------------------------- INITIALIZATION. * All texts for this report have been set up as hard-coded texts (no use * of the report text-pool). Reason: easy copying of report source code. lbl_01 = 'Userid'. lbl_02 = 'Automatically refresh every 30 seconds'. lbl_03 = 'Time correction'. lbl_04 = '(minutes)'. *--------------------------------------------------------------------- * S T A R T - O F - S E L E C T I O N *--------------------------------------------------------------------- START-OF-SELECTION. lcl_big_brother=>gr_bname[] = so_bname[]. lcl_big_brother=>gv_correction_time = abs( pa_mins ) * 60. if pa_mins < 0. lcl_big_brother=>gv_correction_backwards = abap_true. endif. lcl_big_brother=>selection( ). lcl_big_brother=>prepare_alv( ). if pa_timer = abap_true. lcl_big_brother=>start_timer( ). message 'Automatic refresh is active...' type 'S'. endif. lcl_big_brother=>go_salv->display( ).