*&---------------------------------------------------------------------*
*& Report YMSG_RANDY
*&
*&---------------------------------------------------------------------*
*& Copy right Randy Teh 2015July15
*& To have customized table to store chat log
*& Can view the last message history
*&---------------------------------------------------------------------*
REPORT YMSG_RANDY.
TABLES: ztab_randy.
TABLES: sscrfields.
*----------------------------------------------------------------------*
* Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
DATA: t_data TYPE STANDARD TABLE OF ztab_randy.
METHODS:
get_data,
generate_output.
ENDCLASS. "lcl_report DEFINITION
*----------------------------------------------------------------------*
* Local class for events
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.
ENDCLASS. "lcl_report DEFINITION
TYPES: BEGIN OF y_ztab_randy,
mandt TYPE mandt, "primary
UNAME TYPE SYUNAME, "primary
send_time TYPE SYUZEIT, "primary
send_date TYPE SYDATUM, "primary
chatid TYPE char10,
send_msg TYPE text255,
END OF y_ztab_randy.
TYPE-POOLS: icon.
DATA: wa_ztab TYPE y_ztab_randy,
cl_columns TYPE REF TO cl_salv_columns_table,
cl_column TYPE REF TO cl_salv_column_table,
cl_not_found TYPE REF TO cx_salv_not_found.
DATA: lo_report TYPE REF TO lcl_report.
DATA: gr_events TYPE REF TO cl_salv_events_table.
DATA: event_handler TYPE REF TO lcl_handle_events.
DATA: lo_dock TYPE REF TO cl_gui_docking_container,
lo_cont TYPE REF TO cl_gui_container,
lo_alv TYPE REF TO cl_salv_table.
PARAMETERS : CLIENT LIKE SY-MANDT.
PARAMETERS : USER LIKE SY-UNAME OBLIGATORY.
PARAMETERS : CHATID TYPE CHAR10.
PARAMETERS : MESSAGE LIKE SM04DIC-POPUPMSG LOWER CASE.
PARAMETERS : MSG_LEN LIKE SY-INDEX."MESSAGE_LEN LIKE SY-INDEX.
PARAMETERS : CUT_BLKS LIKE SY-LANGU."CUT_BLANKS LIKE SY-LANGU.
SELECTION-SCREEN BEGIN OF LINE.
* Add buttons to application toolbar
SELECTION-SCREEN FUNCTION KEY 1. "Will have a function code of 'FC01'
SELECTION-SCREEN FUNCTION KEY 2. "Will have a function code of 'FC01'
SELECTION-SCREEN END OF LINE.
PARAMETER: p_ucomm LIKE sy-ucomm NO-DISPLAY.
INITIALIZATION.
* Add displayed text string to buttons
MOVE 'REFRESH' TO sscrfields-functxt_01.
MOVE 'song' TO sscrfields-functxt_02.
CLIENT = SY-MANDT.
USER = SY-UNAME.
MSG_LEN = SY-INDEX."MESSAGE_LEN LIKE SY-INDEX.
CUT_BLKS = SY-LANGU."CUT_BLANKS LIKE SY-LANGU.
CREATE OBJECT lo_report.
* generate output
lo_report->get_data( ).
lo_report->generate_output( ).
DATA: wa_usr41 TYPE usr41.
SELECT * FROM USR41 CLIENT SPECIFIED INTO wa_usr41.
ENDSELECT.
AT SELECTION-SCREEN.
* Check if button have been selected or not
IF sscrfields-ucomm EQ 'FC01'.
p_ucomm = 'BUTN1'.
ELSEIF sscrfields-ucomm EQ 'FC02'.
p_ucomm = 'BUTN2'.
ELSE.
CLEAR p_ucomm.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
IF p_ucomm = 'BUTN1'.
MESSAGE 'cant refresh' TYPE 'I' DISPLAY LIKE 'I'.
LEAVE TO TRANSACTION 'YMSG'.
ELSEIF p_ucomm = 'BUTN2'.
MESSAGE 'SONG LAH' TYPE 'I' DISPLAY LIKE 'I'.
ENDIF.
at selection-screen on value-request for USER.
PERFORM F_SEARCHHELP.
START-OF-SELECTION.
PERFORM f_collect_data.
TRANSLATE chatid TO UPPER CASE.
IF chatid eq 'DELETE123'.
DELETE FROM ztab_randy.
lo_report->GET_DATA( ).
ELSE.
CALL FUNCTION 'TH_POPUP'
EXPORTING
CLIENT = CLIENT
USER = USER
MESSAGE = MESSAGE
* MESSAGE_LEN = 0
* CUT_BLANKS = ' '
* EXCEPTIONS
* USER_NOT_FOUND = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
TRANSLATE wa_ztab-uname TO UPPER CASE.
IF wa_ztab-chatid <> 'JUNIOR ZAI' .
wa_ztab-chatid = text-001.
ENDIF.
INSERT INTO ztab_randy VALUES wa_ztab.
lo_report->get_data( ).
ENDIF.
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form F_COLELCT_DATA
*&---------------------------------------------------------------------*
FORM f_collect_data.
wa_ztab-mandt = client.
wa_ztab-uname = sy-uname.
wa_ztab-chatid = chatid.
wa_ztab-send_msg = message.
wa_ztab-send_time = sy-uzeit.
wa_ztab-send_date = sy-datum.
ENDFORM. "f_collect_data
*&---------------------------------------------------------------------*
*& Form F_SEARCHHELP
*&---------------------------------------------------------------------*
FORM F_SEARCHHELP .
TABLES: usr02.
data:
begin of t_BNAME occurs 0,
BNAME like USR02-BNAME,
TRDAT TYPE XULDATE,
LTIME TYPE XULTIME,
"maktx like makt-maktx,
end of t_BNAME,
t_values type DYNPREAD occurs 0 WITH HEADER LINE,
v_prog like D020S-PROG.
TYPES: BEGIN OF X_RETURN .
INCLUDE STRUCTURE DDSHRETVAL. "Search help structure
TYPES: END OF X_RETURN.
data: l_dynpprog type sy-repid,
l_dynnr type sy-dynnr,
l_dynprofld TYPE help_info-dynprofld.
data: RETURN_TAB TYPE STANDARD TABLE OF X_RETURN WITH HEADER LINE.
v_prog = sy-repid.
REFRESH: t_values.
CLEAR: t_values.
t_values-fieldname = 'USER'.
APPEND t_VALUES.
* CALL FUNCTION 'DYNP_VALUES_READ'
* EXPORTING
* dyname = v_prog
* dynumb = '1000'
* TRANSLATE_TO_UPPER = ' '
* REQUEST = ' '
* PERFORM_CONVERSION_EXITS = ' '
* PERFORM_INPUT_CONVERSION = ' '
* DETERMINE_LOOP_INDEX = ' '
* TABLES
* dynpfields = t_values.
* IF sy-subrc = 0.
* READ TABLE T_VALUES INDEX 1.
* IF SY-SUBRC = 0.
SELECT BNAME TRDAT LTIME FROM usr02 INTO t_BNAME "to get recent login of the day
where USTYP = 'A' AND
TRDAT = SY-DATUM.
APPEND T_BNAME.
ENDSELECT.
if sy-subrc = 0.
l_dynpprog = sy-repid.
l_dynnr = sy-dynnr.
l_dynprofld = 'BNAME' .
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BNAME'
DYNPPROG = l_dynpprog
DYNPNR = l_dynnr
DYNPROFIELD = l_dynprofld
VALUE_ORG = 'S'
TABLES
value_tab = t_BNAME
RETURN_TAB = RETURN_TAB.
* IF sy-subrc = 0.
* IF NOT RETURN_TAB[] IS INITIAL.
* READ TABLE RETURN_TAB INDEX 1.
* IF SY-SUBRC = 0.
* T_BNAME = RETURN_TAB-FIELDVAL.
* ENDIF.
* ENDIF.
* ENDIF.
ENDIF.
* ENDIF.
* ENDIF.
ENDFORM. "F_SEARCHHELP
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
METHOD get_data.
* data selection
SELECT * FROM ztab_randy
INTO TABLE me->t_data
WHERE send_date = sy-datum ORDER BY send_date send_time DESCENDING.
IF sy-dbcnt IS INITIAL.
MESSAGE s398(00) WITH 'No data selected'.
ENDIF.
* export to memory
EXPORT data = me->t_data TO MEMORY ID sy-cprog.
ENDMETHOD. "get_data
METHOD generate_output.
* import output table from the memory and free afterwards
IMPORT data = me->t_data FROM MEMORY ID sy-cprog.
FREE MEMORY ID sy-cprog.
* Only if there is some data
CHECK me->t_data IS NOT INITIAL.
IF lo_dock IS NOT INITIAL.
lo_dock->free( ).
ENDIF.
* Create a docking control at bottom
* CHECK lo_dock IS INITIAL.
CREATE OBJECT lo_dock
EXPORTING
repid = sy-cprog
dynnr = sy-dynnr
ratio = 80
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCK_CONT'.
IF sy-subrc <> 0.
MESSAGE 'Error in the Docking control' TYPE 'S'.
ENDIF.
lo_dock->set_height( height = '340' ).
* Create a SALV for output
* CHECK lo_alv IS INITIAL.
TRY.
* Narrow Casting: To initialize custom container from
* docking container
lo_cont ?= lo_dock.
* SALV Table Display on the Docking container
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
r_container = lo_cont
container_name = 'DOCK_CONT'
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = me->t_data.
CATCH cx_salv_msg .
ENDTRY.
* Pf status
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
lo_functions = lo_alv->get_functions( ).
lo_functions->set_default( abap_true ).
lo_functions->add_function(
name = '&REF'
icon = '@42@'
* text =
tooltip = 'Refresh'
position = if_salv_c_function_position=>right_of_salv_functions ).
* Set event
gr_events = lo_alv->get_event( ).
CREATE OBJECT event_handler.
SET HANDLER event_handler->on_user_command FOR gr_events.
PERFORM set_column_setting USING lo_alv.
* output display
lo_alv->display( ).
ENDMETHOD. "generate_output
ENDCLASS. "lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
CASE e_salv_function.
WHEN '&REF'.
lo_report->get_data( ).
lo_report->generate_output( ).
ENDCASE.
ENDMETHOD. "on_user_command
ENDCLASS.
FORM set_column_setting USING lo_alv TYPE REF TO cl_salv_table.
DATA: v_text TYPE string.
DATA:lv_scrtext_s TYPE dd04t-scrtext_s,
lv_scrtext_m TYPE dd04t-scrtext_m,
lv_scrtext_l TYPE dd04t-scrtext_l.
cl_columns = lo_alv->get_columns( ).
cl_columns->set_optimize( abap_true ).
*
* TRY.
* cl_columns->set_cell_type_column( 'CELLTAB' ).
* CATCH cx_salv_data_error. "#EC NO_HANDLER
* ENDTRY.
TRY.
* cl_column ?= cl_columns->get_column( 'TABNAME' ).
* cl_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
cl_column ?= cl_columns->get_column( 'CHATID' ).
lv_scrtext_s = lv_scrtext_m = lv_scrtext_l = 'CHAT ID'.
cl_column->set_short_text( lv_scrtext_s ).
cl_column->set_medium_text( lv_scrtext_m ).
cl_column->set_long_text( lv_scrtext_l ).
CATCH cx_salv_not_found INTO cl_not_found.
CLEAR: v_text.
v_text = cl_not_found->get_text( ).
* MESSAGE v_text TYPE c_i.
ENDTRY.
ENDFORM. "set_column_setting
Post a Comment