Sunday, 6 November 2011

Send mail to sap inbox Business Workplace

DATA:it_receivers    TYPE STANDARD TABLE OF  somlreci1,
             wa_it_receivers LIKE LINE OF it_receivers,
             it_message         TYPE STANDARD TABLE OF solisti1,
             wa_it_message      LIKE LINE OF it_message,
             c1(99)    TYPE c,
             c2(15)    TYPE c,
             num_lines TYPE i,
             psubject(90)       TYPE c,
             it_packing_list TYPE STANDARD TABLE OF  sopcklsti1,
             gd_doc_data     TYPE sodocchgi1,
             wa_it_packing_list LIKE LINE OF  it_packing_list.

        FREE wa_it_receivers.
        wa_it_receivers-receiver   = sy-uname.  "&----- Assign SAP User Id
        wa_it_receivers-rec_type   = 'B'.                    "&-- Send to SAP Inbox
        wa_it_receivers-com_type   = 'INT'.
        wa_it_receivers-notif_del  = 'X'.
        wa_it_receivers-notif_ndel = 'X'.
        APPEND wa_it_receivers TO it_receivers .
        DESCRIBE TABLE it_receivers LINES num_lines.
*AT LAST.
        IF num_lines IS NOT INITIAL.
          CONCATENATE 'Apriso inbound idoc errors.' wa_data-docnum INTO psubject SEPARATED BY space.
*    psubject = 'Apriso inbound idoc errors.' .
          CLEAR wa_it_message.
        ENDIF.
        AT LAST.
          c1 = 'Dear'(005).
          c2 = sy-uname.
          CONCATENATE c1 c2 ',' INTO
          wa_it_message-line SEPARATED BY space.
          APPEND wa_it_message TO it_message.

          LOOP AT lt_txt INTO ls_txt.
            CLEAR wa_it_message.
            wa_it_message-line = ls_txt.
            APPEND wa_it_message TO it_message.
          ENDLOOP.
*endif.
**********************download log

          gd_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
          gd_doc_data-obj_langu = sy-langu.
          gd_doc_data-obj_name = 'SAPRPT'.
          gd_doc_data-obj_descr = psubject.
          gd_doc_data-sensitivty = 'F'.
*Describe the body of the message
          CLEAR wa_it_packing_list.
          REFRESH it_packing_list.
          wa_it_packing_list-transf_bin = space.
          wa_it_packing_list-head_start = 1.
          wa_it_packing_list-head_num = 0.
          wa_it_packing_list-body_start = 1.
          DESCRIBE TABLE it_message LINES wa_it_packing_list-body_num.
          wa_it_packing_list-doc_type = 'RAW'.
          APPEND wa_it_packing_list TO it_packing_list.
*&------ Call the Function Module to send the message to External and SAP Inbox
          CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
            EXPORTING
              document_data              = gd_doc_data
              put_in_outbox              = 'X'
              commit_work                = 'X'
            TABLES
              packing_list               = it_packing_list
              contents_txt               = it_message
              receivers                  = it_receivers
            EXCEPTIONS
              too_many_receivers         = 1
              document_not_sent          = 2
              document_type_not_exist    = 3
              operation_no_authorization = 4
              parameter_error            = 5
              x_error                    = 6
              enqueue_error              = 7
              OTHERS                     = 8.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.

Saturday, 5 November 2011

Log Creation code

DATA: lt_txt TYPE TABLE OF t_txt,
                ls_txt TYPE t_txt.
        counter = counter + 1.
        IF counter = 1.
          ls_txt  = 'Segment Number       Error'.
          APPEND ls_txt TO lt_txt.
        endif.
          LOOP AT ret INTO wa_ret.
            CONCATENATE wa_data-segnum wa_ret-message INTO ls_txt SEPARATED BY space.
          ENDLOOP.
          APPEND ls_txt TO lt_txt.
        AT LAST.
          CALL METHOD cl_gui_frontend_services=>get_desktop_directory
            CHANGING
              desktop_directory    = lv_path
            EXCEPTIONS
              cntl_error           = 1
*    error_no_gui         = 2
*    not_supported_by_gui = 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.

          CALL METHOD cl_gui_cfw=>update_view.
          CONCATENATE lv_path '\error_log.txt' INTO lv_path IN CHARACTER MODE.
*    CONCATENATE 'C:\Documents and Settings\XPMUser\Desktop' '_LOG.txt' INTO lv_path IN CHARACTER MODE.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              filename                = lv_path
            TABLES
              data_tab                = lt_txt
            EXCEPTIONS
              file_write_error        = 1
              no_batch                = 2
              gui_refuse_filetransfer = 3
              invalid_type            = 4
              no_authority            = 5
              unknown_error           = 6
              header_not_allowed      = 7
              separator_not_allowed   = 8
              filesize_not_allowed    = 9
              header_too_long         = 10
              dp_error_create         = 11
              dp_error_send           = 12
              dp_error_write          = 13
              unknown_dp_error        = 14
              access_denied           = 15
              dp_out_of_memory        = 16
              disk_full               = 17
              dp_timeout              = 18
              file_not_found          = 19
              dataprovider_exception  = 20
              control_flush_error     = 21
              OTHERS                  = 22.
          IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

Tuesday, 1 November 2011

Submit program

CALL FUNCTION 'DEQUEUE_ALL'.
      read table it_comm_idocs into wa_comm_idocs index 1.
      if sy-subrc = 0.
      RANGES: R_DOCNUM  FOR  EDIDC-DOCNUM.
      R_DOCNUM-SIGN = 'I'.
      R_DOCNUM-OPTION = 'EQ'.
      R_DOCNUM-LOW = wa_comm_idocs-DOCNUM.
      APPEND R_DOCNUM.
      submit RSEOUT00 with DOCNUM in R_DOCNUM and return.
      endif.