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

Sap Chat



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Thu Oct 25, 2007 12:13 pm    Post subject: Sap Chat Reply with quote

Code:
*---------------------------------------------------------------------
* program title    : ZSAPcHAT v.1
* detail info at   : http://www.geocities.com/ZSAPcHAT
* author           : gadang b.susetyo ( gbstyo@yahoo.com.sg )
* created          : Sept 2002
*---------------------------------------------------------------------
PROGRAM  zsapchat.

INCLUDE tskhincl.
INCLUDE rsusrcom.
INCLUDE rsblkcom.

TABLES: zsapchat, nriv.
TYPES: texty(200) TYPE c.

DATA: p_text         TYPE texty,
      BEGIN OF tab_o OCCURS 0,
        name1(14),
        text         TYPE texty,
      END OF tab_o,
      BEGIN OF tab_i OCCURS 0,
        text         TYPE texty,
      END OF tab_i.

DATA: BEGIN OF usrtab OCCURS 0,
        uname TYPE sy-uname,
        pick  TYPE c,
      END OF usrtab.

DATA: last_segno  TYPE zsapchat-segno,
      last_uzeit  TYPE sy-uzeit,
      pv_uname    TYPE sy-uname,
      chat_type(1),
      v_text(30),
      v_maxsegno TYPE zsapchat-segno,
      v_init(1)  VALUE 'X',
      v_toolb(1) VALUE 'X',
      v_long(1)  VALUE 'X',
      v_message  TYPE sm04dic-popupmsg,
      funtioncode(22).

DATA: answer TYPE c,
      textline1(80),
      textline2(80).

DATA: dbtab TYPE TABLE OF zsapchat WITH HEADER LINE.

CONTROLS: tc_usr TYPE TABLEVIEW USING SCREEN 0888.

*----------------------------------------------------------------------*
MODULE sapchat_o1 OUTPUT.

  CLEAR: p_text, sy-ucomm, dbtab[].

  IF v_init = 'X'.
    PERFORM initialization.
  ENDIF.

  SET PF-STATUS 'ZSAPCHAT'.

  IF pv_uname IS INITIAL.
    SELECT * INTO TABLE dbtab FROM zsapchat
           WHERE  tcode  EQ sy-tcode
           AND    type   EQ chat_type
           AND    datum  EQ sy-datum
           AND    uzeit  GT last_uzeit
           AND    segno  GT last_segno.
    IF sy-subrc EQ 0.
      SORT dbtab BY uzeit segno.
      LOOP AT dbtab.
        CONCATENATE '[' dbtab-name1 ']' INTO tab_o-name1.
        tab_o-text  = dbtab-text.
        INSERT tab_o INDEX 1.
        last_uzeit = dbtab-uzeit. last_segno = dbtab-segno.
      ENDLOOP.
    ENDIF.

  ELSE.
    SELECT * INTO TABLE dbtab FROM zsapchat
           WHERE   tcode  EQ sy-tcode
           AND     type   EQ chat_type
           AND ( ( name1  EQ sy-uname AND name2 EQ pv_uname  ) OR
                 ( name1  EQ pv_uname AND name2 EQ sy-uname  )    )
           AND     datum  EQ sy-datum
           AND     uzeit  GT last_uzeit
           AND     segno  GT last_segno.
    IF sy-subrc EQ 0.
      SORT dbtab BY uzeit segno.
      LOOP AT dbtab.
        CONCATENATE '[' dbtab-name1 ']' INTO tab_o-name1.
        tab_o-text  = dbtab-text.
        INSERT tab_o INDEX 1.
        last_uzeit = dbtab-uzeit. last_segno = dbtab-segno.
      ENDLOOP.
    ENDIF.
  ENDIF.

**show long input message
  CALL FUNCTION 'RH_EDITOR_SET'
       EXPORTING
            repid          = sy-repid
            dynnr          = sy-dynnr
            controlname    = 'SAPCHAT_I'
            max_cols       = 250
            show_tool      = ' '
            show_status    = ' '
            display_mode   = v_long
       TABLES
            lines          = tab_i
       EXCEPTIONS
            create_error   = 1
            internal_error = 2
            OTHERS         = 3.

**show message output
  CALL FUNCTION 'RH_EDITOR_SET'
       EXPORTING
            repid          = sy-repid
            dynnr          = sy-dynnr
            controlname    = 'SAPCHAT_O'
            max_cols       = 250
            show_tool      = v_toolb
            show_status    = ' '
            display_mode   = 'X'
       TABLES
            lines          = tab_o
       EXCEPTIONS
            create_error   = 1
            internal_error = 2
            OTHERS         = 3.

**get online user
  REFRESH: usr_tabl, usrtab.
  CALL 'ThUsrInfo' ID 'OPCODE' FIELD opcode_list
    ID 'TAB' FIELD usr_tabl-*sys*.

  IF pv_uname IS INITIAL.
    LOOP AT usr_tabl WHERE mandt = sy-mandt
                       AND tcode = sy-tcode.
      CLEAR usrtab. usrtab-uname = usr_tabl-bname. APPEND usrtab.
    ENDLOOP.
    SORT usrtab BY uname.

  ELSE.
    usrtab-uname = sy-uname. APPEND usrtab.
    READ TABLE usr_tabl WITH KEY mandt = sy-mandt
                                 tcode = sy-tcode
                                 bname = pv_uname.
    IF sy-subrc EQ 0.
      usrtab-uname = pv_uname. APPEND usrtab.
    ELSE.
      MESSAGE w016(rp) WITH pv_uname ' has off-line'.
    ENDIF.
  ENDIF.

  DESCRIBE TABLE usrtab LINES tc_usr-lines.
ENDMODULE.                 " sapchat_o  OUTPUT

*----------------------------------------------------------------------*
MODULE sapchat_i0 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " sapchat_i0  INPUT

*----------------------------------------------------------------------*
MODULE sapchat_i1 INPUT.

  CHECK sy-ucomm NE 'INSTANT'.
  IF NOT p_text IS INITIAL.
    zsapchat-tcode = sy-tcode.
    zsapchat-type  = chat_type.
    zsapchat-name1 = sy-uname.
    zsapchat-name2 = pv_uname.
    zsapchat-datum = sy-datum.
    zsapchat-uzeit = sy-uzeit.
    PERFORM get_segno CHANGING zsapchat-segno.
    zsapchat-text  = p_text.
    INSERT zsapchat. "COMMIT WORK.
  ENDIF.

  IF v_long = space.
    CALL FUNCTION 'RH_EDITOR_GET'
         EXPORTING
              controlname    = 'SAPCHAT_I'
         TABLES
              lines          = tab_i
         EXCEPTIONS
              internal_error = 1
              OTHERS         = 2.

    IF sy-subrc = 0.
      LOOP AT tab_i WHERE text NE space.
        zsapchat-tcode = sy-tcode.
        zsapchat-type  = chat_type.
        zsapchat-name1 = sy-uname.
        zsapchat-name2 = pv_uname.
        zsapchat-datum = sy-datum.
        zsapchat-uzeit = sy-uzeit.
        PERFORM get_segno CHANGING zsapchat-segno.
        zsapchat-text  = tab_i-text.
        INSERT zsapchat. "COMMIT WORK.
      ENDLOOP.
      REFRESH tab_i.
    ENDIF.
  ENDIF.

ENDMODULE.                 " sapchat_i  INPUT

*----------------------------------------------------------------------*
MODULE sapchat_i2 INPUT.
  CLEAR: usrtab.
  READ TABLE usrtab WITH KEY pick = 'X'.
  IF sy-subrc = 0 AND pv_uname EQ space AND sy-ucomm NE 'INSTANT'.
    CONCATENATE 'Would you like to invite' usrtab-uname '?'
           INTO textline1 SEPARATED BY space.

    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
         EXPORTING
              textline1      = textline1
              titel          = 'Private Chat'
              cancel_display = ' '
         IMPORTING
              answer         = answer.

    IF answer = 'J'.
      zsapchat-tcode = sy-tcode.
      zsapchat-type  = 'I'. "private invitation
      zsapchat-name1 = sy-uname.
      zsapchat-name2 = usrtab-uname.
      zsapchat-datum = sy-datum.
      zsapchat-uzeit = sy-uzeit.
      PERFORM get_segno CHANGING zsapchat-segno.
      zsapchat-text  = 'I'.
      INSERT zsapchat.
      IF sy-subrc EQ 0.
        MESSAGE s016(rp) WITH 'Invitation has been sent'.
      ELSE.
        MESSAGE s016(rp) WITH 'Unable to invite'.
      ENDIF.
    ELSEIF answer = 'N'.
    ENDIF.
  ENDIF.
ENDMODULE.                 " sapchat_i2  INPUT


*----------------------------------------------------------------------*
MODULE sapchat_i3 INPUT.
  DATA: i_answer   TYPE c,
        i_valueout TYPE sy-uname.

  CASE sy-ucomm.
    WHEN 'O_TOOL'.
      IF v_toolb EQ 'X'.
        v_toolb = space.
      ELSE.
        v_toolb = 'X'.
      ENDIF.
    WHEN 'I_LONG'.
      IF v_long EQ 'X'.
        v_long = space.
      ELSE.
        v_long = 'X'.
      ENDIF.
    WHEN 'INSTANT'.
      IF p_text IS INITIAL.
        MESSAGE s016(rp)
        WITH 'Please enter text in the short message input box'.
      ELSE.
        CALL FUNCTION 'POPUP_TO_GET_VALUE'
             EXPORTING
                  fieldname           = 'UNAME'
                  tabname             = 'SYST'
                  titel               = 'Please enter the '
                  valuein             = usrtab-uname
             IMPORTING
                  answer              = i_answer
                  valueout            = i_valueout
             EXCEPTIONS
                  fieldname_not_found = 1
                  OTHERS              = 2.
        IF sy-subrc EQ 0 AND i_answer NE 'C'.
          CONCATENATE '[' sy-uname ']' p_text INTO v_message.
          CALL FUNCTION 'TH_POPUP'
               EXPORTING
                    client         = sy-mandt
                    user           = i_valueout
                    MESSAGE        = v_message
               EXCEPTIONS
                    user_not_found = 1
                    OTHERS         = 2.
          IF sy-subrc EQ 0.
            MESSAGE s016(rp) WITH 'Message has been sent'.
          ELSE.
            MESSAGE s016(rp) WITH 'Unable to send message'.
            PERFORM send_offline_message USING i_valueout
                                               p_text.
          ENDIF.
        ENDIF.
      ENDIF.
  ENDCASE.
ENDMODULE.                 " sapchat_i3  INPUT


*---------------------------------------------------------------------*
MODULE tc_usr_mark INPUT.
  MODIFY usrtab
    INDEX tc_usr-current_line
    TRANSPORTING pick.
ENDMODULE.

*----------------------------------------------------------------------*
FORM initialization.
  CLEAR: pv_uname, chat_type.

  SELECT SINGLE * FROM  zsapchat
                 WHERE  datum  LT sy-datum
                   AND  type   NE 'F'.

  IF sy-subrc EQ 0.
    DELETE FROM zsapchat WHERE datum LT sy-datum
                           AND type  NE 'F'. "off-line message
    IF sy-subrc EQ 0.
      CALL FUNCTION 'NUMBER_RANGE_INTERVAL_INIT'
           EXPORTING
                object            = 'ZSAPCHAT'
           EXCEPTIONS
                no_interval_found = 1
                object_not_found  = 2
                OTHERS            = 3.
    ENDIF.
  ENDIF.

**private chat
  SELECT SINGLE * FROM zsapchat WHERE type  = '@'
                                  AND name1 = sy-uname.
  IF sy-subrc EQ 0.
    chat_type = 'V'. "private chat
    pv_uname  = zsapchat-name2.

    DELETE zsapchat.

    SET TITLEBAR 'ZSAPCHAT' WITH 'Private chat with ' pv_uname.
  ELSE.
    chat_type = 'M'. "mass/public chat
    SET TITLEBAR 'ZSAPCHAT'
    WITH 'Welcome to SAPcHAT v.1 - public channel'
          space.
  ENDIF.

  CONCATENATE '/O' sy-tcode INTO funtioncode.
  PERFORM last_refresh_segno.
  PERFORM load_offline_message.
  CLEAR: v_init.
ENDFORM.                    " initialization

*----------------------------------------------------------------------*
FORM get_segno CHANGING p_segno.
  CALL FUNCTION 'NUMBER_GET_NEXT'
       EXPORTING
            nr_range_nr             = '88'
            object                  = 'ZSAPCHAT'
       IMPORTING
            number                  = p_segno
       EXCEPTIONS
            interval_not_found      = 1
            number_range_not_intern = 2
            object_not_found        = 3
            quantity_is_0           = 4
            quantity_is_not_1       = 5
            interval_overflow       = 6
            buffer_overflow         = 7
            OTHERS                  = 8.
  IF  sy-subrc = 3.
    MESSAGE w016(rp)
    WITH 'Please create number range Object:ZSAPCHAT; No:88'.
  ENDIF.
ENDFORM.                    " get_abcde

*----------------------------------------------------------------------*
FORM last_refresh_segno.
  CALL FUNCTION 'NUMBER_GET_INFO'
       EXPORTING
            nr_range_nr        = '88'
            object             = 'ZSAPCHAT'
       IMPORTING
            interval           = nriv
       EXCEPTIONS
            interval_not_found = 1
            object_not_found   = 2
            OTHERS             = 3.

  IF sy-subrc EQ 0.
    last_segno = nriv-nrlevel.
  ENDIF.
ENDFORM.                    " last_refresh_segno

*----------------------------------------------------------------------*
MODULE sapchat_o2 OUTPUT.
  DATA: l_name TYPE sy-uname,
        t_zsapchat TYPE TABLE OF zsapchat.

  SELECT * FROM zsapchat INTO TABLE t_zsapchat
                         WHERE tcode = sy-tcode
                           AND   type  = 'I' "private invitation
                           AND ( name1 = sy-uname OR name2 = sy-uname ).

  LOOP AT t_zsapchat INTO zsapchat.
    IF zsapchat-name1 = sy-uname.
      l_name = zsapchat-name2.
    ELSE.
      l_name = zsapchat-name1.
    ENDIF.
    CASE zsapchat-text.
      WHEN 'I'. "initial invitation
        IF zsapchat-name2 = sy-uname.
          CONCATENATE 'You''ve got private chat invitation from' l_name
                      '.' INTO textline1 SEPARATED BY space.
          textline2 = 'Accept it..?'.
          CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
               EXPORTING
                    textline1      = textline1
                    textline2      = textline2
                    titel          = 'Private Chat Invitation'
                    cancel_display = ' '
               IMPORTING
                    answer         = answer.

          IF answer = 'J'.
            zsapchat-text = 'J'.
            UPDATE zsapchat.

            zsapchat-type  = '@'.
            zsapchat-name1 = sy-uname.
            zsapchat-name2 = l_name.
            INSERT zsapchat.
            IF sy-subrc EQ 0.
              PERFORM creates_a_new_session
                USING 'Opening new private chat session...'.
            ENDIF.

          ELSEIF answer = 'N'.
            CONCATENATE 'Your private chat invitation to'
                         sy-uname 'has been rejected.'
                   INTO  v_message SEPARATED BY space.

            CALL FUNCTION 'TH_POPUP'
                 EXPORTING
                      client         = sy-mandt
                      user           = l_name
                      MESSAGE        = v_message
                 EXCEPTIONS
                      user_not_found = 1
                      OTHERS         = 2.

            DELETE zsapchat.
          ENDIF.
        ENDIF.

      WHEN 'J'.
        IF zsapchat-name1 = sy-uname.
          DELETE zsapchat.

          zsapchat-type  = '@'.
          zsapchat-name1 = sy-uname.
          zsapchat-name2 = l_name.
          INSERT zsapchat.
          IF sy-subrc EQ 0.
            PERFORM creates_a_new_session
              USING 'Opening new session for private chat...'.
          ENDIF.
        ENDIF.
      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.
ENDMODULE.                 " sapchat_o2  OUTPUT

*----------------------------------------------------------------------*
FORM send_offline_message USING    p_uname
                                   p_message.

  DATA: l_uzeit(10). WRITE sy-uzeit TO l_uzeit.
  DATA: l_datum(10). WRITE sy-datum TO l_datum.

  zsapchat-tcode = sy-tcode.
  zsapchat-type  = 'F'. "off-line message
  zsapchat-name1 = sy-uname.
  zsapchat-name2 = p_uname.
  zsapchat-datum = sy-datum.
  zsapchat-uzeit = sy-uzeit.
  PERFORM get_segno CHANGING zsapchat-segno.
  CONCATENATE '***' l_datum l_uzeit '***' p_message
         INTO zsapchat-text SEPARATED BY space.
  INSERT zsapchat.
  IF sy-subrc EQ 0.
    MESSAGE s016(rp)
    WITH 'Your message has been sent as an off-line message'.
  ENDIF.
ENDFORM.                    " send_offline_message

*----------------------------------------------------------------------*
FORM load_offline_message.
  SELECT * FROM  zsapchat
         WHERE  tcode  EQ sy-tcode
         AND    type   EQ 'F' "offline message
         AND    name2  EQ sy-uname
         ORDER BY uzeit segno.
    CONCATENATE '[' zsapchat-name1 ']' INTO tab_o-name1.
    tab_o-text  = zsapchat-text.
    INSERT tab_o INDEX 1.
    DELETE zsapchat.
  ENDSELECT.
ENDFORM.                    " load_offline_message


*----------------------------------------------------------------------*
FORM creates_a_new_session USING    value(p_text).
  MESSAGE s016(rp) WITH p_text.
  CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'
       EXPORTING
            functioncode           = funtioncode
       EXCEPTIONS
            function_not_supported = 1
            OTHERS                 = 2.
ENDFORM.                    " creates_a_new_session
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 -> Programming Techniques | Приемы программирования 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.