显示登录用户并发消息

*&---------------------------------------------------------------------*
*& Report  ZTEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest.

*REPORT Z_SEND_POPUP  NO STANDARD PAGE HEADING.

INCLUDE <icon>.

* Global data decleration
DATA: itab_uinfo LIKE STANDARD TABLE OF uinfo WITH HEADER LINE.
DATA: itab_send  LIKE STANDARD TABLE OF uinfo WITH HEADER LINE.
DATA: box(1) TYPE c,
      lines  TYPE i,
      w_text1  LIKE sm04dic-popupmsg,
      w_text2  LIKE sm04dic-popupmsg,
      message  LIKE sm04dic-popupmsg.

START-OF-SELECTION.

  SET PF-STATUS 'LIST'.

* Text which should be send to other users
  PERFORM show_input_message.

* First, show all User which are in the system...
  PERFORM show_loged_on_users.

  lines = sy-linno - 1.

END-OF-SELECTION.

 

AT USER-COMMAND.

  CASE sy-ucomm.
    WHEN 'EXEC'.

* Determine Text
      READ LINE 2 FIELD VALUE w_text1.
      w_text2 = w_text1.

      DO lines TIMES.
        CLEAR box.
        READ LINE sy-index FIELD VALUE box.
        IF box = 'X'.
          itab_send-bname = itab_uinfo-bname.
          itab_send-mandt = itab_uinfo-mandt.
          APPEND itab_send.

        ENDIF.
      ENDDO.
* Finally send message....
      PERFORM send_message.

    WHEN 'AUFF'.

* Text which should be send to other users
      PERFORM show_input_message.

* First, show all User which are in the system...
      PERFORM show_loged_on_users.

      lines = sy-linno - 1.
      sy-lsind = sy-lsind - 1.
    WHEN OTHERS.
  ENDCASE.

 


*&---------------------------------------------------------------------*
*&      Form  show_loged_on_users
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM show_loged_on_users.

* Get all loged on users
  PERFORM get_loged_on_users.

* Combine to only GUI - Users
  PERFORM combine_users.

* Show Users
  PERFORM show_users_in_list.


ENDFORM.                    " show_loged_on_users
*&---------------------------------------------------------------------*
*&      Form  get_loged_on_users
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_loged_on_users.

  DATA: itab_rfchosts LIKE STANDARD TABLE OF rfchosts WITH HEADER LINE.

  CALL FUNCTION 'RFC_GET_LOCAL_DESTINATIONS'
    TABLES
      localdest     = itab_rfchosts
    EXCEPTIONS
      not_available = 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.

 

  LOOP AT itab_rfchosts.

    CALL FUNCTION 'THUSRINFO' DESTINATION itab_rfchosts
      TABLES
        usr_tabl              = itab_uinfo
      EXCEPTIONS
        communication_failure = 17.

  ENDLOOP.


ENDFORM.                    " get_loged_on_users
*&---------------------------------------------------------------------*
*&      Form  combine_users
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM combine_users.

  DATA: itab_loc_uinfo LIKE STANDARD TABLE OF uinfo WITH HEADER LINE.

  itab_loc_uinfo[]  = itab_uinfo[].

  CLEAR itab_uinfo. REFRESH itab_uinfo.

  LOOP AT itab_loc_uinfo.
    IF itab_loc_uinfo-stat = '2' AND  "GUI - User
       itab_loc_uinfo-bname NE space.
      READ TABLE itab_uinfo WITH KEY mandt = itab_loc_uinfo-mandt
                                     bname = itab_loc_uinfo-bname.
      IF sy-subrc NE 0.
        itab_uinfo = itab_loc_uinfo.
        APPEND itab_uinfo.
      ENDIF.
    ENDIF.
  ENDLOOP.

* finaly sort...
  SORT itab_uinfo BY bname.

ENDFORM.                    " combine_users
*&---------------------------------------------------------------------*
*&      Form  show_users_in_list
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM show_users_in_list.

  DATA: w_color       TYPE c,
        w_bapibname LIKE  bapibname-bapibname,
        w_bapiaddr3 LIKE  bapiaddr3.

  DATA: itab_return LIKE STANDARD TABLE OF bapiret2.

  LOOP AT itab_uinfo.
* First, Color Handling....
    IF w_color EQ space.
      FORMAT COLOR COL_HEADING.
      w_color = 'X'.
    ELSE.
      FORMAT COLOR COL_NORMAL.
      w_color = space.
    ENDIF.

* Get Additional Information to the user..

    w_bapibname = itab_uinfo-bname.

    CALL FUNCTION 'BAPI_USER_GET_DETAIL'
      EXPORTING
        username = w_bapibname
      IMPORTING
        address  = w_bapiaddr3
      TABLES
        return   = itab_return.


    WRITE : /
    icon_hr_position AS ICON,
    box AS CHECKBOX,
    itab_uinfo-mandt, itab_uinfo-bname,
    w_bapiaddr3-fullname, AT sy-linsz ' '.
    HIDE: box, itab_uinfo-mandt, itab_uinfo-bname.

  ENDLOOP.

ENDFORM.                    " show_users_in_list
*&---------------------------------------------------------------------*
*&      Form  show_input_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM show_input_message.

  w_text1 = '   Enter text here'.

  FORMAT COLOR COL_NEGATIVE.
  WRITE : icon_bw_ra_setting_active AS ICON,
  'Please fill in the text for Sending:',
  icon_bw_ra_setting_active AS ICON,
  AT sy-linsz ' '
.
  WRITE / w_text1 INPUT ON.

  ULINE.


ENDFORM.                    " show_input_message
*&---------------------------------------------------------------------*
*&      Form  send_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM send_message.

  DATA: w_name  LIKE sy-uname,
        w_mandt LIKE sy-mandt,
        w_icon1 LIKE icon-name,
        w_icon2 LIKE icon-name,
        w_icon3 LIKE icon-name,
        w_success TYPE c,
        w_succt(100) TYPE c.

  CONCATENATE sy-uname ':' w_text2 INTO message.

  LOOP AT itab_send.
    w_name  = itab_send-bname.
    w_mandt = itab_send-mandt.

    CALL FUNCTION 'TH_POPUP'
      EXPORTING
        client               = w_mandt
        user                 = w_name
        MESSAGE              = message
*   MESSAGE_LEN          = 0
*   CUT_BLANKS           = ' '
      EXCEPTIONS
        user_not_found       = 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.

    ELSE.

      w_success = 'X'.

    ENDIF.

  ENDLOOP.

  REFRESH itab_send.
  CLEAR   itab_send.

  IF w_success NE space.

    w_icon1 = 'ICON_MANAGER'.
    w_icon2 = 'ICON_PM_INSERT'.
    w_icon3 = 'ICON_MESSAGE_INFORMATION_SMALL'.

    CONCATENATE sy-uname
    ':Your message has be send to the selected user(s)'
    INTO w_succt.

    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        titlebar                    = 'Send Message to User'
        text_question               = w_succt
        text_button_1               = 'Yes'
        icon_button_1               = w_icon1
        text_button_2               = 'Yuhuu'
        icon_button_2               = w_icon2
        display_cancel_button       = ' '
          popup_type                  = w_icon3
* IMPORTING
*   ANSWER                      =
* TABLES
*   PARAMETER                   =
  EXCEPTIONS
    text_not_found              = 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.
  ENDIF.
ENDFORM.                    " send_message

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值