Purpose: Sometimes, some SAP consultant are locking tcode/ material, customer.
And you need to eidt this object but not have phone-number. You can use this tool to send a message.
And you can call her to eat sometimes.
Solution: Use FM:TH_POPUP, Send message like QQ/Wechat/Weixin directory to user who login SAP GUI.
Step1: Create a z report, create a new screen 9000, create a customer control named”G_CONTAINER”.
Step2:Add below logic in “Logic process” of screen 9000.
PROCESS BEFORE OUTPUT.
MODULE status_9000.
MODULE display_alv.
PROCESS AFTER INPUT.
MODULE user_command_9000.
MODULE exit AT EXIT-COMMAND.
Step 3: Add “ok_code” in Screen.
Step 4: Create title-bar and status, add below source code.
REPORT ZQQ.
TYPES: BEGIN OF ty_itab.
INCLUDE STRUCTURE usr41.
TYPES: name_textc TYPE user_addr-name_textc,
message TYPE sm04dic-popupmsg,
END OF ty_itab.
TYPES: BEGIN OF ty_name,
bname TYPE usr41-bname,
name_textc TYPE user_addr-name_textc,
END OF ty_name.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
DATA: it_tab TYPE STANDARD TABLE OF ty_itab,
wa_tab LIKE LINE OF it_tab,
it_name TYPE STANDARD TABLE OF ty_name,
wa_name LIKE LINE OF it_name.
*** ALV
DATA: it_fieldcat TYPE lvc_t_fcat,
w_layout TYPE lvc_s_layo,
g_container TYPE REF TO cl_gui_custom_container,
g_alv TYPE REF TO cl_gui_alv_grid.
DATA: gt_exclude TYPE ui_functions.
INITIALIZATION.
START-OF-SELECTION.
END-OF-SELECTION.
CALL SCREEN 9000.
*& Module STATUS_9000 OUTPUT
*&———————————————————————*
* pbo
*———————————————————————-*
MODULE status_9000 OUTPUT.
SET PF-STATUS ‘STA9000’.
SET TITLEBAR ‘TIT9000’.
ENDMODULE. ” STATUS_9000 OUTPUT
*&———————————————————————*
*& Module USER_COMMAND_9000 INPUT
*&———————————————————————*
* User Command.
*———————————————————————-*
MODULE user_command_9000 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN ‘ENTR’.
WHEN ‘BACK’.
LEAVE TO SCREEN 0.
WHEN ‘SAVE’.
PERFORM send_message.
WHEN OTHERS.
ENDCASE.
ENDMODULE. ” USER_COMMAND_9000 INPUT
*&———————————————————————*
*& Module EXIT INPUT
*&———————————————————————*
* Leave
*———————————————————————-*
MODULE exit INPUT.
LEAVE PROGRAM.
ENDMODULE. ” EXIT INPUT
*&———————————————————————*
*& Module DISPLAY_ALV OUTPUT
*&———————————————————————*
* ALV
*———————————————————————-*
MODULE display_alv OUTPUT.
IF g_container IS INITIAL.
PERFORM frm_create_container.
PERFORM get_user_list.
PERFORM frm_pre_fieldcat.
PERFORM frm_pre_layout.
PERFORM exclude_tb_functions TABLES gt_exclude.
PERFORM frm_set_tab_display.
PERFORM frm_change_edit_mode.
ELSE.
PERFORM frm_refresh_alv.
ENDIF.
ENDMODULE. ” DISPLAY_ALV OUTPUT
*&———————————————————————*
*& Form FRM_CREATE_CONTAINER
*&———————————————————————*
*
*———————————————————————-*
FORM frm_create_container .
CREATE OBJECT g_container
EXPORTING
container_name = ‘G_CONTAINER’.
CREATE OBJECT g_alv
EXPORTING
i_parent = g_container.
ENDFORM. ” FRM_CREATE_CONTAINER
*&———————————————————————*
*& Form frm_pre_fieldcat
*&———————————————————————*
* 设置字段目录属性
*———————————————————————-*
FORM frm_pre_fieldcat .
PERFORM frm_fieldcat USING :
‘MANDT’ ‘客户端’ ‘X’ ‘X’ space 10 12,
‘BNAME’ ‘用户名’ ‘X’ ‘X’ space 10 12,
‘NAME_TEXTC’ ‘姓名’ ‘X’ ‘X’ space 16 16,
‘MESSAGE’ ‘消息内容’ space space ‘X’ 50 50.
ENDFORM. ” frm_pre_fieldcat
*&———————————————————————*
*& Form frm_fieldcat
*&———————————————————————*
* text
*———————————————————————-*
FORM frm_fieldcat USING p_field p_text p_key p_no_zero p_edited p_vlen p_ilen.
DATA lw_fcat TYPE lvc_s_fcat.
lw_fcat-fieldname = p_field.
lw_fcat-coltext = p_text.
lw_fcat-no_zero = ”.
lw_fcat-key = p_key.
lw_fcat-no_zero = p_no_zero.
lw_fcat-checktable = ‘!’.
lw_fcat-edit = p_edited.
lw_fcat-outputlen = p_vlen. “显示长度
lw_fcat-dd_outlen = p_ilen. “可输入长度
APPEND lw_fcat TO it_fieldcat.
ENDFORM. ” frm_fieldcat
*&———————————————————————*
*& Form frm_pre_layout
*&———————————————————————*
* 设置ALV样式
*———————————————————————-*
FORM frm_pre_layout .
w_layout-zebra = ‘X’.
w_layout-sel_mode = ‘B’.
ENDFORM. ” frm_pre_layout
*&———————————————————————*
*& Form frm_set_tab_display
*&———————————————————————*
* 显示ALV
*———————————————————————-*
FORM frm_set_tab_display .
CALL METHOD g_alv->set_table_for_first_display
EXPORTING
i_save = ‘ ‘
is_layout = w_layout
it_toolbar_excluding = gt_exclude
CHANGING
it_outtab = it_tab[]
it_fieldcatalog = it_fieldcat
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.
ENDFORM. ” frm_set_tab_display
*&———————————————————————*
*& Form frm_refresh_alv
*&———————————————————————*
* 刷新ALV
*———————————————————————-*
FORM frm_refresh_alv .
DATA: ls_stable TYPE lvc_s_stbl.
ls_stable-row = ‘X’.
ls_stable-col = ‘X’.
CALL METHOD g_alv->refresh_table_display
EXPORTING
is_stable = ls_stable
* i_soft_refresh =
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. ” frm_refresh_alv
*&———————————————————————*
*& Form frm_change_edit_mode
*&———————————————————————*
* 切换编辑模式
*———————————————————————-*
FORM frm_change_edit_mode.
CALL METHOD g_alv->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
“切换模式后刷新ALV
PERFORM frm_refresh_alv.
ENDFORM. ” frm_change_edit_mode
*&———————————————————————*
*& Form EXCLUDE_TB_FUNCTIONS
*&———————————————————————*
* 弃掉标准按钮(增加、插入)
*———————————————————————-*
* –>P_GT_EXCLUDE text
* –>P_ELSE text
*———————————————————————-*
FORM exclude_tb_functions TABLES pt_exclude TYPE ui_functions.
DATA: ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_CUT. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_COPY. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_COPY_ROW. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_LYSTYLE_NO_INSERT_ROWS. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_LY_NO_INSERT_ROWS. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT_BACK. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT_PREV. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_FC_VIEWS. APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ENDFORM.
*&———————————————————————*
*& Form GET_USER_LIST
*&———————————————————————*
* get_user_list
*———————————————————————-*
FORM get_user_list .
SELECT *
FROM usr41 CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE it_tab.
IF sy-subrc = 0.
SORT it_tab BY mandt bname.
DELETE ADJACENT DUPLICATES FROM it_tab COMPARING mandt bname.
SELECT bname
name_textc
FROM user_addr CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE it_name
FOR ALL ENTRIES IN it_tab
WHERE mandt = it_tab-mandt
AND bname = it_tab-bname.
LOOP AT it_tab INTO wa_tab.
READ TABLE it_name INTO wa_name WITH KEY bname = wa_tab-bname.
IF sy-subrc = 0.
wa_tab-name_textc = wa_name-name_textc.
MODIFY it_tab FROM wa_tab.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. ” GET_USER_LIST
*&———————————————————————*
*& Form SEND_MESSAGE
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM send_message .
CALL METHOD g_alv->check_changed_data.
LOOP AT it_tab INTO wa_tab WHERE message IS NOT INITIAL.
READ TABLE it_name INTO wa_name WITH KEY bname = sy-uname.
IF sy-subrc = 0.
CONCATENATE wa_tab-message ‘–From:’ sy-sysid ‘:’ sy-mandt ‘/’
wa_name-name_textc ‘/TCode:ZQQ,www.hot583.com’ INTO wa_tab-message.
ENDIF.
CALL FUNCTION ‘TH_POPUP’
EXPORTING
client = wa_tab-mandt
user = wa_tab-bname
message = wa_tab-message.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
RETURN.
ENDIF.
MESSAGE ‘Send Successed’ TYPE ‘S’.
ENDLOOP.
ENDFORM. ” SEND_MESSAGE
This post is come from www.hot583.com, you can share/use it with the post original link for free.
But pay attention of any risk yourself.
微信原文《The End》