REPORT  zemail.

DATAc(50).
DATAsent LIKE sonv-flag.
DATAemail_id LIKE sofolenti1-object_id.
DATABEGIN OF email_data.
        INCLUDE STRUCTURE sodocchgi1.
DATAEND OF email_data.
DATABEGIN OF email_send OCCURS 10.
        INCLUDE STRUCTURE somlreci1.
DATAEND OF email_send.
DATABEGIN OF email_text OCCURS 10.
        INCLUDE STRUCTURE solisti1.
DATAEND OF email_text.
DATAftab LIKE solisti1  OCCURS WITH HEADER LINE.
DATA act_filetype LIKE  rlgrap-filetype.
DATA act_filename LIKE  rlgrap-filename.

SELECT-OPTIONS send_to FOR NO INTERVALS LOWER CASE.
SELECTION-SCREEN SKIP.
PARAMETERSsubject(30).
SELECTION-SCREEN SKIP.
PARAMETERSfile LIKE rlgrap-filename DEFAULT 'c:\temp'.
SELECTION-SCREEN SKIP.
PARAMETERSl1(84).
PARAMETERSl2(84).
PARAMETERSl3(84).
PARAMETERSl4(84).
PARAMETERSl5(84).
PARAMETERSl6(84).
PARAMETERSl7(84).
PARAMETERSl8(84).
PARAMETERSl9(84).

INITIALIZATION.
  send_to-low '@.'.
  APPEND send_to.

START-OF-SELECTION.
  PERFORM upload.
  PERFORM send.

END-OF-SELECTION.

*---------------------------------------------------------------------*
*       FORM SEND                                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM send.
  email_text-line l1.
  APPEND email_text.
  email_text-line l2.
  APPEND email_text.
  email_text-line l3.
  APPEND email_text.
  email_text-line l4.
  APPEND email_text.
  email_text-line l5.
  APPEND email_text.
  email_text-line l6.
  APPEND email_text.
  email_text-line l7.
  APPEND email_text.
  email_text-line l8.
  APPEND email_text.
  email_text-line l9.
  APPEND email_text.

  email_data-obj_name 'MESSAGE'.
  email_data-obj_descr subject.
  email_data-obj_langu 'E'.
  email_data-sensitivty 'P'.
  email_data-obj_prio '1'.
  email_data-no_change 'X'.
  email_data-priority '1'.

  LOOP AT send_to.
    email_send-receiver send_to-low.
    email_send-rec_type 'U'.
    email_send-com_type 'INT'.
    email_send-express 'X'.
    APPEND email_send.
  ENDLOOP.

  WRITE:'End of program'.

*****************************************************

  DATA lines TYPE i,
         f_lines TYPE i.
  DATA e_packing_tab LIKE sopcklsti1 OCCURS WITH HEADER LINE.

*
  DESCRIBE TABLE email_text LINES lines.
  e_packing_tab-transf_bin space.
  e_packing_tab-head_start 1.
  e_packing_tab-head_num   0.
  e_packing_tab-body_start 1.
  e_packing_tab-body_num   lines.
  e_packing_tab-doc_type   'RAW'.
  APPEND e_packing_tab.

  DESCRIBE TABLE ftab LINES f_lines.
  DATA doc_size TYPE i.
  doc_size f_lines * 255.

  DATAobjhead LIKE solisti1 OCCURS WITH HEADER LINE.
  objhead act_filenameAPPEND objhead.


  DATAdoc_type(3).
  SPLIT act_filename AT '.' INTO act_filename doc_type.

  e_packing_tab-transf_bin 'X'.
  e_packing_tab-head_start 1.
  e_packing_tab-head_num   1.
  e_packing_tab-body_start 1.
  e_packing_tab-body_num   f_lines.
  e_packing_tab-doc_type   doc_type.
  e_packing_tab-obj_name   'obj name'.
  e_packing_tab-obj_descr  'obj desc'.
  e_packing_tab-doc_size   doc_size.
  APPEND e_packing_tab.





  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                    email_data
      put_in_outbox                    'X'
      commit_work 'X'
    IMPORTING
      sent_to_all                      sent
      new_object_id                    email_id
    TABLES
      packing_list                     e_packing_tab
      object_header                    objhead
      contents_bin                     ftab
      contents_txt                     email_text
*     CONTENTS_HEX                     =
*     OBJECT_PARA                      =
*     OBJECT_PARB                      =
      receivers                        email_send
    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.



  WRITE:/ email_id.
  WRITE:/ sent.
  WRITE:/ sy-subrc.

ENDFORM.                    " SEND
*---------------------------------------------------------------------*
*       FORM UPLOAD                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM upload.

  CALL FUNCTION 'UPLOAD'
    EXPORTING
*     CODEPAGE                      = ' '
      filename                      file
      filetype                      'BIN'
*     ITEM                          = ' '
*     FILEMASK_MASK                 = ' '
*     FILEMASK_TEXT                 = ' '
*     FILETYPE_NO_CHANGE            = ' '
*     FILEMASK_ALL                  = ' '
*     FILETYPE_NO_SHOW              = ' '
*     LINE_EXIT                     = ' '
*     USER_FORM                     = ' '
*     USER_PROG                     = ' '
*     SILENT                        = 'S'
    IMPORTING
*     FILESIZE                      =
*     CANCEL                        =
      act_filename                  act_filename
      act_filetype                  act_filetype
    TABLES
      data_tab                      ftab
*   EXCEPTIONS
*     CONVERSION_ERROR              = 1
*     INVALID_TABLE_WIDTH           = 2
*     INVALID_TYPE                  = 3
*     NO_BATCH                      = 4
*     UNKNOWN_ERROR                 = 5
*     GUI_REFUSE_FILETRANSFER       = 6
*     OTHERS                        = 7
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  DATATYPE i,
        j TYPE i.
  STRLENact_filename ).
  DO TIMES.
    j sy-index 1.
    IF act_filename+j(1'\'.
      j j + 1.
      act_filename act_filename+j.
      EXIT.
    ENDIF.
  ENDDO.
  WRITE:/ act_filename,
          act_filetype.

ENDFORM.                    " UPLOAD
profile

사이트운영 : http://sapjoy.co.kr   http://sapjob.co.kr  

저         서 : Easy ABAP, Plus ABAP

경         험 : SAP ABAP Tuning, SAP SCM(SD/PP/QM/PM/WM/APO)

자         격 : SAP SD / PP  / SAP ABAP Certification 등

메         일 : sapjoy@naver.com