REPORT zemail.
DATA: c(50).
DATA: sent LIKE sonv-flag.
DATA: email_id LIKE sofolenti1-object_id.
DATA: BEGIN OF email_data.
INCLUDE STRUCTURE sodocchgi1.
DATA: END OF email_data.
DATA: BEGIN OF email_send OCCURS 10.
INCLUDE STRUCTURE somlreci1.
DATA: END OF email_send.
DATA: BEGIN OF email_text OCCURS 10.
INCLUDE STRUCTURE solisti1.
DATA: END OF email_text.
DATA: ftab LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA act_filetype LIKE rlgrap-filetype.
DATA act_filename LIKE rlgrap-filename.
SELECT-OPTIONS send_to FOR c NO INTERVALS LOWER CASE.
SELECTION-SCREEN SKIP.
PARAMETERS: subject(30).
SELECTION-SCREEN SKIP.
PARAMETERS: file LIKE rlgrap-filename DEFAULT 'c:temp'.
SELECTION-SCREEN SKIP.
PARAMETERS: l1(84).
PARAMETERS: l2(84).
PARAMETERS: l3(84).
PARAMETERS: l4(84).
PARAMETERS: l5(84).
PARAMETERS: l6(84).
PARAMETERS: l7(84).
PARAMETERS: l8(84).
PARAMETERS: l9(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 0 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.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
objhead = act_filename. APPEND objhead.
DATA: doc_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.
DATA: i TYPE i,
j TYPE i.
i = STRLEN( act_filename ).
DO i TIMES.
j = i - 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
DATA: c(50).
DATA: sent LIKE sonv-flag.
DATA: email_id LIKE sofolenti1-object_id.
DATA: BEGIN OF email_data.
INCLUDE STRUCTURE sodocchgi1.
DATA: END OF email_data.
DATA: BEGIN OF email_send OCCURS 10.
INCLUDE STRUCTURE somlreci1.
DATA: END OF email_send.
DATA: BEGIN OF email_text OCCURS 10.
INCLUDE STRUCTURE solisti1.
DATA: END OF email_text.
DATA: ftab LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA act_filetype LIKE rlgrap-filetype.
DATA act_filename LIKE rlgrap-filename.
SELECT-OPTIONS send_to FOR c NO INTERVALS LOWER CASE.
SELECTION-SCREEN SKIP.
PARAMETERS: subject(30).
SELECTION-SCREEN SKIP.
PARAMETERS: file LIKE rlgrap-filename DEFAULT 'c:temp'.
SELECTION-SCREEN SKIP.
PARAMETERS: l1(84).
PARAMETERS: l2(84).
PARAMETERS: l3(84).
PARAMETERS: l4(84).
PARAMETERS: l5(84).
PARAMETERS: l6(84).
PARAMETERS: l7(84).
PARAMETERS: l8(84).
PARAMETERS: l9(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 0 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.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
objhead = act_filename. APPEND objhead.
DATA: doc_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.
DATA: i TYPE i,
j TYPE i.
i = STRLEN( act_filename ).
DO i TIMES.
j = i - 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
좋은자료 감사합니다~