ITAB data as an mail attachment
Hi all,
I wantto send the ITAB Data as an mail attachment. But i amgetting error. Mail not been sent . What is the mistake i am doing ?
TABLES:adr6.
TYPES: BEGIN OF t_test,
x(3),
y(3),
z(3),
END OF t_test.
DATA: itab TYPE STANDARD TABLE OF t_test,
wa TYPE t_test.
SELECT-OPTIONS : s_rcvr FOR adr6-smtp_addr LOWER CASE VISIBLE LENGTH 30
NO INTERVALS OBLIGATORY.
wa-x = 12.
wa-y = 13.
wa-z = 14.
APPEND wa to itab.
PERFORM send_email.
*& Form send_email
text
--> p1 text
<-- p2 text
form send_email .
DATA : lo_mail_docu TYPE REF TO cl_document_bcs,
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL ,
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL ,
l_oref TYPE REF TO cx_root,
l_message_body TYPE bcsy_text VALUE IS INITIAL,
l_message_line LIKE LINE OF l_message_body,
l_doc_subject TYPE so_obj_des,
l_file_subject TYPE so_obj_des,
l_mail_subject TYPE string,
l_text TYPE string.
DATA itab_bin TYPE TABLE OF solix.
CONCATENATE 'Error' ' Log -' INTO l_doc_subject SEPARATED BY space.
l_mail_subject = l_doc_subject.
CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
TABLES
text_tab = itab
binary_tab = itab_bin.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CONCATENATE 'Attached is the' 'log file generated '
INTO l_message_line-line SEPARATED BY space.
APPEND l_message_line TO l_message_body.
APPEND '' TO l_message_body. APPEND '' TO l_message_body.
TRY.
lo_mail_docu = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_message_body
i_subject = l_doc_subject ).
lo_mail_docu->add_attachment(
EXPORTING
i_attachment_type = 'TXT'
i_attachment_subject = l_file_subject
i_att_content_hex = itab_bin ).
lo_send_request = cl_bcs=>create_persistent( ).
CALL METHOD lo_send_request->set_message_subject
EXPORTING
ip_subject = l_mail_subject.
LOOP AT s_rcvr .
lo_recipient = cl_cam_address_bcs=>create_internet_address( s_rcvr-low ).
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = '' ).
ENDLOOP.
lo_send_request->set_document( lo_mail_docu ).
lo_send_request->set_send_immediately( 'X' ).
lo_send_request->send( ).
CATCH : cx_send_req_bcs INTO l_oref,
cx_document_bcs INTO l_oref,
cx_address_bcs INTO l_oref.
ENDTRY.
COMMIT WORK.
FREE : lo_mail_docu, lo_send_request, lo_sender, lo_recipient, l_oref.
REFRESH : l_message_body, itab_bin.
CLEAR : l_message_line, l_doc_subject, l_mail_subject, l_file_subject,
l_text.
endform.
Thanks in advance
Krupali
Hi,
Pl go through this demo code, its working absolutely fine at my end.. just have a glance on this code.
FIELD-SYMBOLS: <field> TYPE ANY.
DATA : BEGIN OF i_dload OCCURS 0 ,
dload(1000) ,
END OF i_dload .
DATA: it_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
w_object_content LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: w_doc_data LIKE sodocchgi1 OCCURS 0 WITH HEADER LINE.
DATA :w_records TYPE zres_records.
DATA: w_rsnum(10),
w_bdmng(14),
w_meins(4).
*---for internal e_mail address
DATA: ws_email LIKE adr6-smtp_addr.
*--Internal table declaration
DATA: it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: it_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA: w_longtext(255) TYPE c.
DATA: v_date(10) TYPE c.
DATA: text(200) TYPE c.
DATA: w_text(50) TYPE c.
*---declaration for diaplaying msg in the body of mail.
DATA: w_msga(18) TYPE c,
w_msgb(22) TYPE c,
w_msgc(27) TYPE c.
*--Get receipient address
CLEAR it_reclist.
*--To send error to internal mail
ws_email = p_email.
*---setting name of file for csv
CONCATENATE text-003 p_bdoc text-004 INTO w_filename.
to send error file.
IF p_email IS NOT INITIAL.
build body of message
*---text-009 'Errors in file '
CONCATENATE text-009 ' ' INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
CLEAR: w_msga, w_msgb, w_msgc.
w_msga = text-012.
w_msgb = text-013.
w_msgc = text-014.
CONCATENATE w_msga w_msgb w_msgc INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
*---end of code by sparta05_02+
it_reclist-receiver = ws_email.
it_reclist-rec_type = c_u.
it_reclist-express = ' '.
it_reclist-com_type = c_int.
APPEND it_reclist.
Set title of object and email
CLEAR: w_text.
doc_chng-obj_descr = text-005.
doc_chng-obj_name = c_inbound.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
*--Move the Report Name as the Heading line for email file
CLEAR: w_longtext.
*---text-016 contains 'name of report for testing'
w_longtext = text-008.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append Blank Lines
APPEND it_objbin. CLEAR it_objbin.
APPEND it_objbin. CLEAR it_objbin.
---appending heading to Internal table of Email
CLEAR: w_longtext, w_xblnr_1 , w_aubel_1, w_vemng_1,
w_matnr_1, w_harmdesc_1, w_hc_1, w_cooland1_1,
w_brgew_1, w_tknum_1, w_vbeln_1, w_vbeln1_1,
w_exidv_1, w_vhilm_1, w_pack_no_1,
w_brgew1_1, w_laeng_1, w_breit_1,
w_hoehe_1, w_vol_1,
w_gr_wt_1,
w_ni_wt_1,
w_imp_ln_1,
w_imp_wd_1,
w_imp_ht_1,
w_cu_ft_1.
w_xblnr_1 = 'Cust PO'.
w_aubel_1 = 'Order'.
w_vemng_1 = 'Qty'.
w_matnr_1 = 'Part#'.
w_harmdesc_1 = 'Harm Desc'.
w_hc_1 = 'HTS#'.
w_cooland1_1 = 'COO'.
w_brgew_1 = 'NW(KG)'.
w_tknum_1 = 'Ship ID'.
w_vbeln_1 = 'Bill#'.
w_vbeln1_1 = 'Delivery#'.
w_exidv_1 = 'ID#'.
w_vhilm_1 = 'Pkg'.
w_pack_no_1 = 'PCS'.
w_brgew1_1 = 'GW(KG)'.
w_laeng_1 = 'L(CM)'.
w_breit_1 = 'W(CM)'.
w_hoehe_1 = 'H(CM)'.
w_vol_1 = 'CBM'.
w_gr_wt_1 = 'GW(LB)'. "added by sparta01_01+
w_ni_wt_1 = 'NW(LB)'. "added by sparta05_04+
w_imp_ln_1 = 'L(IN)'.
w_imp_wd_1 = 'W(IN)'.
w_imp_ht_1 = 'H(IN)'.
w_cu_ft_1 = 'CUFT'.
CONCATENATE w_xblnr_1 w_aubel_1 w_vemng_1
w_matnr_1 w_harmdesc_1 w_hc_1 w_cooland1_1
w_brgew_1
w_tknum_1 w_vbeln_1 w_vbeln1_1
w_exidv_1 w_vhilm_1 w_pack_no_1
w_brgew1_1 w_laeng_1 w_breit_1
w_hoehe_1
w_vol_1
w_gr_wt_1 "added by sparta01_01+
w_ni_wt_1 "added by sparta05_04+
w_imp_ln_1 w_imp_wd_1
w_imp_ht_1
w_cu_ft_1
INTO w_longtext SEPARATED BY c_cma.
" changed by sparta05_03+ c_cma for ','.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append the details to Internal table of Email
LOOP AT it_tab.
DO .
*---to avoid display of error column
IF sy-index = c_25. "changed by sparta05_03+ (c_31 to c_25)
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
SEARCH <field> FOR ',' IN CHARACTER MODE.
If search for commas was successful.
IF sy-subrc = 0.
REPLACE ALL OCCURRENCES OF ','
IN <field> WITH space . "added by sparta05_04+
ENDIF.
IF sy-index = 1.
i_dload-dload = <field>.
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONDENSE i_dload-dload .
ELSE.
Put Comma as a separator for values in IT_DLOAD internal table
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONDENSE i_dload-dload .
CONCATENATE i_dload-dload <field> INTO i_dload-dload
SEPARATED BY c_cma IN CHARACTER MODE.
"changed by sparta05_03+ c_cma for ','
ENDIF.
ENDDO.
it_objbin = i_dload-dload.
APPEND it_objbin. CLEAR it_objbin.
IF NOT it_tab-error IS INITIAL.
it_objtxt+0(18) = it_tab-matnr.
it_objtxt+21(41) = it_tab-exidv.
it_objtxt+46(66) = it_tab-error.
APPEND it_objtxt.
CLEAR it_objtxt.
ENDIF.
ENDLOOP.
flag = 0.
ENDIF.
-Convert to correct format----
CALL FUNCTION 'SO_RAW_TO_RTF'
TABLES
objcont_old = it_objbin
objcont_new = it_objbin.
create the control table entry for the main email
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR it_objpack-transf_bin.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = c_raw.
APPEND it_objpack.
DESCRIBE TABLE it_objbin LINES tab_lines.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-transf_bin = c_x.
it_objpack-doc_type = c_csv.
it_objpack-obj_descr = w_filename.
it_objpack-obj_name = c_billing. "code added by sparta05_02+
it_objpack-doc_size = tab_lines * 255.
APPEND it_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
PUT_IN_OUTBOX = c_x
commit_work = c_x
TABLES
packing_list = it_objpack
object_header = it_objhead
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
WRITE: / 'failure in sending mail'.
ELSE.
IF flag = 0.
MESSAGE s999(pp) WITH text-007.
ENDIF.
IF flag = 1.
MESSAGE s999(pp) WITH text-006.
ENDIF.
ENDIF.
ENDFORM. " p_send_email
Thanks,
Krishna
Similar Messages
-
Sending mail attachment as XML file
Hi Experts,
I have a XML in an ITAB.
I want to send this data as a mail attachment, any body help, if any one have sample code please send me.
Thanks,
Regards
Venkathi
chk the sample code
REPORT ZMAIL_XLS NO STANDARD PAGE HEADING.
Data for mailing purpose
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER
LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER
LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER
LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER
LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER
LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
Data required for preparing XLS type attachment
DATA: V_TABS TYPE X VALUE '09',
V_NEW_LINE TYPE X VALUE '0D'.
START-OF-SELECTION.
Prepare data to send
PERFORM PREPARE_DATA.
Send mail with XLS attachment
PERFORM SEND_MAIL.
*& Form send_mail
form send_mail.
Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'TEST'.
DOC_CHNG-OBJ_DESCR = 'TEST MAIL WITH XLS
ATTACHMENT'. "mail subject
OBJTXT = 'Test mail with XLS attachment'.
APPEND OBJTXT.
CLEAR OBJTXT.
APPEND OBJTXT.
APPEND OBJTXT.
OBJTXT = 'Please double click the attachment to
verify'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 +
STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Sample XLS attachement'. "
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'XLS'.
OBJPACK-OBJ_NAME = 'TEST'.
OBJPACK-OBJ_DESCR = 'Test.XLS'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
For sending mail to Internet Address
RECLIST-RECEIVER = '[email protected]'.
RECLIST-REC_TYPE = 'U'.
For sending mail to SAP user ID
RECLIST-RECEIVER = 'fing087'.
RECLIST-REC_TYPE = 'B'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE :/ 'MAIL SENT....'.
WHEN 1.
WRITE :/ 'TOO MANY RECEIVERS'.
WHEN 2.
WRITE :/ 'DOCUMENT NOT SENT'.
WHEN 4.
WRITE :/ 'NO SEND AUTHORIZATION'.
WHEN OTHERS.
WRITE :/ 'ERROR OCCURED WHILE SENDING
MAIL'.
ENDCASE.
endform. " send_mail
*& Form PREPARE_DATA
FORM PREPARE_DATA.
CONCATENATE 'NAME'
'ADDRESS'
'PHONE'
INTO OBJBIN-LINE
SEPARATED BY V_TABS.
APPEND OBJBIN.
CLEAR OBJBIN.
CONCATENATE 'Hajira'
'MIG-2022'
'23025487'
INTO OBJBIN-LINE SEPARATED BY V_TABS.
CONCATENATE V_NEW_LINE OBJBIN-LINE INTO
OBJBIN-LINE .
APPEND OBJBIN.
CLEAR OBJBIN.
CONCATENATE 'Faiz'
'MIG-2022'
'23025487'
INTO OBJBIN-LINE SEPARATED BY V_TABS.
CONCATENATE V_NEW_LINE OBJBIN-LINE INTO
OBJBIN-LINE .
APPEND OBJBIN.
CLEAR OBJBIN.
ENDFORM. " PREPARE_DATA
**reward if helpful
regards,
madhumitha -
Getting mail attachment as win mail.dat
Hi,
I have gone through lots of duscussion and note on this but unfortunately i am still with the same problem and not able to use my apple mail. I can access the same attachment through my webmail login but cant access it from my apple mail client this always shows like winmail.dat and inspite of all the discussion on same topic why apple team is not able to provide the solution for the same.
If any one has idea to resolve the same pls ..The problem is with Outlook on the PC. Whoever is sending messages is sending them as "rich text" which encapsulates them in a Winmail.dat file inside a MIME component of the message.
There are 2 options you have:
1) Tell the sender of the email to use plain text or HTML instead of rich text as their default format in Outlook. There is a setting for this, and they should use it as good email hygiene.
2) You could use a mail plugin like "letter opener" or equivalent (just Google search for winmail.dat os x mail). This should let you view them, though Mail's stability could suffer because plugins are not supported. -
XLS as MAIL attachment....points Guranteed
I am sending one xls file as mail attachment.
The following code is sending the mail pefectly, but the attchment appears with a different icon, not as xls icon in the attchment, as it normaly does if we use so00 for sending a xls attchment thorugh mail.
If i download the xls attchment in local pc after opening the mail, it does open with Excel application, but if double click on it in the mail itself, its not opening in normal text format in sap text-editor in read only mode, not as xls file.I suspect something is wrong...here is the code..please let me know about your suggestion..
For Max, and those who answered my last question, i will reward point to deserving answer after this post.. i got disconnected while surfing...sory for the delay.
REPORT ZEMAIL_ATTACH .
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT '[email protected]'.
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODYSorry for a mistake...this the code..i was talking about
REPORT ztest3.
E-mail an Abap report *
DATA : w_name TYPE sos04-l_adr_name.
SELECT-OPTIONS :
Recipient address
s_name FOR w_name DEFAULT sy-uname NO INTERVALS.
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
START-OF-SELECTION.
E-mail Abap report
PERFORM CREATE_XLS_FILE_DATA.
PERFORM f_send_mail.
Form f_send_mail
FORM f_send_mail.
Data Declaration
DATA:
l_datum(10),
ls_docdata TYPE sodocchgi1,
lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,
l_tab_lines TYPE i,
l_att_type LIKE soodk-objtp.
WRITE sy-datum TO l_datum.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
ls_docdata-obj_name = 'Sample Records From Ekpo in XLS Format'.
CONCATENATE 'Sample Records From Ekpo' 'In XLS FORMAT'
into ls_docdata-obj_descr SEPARATED BY space.
Main Text
lt_objtxt = 'Sample Records From Ekpo in XLS Format'. "#EC *
APPEND lt_objtxt.
Write Packing List (Main)
DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
READ TABLE lt_objtxt INDEX l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
CLEAR lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
APPEND lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
LT_OBJHEAD = 'TEST.XLS'.
APPEND LT_OBJHEAD.
DESCRIBE TABLE it_attach LINES l_tab_lines.
READ TABLE it_attach INDEX l_tab_lines.
lt_objpack-doc_size = l_tab_lines * 255.
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 1.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'TEST.XLS'. "#EC *
APPEND lt_objpack.
Create receiver list
LOOP AT s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'B'.
APPEND lt_reclist.
ENDLOOP.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
put_in_outbox = ''
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = it_attach
contents_txt = lt_objtxt
receivers = lt_reclist
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.
Document sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.
ELSE.
Document <&> could not be sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH ls_docdata-obj_name.
ENDIF.
ENDFORM. " F_SEND_MAIL
*& Form CREATE_XLS_FILE_DATA
form CREATE_XLS_FILE_DATA .
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
" DATA_RETRIEVAL
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
" BUILD_XLS_DATA_TABLE
endform. " CREATE_XLS_FILE_DATA -
Sending smartform output as mail attachment (PDF)
Hi,
I am trying to send a smartform output in PDF format as a mail attachment. This has to be fired in the save of a Invoice.. configured by the output type.
Here is the code which i have .. and it does not work.
DATA: ls_bil_invoice TYPE lbbil_invoice.
tables: nast.
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
wa_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng typE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
call function 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSDDLB_BIL_INVOICE'
IMPORTING
fm_name = v_form_name
EXCEPTIONS
no_form = 1
no_function_module = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = 'X'
IMPORTING
job_output_info = w_return
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
i_otf[] = w_return-otfdata[].
call function 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
if sy-subrc EQ 0.
endif.
Convert PDF from 132 to 255.
loop at i_tline.
translate i_tline using '~'.
concatenate wa_buffer i_tline into wa_buffer.
endloop.
translate wa_buffer using '~'.
do.
i_record = wa_buffer.
append i_record.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
refresh:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear wa_objhead.
Object with PDF.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES v_lines_bin.
Object with main text of the mail.
i_objtxt = 'Find attached the output of the smart form.'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
wa_doc_chng-obj_name = 'Smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'Smart form output'.
wa_doc_chng-sensitivty = 'F'. "Functional object
wa_doc_chng-doc_size = v_lines_txt * 255.
Pack to main body as RAW.
Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
Start line of object header in transport packet Smart Forms
i_objpack-head_start = 1.
Number of lines of an object header in object packet
i_objpack-head_num = 0.
Start line of object contents in an object packet
i_objpack-body_start = 1.
Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Smartform_output' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = '[email protected]'.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = wa_objhead
CONTENTS_BIN = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
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 EQ 0.
ENDIF.Hi Aviroop,
Compare your part of code with the below given code.
*& Report YSSN_SIMPLE_SMARTFORM *
report zhr_bhaskar_pdf_to_email message-id zmsg.
parameters: p_vbeln type vbak-vbeln default '35'.
data: it_items type table of vbap,
v_fm_name type rs38l_fnam,
v_tot_lines type i,
v_sy_tabix type i,
output_data type ssfcrescl. " To hold Output information
constants:
c_sep type c value '-', " Value -
c_x type c value 'X', " Value X
c_space type c value ' '. " Space
*****MAIL START
include .
data: g_mail_rec_obj type swotobjid,
g_mail_sen_obj type swotobjid,
g_mail_app_obj type swotobjid,
g_cont_par type ssfctrlop,
folder type swc_object,
begin of sofmfol_key,
foldertype like sofm-foltp,
folderyear like sofm-folyr,
foldernumber like sofm-folno,
type like sofm-doctp,
year like sofm-docyr,
number like sofm-docno,
forwarder like soub-usrnam,
end of sofmfol_key,
bor_key like swotobjid-objkey,
g_mail TYPE ppfdmailad VALUE '[email protected]',
g_mail type so_name value '[email protected]',
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_rectype type so_escape value 'U'. " 'B'.
data: job_output_info type ssfcrescl,
hotfdata like itcoo occurs 1 with header line,
htline like tline occurs 1 with header line,
x_objcont like soli occurs 1 with header line,
ld_packing_list like soxpl occurs 1 with header line,
x_object_hd_change like sood1 occurs 1 with header line,
x_objhead like soli occurs 1 with header line,
x_receivers like soos1 occurs 1 with header line,
format_pdf(10) value 'PDF',
doc_size(12) type c,
hltlines type i,
htabix like sy-tabix,
fle1(2) type p,
fle2(2) type p,
off1 type p,
hfeld(500) type c.
tables: soud.
*****MAIL END
select *
into table it_items
from vbap
where vbeln = p_vbeln.
if it_items[] is initial.
exit.
endif.
perform call_smartform.
*& Form call_smartform
text
--> p1 text
<-- p2 text
form call_smartform .
*DATA: lx_control_parameters TYPE SSFCTRLOP,
lx_OUTPUT_OPTIONS type SSFCOMPOP.
lx_OUTPUT_OPTIONS-TDIMMED = ' '.
lx_OUTPUT_OPTIONS-TDfinal = 'X'.
lx_OUTPUT_OPTIONS-TDDELETE = 'X'.
lx_CONTROL_PARAMETERS-NO_CLOSE = 'X'.
lx_CONTROL_PARAMETERS-NO_OPEN = ' '.
data: x_ssfcompop type ssfcompop,
x_ssfctrlop like ssfctrlop,
x_ssfcrescl type ssfcrescl.
**MAIL
g_cont_par-langu = sy-langu.
g_cont_par-no_dialog = 'X'.
g_cont_par-getotf = 'X'.
g_cont_par-device = 'MAIL'.
Get BOR-Objects for Recipient, Sender und Applikation
perform mail_recipient_object changing g_mail_rec_obj.
perform mail_sender_object changing g_mail_sen_obj.
perform mail_appl_object changing g_mail_app_obj.
**MAIL
*--Internal table is having more than 1 record
if v_tot_lines gt 1.
if v_sy_tabix = 1.
*--For first record of table
x_ssfctrlop-no_open = c_space.
x_ssfctrlop-no_close = c_x.
elseif v_sy_tabix = v_tot_lines.
*--For last record of table
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_space.
else.
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_x.
endif.
endif.
IF r_previ = c_x.
x_ssfctrlop-preview = c_x.
x_ssfctrlop-getotf = c_x.
ENDIF.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'YSSN_SMARTFORM'
VARIANT = ' '
DIRECT_CALL = ' '
importing
fm_name = v_fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
if sy-subrc <> 0.
message i000 with 'Smart form module name failure'.
exit.
endif.
CALL FUNCTION '/1BCDWB/SF00000199'
call function v_fm_name
exporting
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = g_cont_par
mail_appl_obj = g_mail_app_obj
mail_recipient = g_mail_rec_obj
mail_sender = g_mail_sen_obj
OUTPUT_OPTIONS = lx_OUTPUT_OPTIONS
USER_SETTINGS = 'X'
t_vbap = it_items
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = job_output_info
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
perform send_pdf_mail.
endform. " call_smartform
*& Form send_pdf_mail
text
--> p1 text
<-- p2 text
form send_pdf_mail .
data ld_binfile type xstring.
pdf_table type rcl_bag_tline,
data: ld_originator like soos1-recextnam.
convert form
loop at job_output_info-otfdata into hotfdata.
append hotfdata.
endloop.
call function 'CONVERT_OTF'
exporting
format = format_pdf
max_linewidth = 132
importing
bin_filesize = doc_size
bin_file = ld_binfile
tables
otf = output_data-otfdata
lines = htline
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
*-Itab 134 Zeichen nach 255 Zeichen überführen
describe table htline lines hltlines.
describe field htline length fle1 in character mode.
describe field x_objcont length fle2 in character mode.
loop at htline.
htabix = sy-tabix.
move htline to hfeld+off1.
if htabix = hltlines.
fle1 = strlen( htline ).
endif.
off1 = off1 + fle1.
if off1 ge fle2.
clear x_objcont.
x_objcont = hfeld(fle2).
append x_objcont.
shift hfeld by fle2 places.
off1 = off1 - fle2.
endif.
if htabix = hltlines.
if off1 gt 0.
clear x_objcont.
x_objcont = hfeld(off1).
append x_objcont.
endif.
endif.
endloop.
x_object_hd_change-objnam = 'EMAIL'.
x_object_hd_change-objdes = 'Smart Form'.
x_object_hd_change-objla = sy-langu.
x_object_hd_change-objsns = 'O'.
x_object_hd_change-objlen = doc_size.
x_object_hd_change-file_ext = 'TXT'.
ld_packing_list-transf_bin = 'X'.
ld_packing_list-head_start = 1.
ld_packing_list-head_num = 0.
ld_packing_list-body_start = 1.
describe table x_objcont lines ld_packing_list-body_num.
ld_packing_list-objtp = 'EXT'.
ld_packing_list-objdes = 'Smart Form'.
ld_packing_list-objla = sy-langu.
ld_packing_list-objlen = doc_size.
ld_packing_list-file_ext = 'PDF'.
append ld_packing_list.
x_receivers-recextnam = g_mail.
x_receivers-recesc = 'E'.
x_receivers-sndart = 'INT'.
append x_receivers.
ld_originator = '[email protected]'.
ld_originator = FSABE-USRNAM.
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = x_object_hd_change
object_type = 'RAW'
originator_type = 'B' "Einfügen
originator = ld_originator "Einfügen
tables
objcont = ld_text
receivers = x_receivers
packing_list = ld_packing_list
att_cont = x_objcont
att_head = x_objhead
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
x_error = 20
others = 21.
endform. " send_pdf_mail
*& Form mail_sender_object
text
<--P_G_MAIL_SEN_OBJ text
form mail_sender_object changing p_mail_sen_obj.
call function 'CREATE_SENDER_OBJECT_PPF'
exporting
ip_sender = sy-uname
importing
ep_sender_id = p_mail_sen_obj
exceptions
invalid_sender = 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.
endform. " mail_sender_object
*& Form mail_appl_object
text
<--P_G_MAIL_APP_OBJ text
form mail_appl_object changing p_mail_app_obj.
SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
ENDSELECT.
IF sy-subrc NE 0.
call function 'SO_USER_AUTOMATIC_INSERT'
exporting
sapname = sy-uname
exceptions
no_insert = 1
sap_name_exist = 2
x_error = 3
others = 4.
if sy-subrc ne 0.
clear soud.
else.
select * from soud where sapnam like sy-uname and deleted = ' '.
endselect.
endif.
ENDIF.
clear sofmfol_key.
sofmfol_key-type = 'FOL'.
sofmfol_key-year = soud-inbyr.
sofmfol_key-number = soud-inbno.
bor_key = sofmfol_key.
if not bor_key is initial.
swc_create_object folder 'SOFMFOL' bor_key.
if sy-subrc = 0.
swc_object_to_persistent folder p_mail_app_obj.
if sy-subrc ne 0.
clear p_mail_app_obj.
endif.
endif.
else.
clear p_mail_app_obj.
endif.
endform. " mail_appl_object
*& Form mail_recipient_object
text
<--P_G_MAIL_REC_OBJ text
form mail_recipient_object changing p_mail_rec_obj.
call function 'CREATE_RECIPIENT_OBJ_PPF'
exporting
IP_COUNTRY =
IP_FAXNO =
ip_mailaddr = g_mail
ip_type_id = g_rectype " 'U'
importing
ep_recipient_id = p_mail_rec_obj
EP_ADDRESS =
ET_RECIPIENT =
exceptions
invalid_recipient = 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.
endform. " mail_recipient_object
I hope this code should definitely work and helps you a lot.
Do reward me if it helps you.
Cheers,
Sampath -
Hi,
im working on sending report output as mail attachment in pdf format..
but im not getting the required output,,,i.e., even after entering email addresses in the selection screen....im not getting any mail to the respective mail-ids..
im pasting the code..pls fix the problem..
pls let me know wat we have to do in SCOT transaction after executing the program....pls respond ..pls ..
TABLES : t001, "COMPANY CODE
knb1, "CUSTOMER MASTER(COMPANY CODE)
cdhdr, "CHANGE DOCUMENT HEADER
knkk, "CUSTOMER MASTER CREDIT MANAGEMENT: CONTROL AREA DATA
kna1, "GENERAL DATA IN CUSTOMER MASTER
adrc, "ADDRESSES (BUSINESS ADDRESS SERVICES)
t001s, "ACCOUNTING CLERKS
adrt, "COMMUNICATION DATA TEXT (BUSINESS ADDRESS SERVICES)
adr6. "E-MAIL ADDRESSES (BUSINESS ADDRESS SERVICES)
TABLES: itcpo, "SAPscript output interface
itcpp. "SAPscript output parameters
TYPES: BEGIN OF y_t001,
bukrs TYPE bukrs,
kkber TYPE kkber,
adrnr TYPE adrnr,
END OF y_t001.
TYPES: BEGIN OF y_cust,
p_objectid TYPE cdobjectv,
END OF y_cust.
TYPES: BEGIN OF y_knkk,
kunnr TYPE kunnr,
kkber TYPE kkber,
dtrev TYPE dtrev_cm,
nxtrv TYPE nxtrv_cm,
klimk TYPE klimk,
dbwae TYPE dbwae_cm,
END OF y_knkk.
TYPES: BEGIN OF y_customer,
kunnr TYPE kunnr,
adrnr TYPE adrnr,
END OF y_customer.
TYPES: BEGIN OF y_custo ,
kunnr TYPE kunnr,
name TYPE name1_gp,
kkber TYPE kkber,
END OF y_custo.
TYPES: BEGIN OF y_knkk1,
kunnr LIKE knkk-kunnr,
dtrev LIKE knkk-dtrev,
nxtrv LIKE knkk-nxtrv,
klimk LIKE knkk-klimk,
END OF y_knkk1.
TYPES: BEGIN OF y_report_display,
kunnr TYPE kunnr,
name TYPE name1_gp,
dtrev TYPE dtrev_cm,
nxtrv TYPE nxtrv_cm,
klimk TYPE klimk,
dbwae TYPE dbwae_cm,
END OF y_report_display.
TYPES: BEGIN OF y_adrt,
addrnumber TYPE adrnr,
comm_type TYPE ad_comm,
remark TYPE ad_remark2,
persnumber TYPE ad_persnum,
date_from TYPE ad_date_fr,
consnumber TYPE ad_consnum,
smtp_addr TYPE ad_smtpadr,
END OF y_adrt.
*TYPES : BEGIN OF y_adr6,
addrnumber TYPE ad_addrnum,
persnumber TYPE ad_persnum,
date_from TYPE ad_date_fr,
consnumber TYPE ad_consnum,
smtp_addr TYPE ad_smtpadr,
END OF y_adr6.
*TYPES: BEGIN OF y_addr,
addrnumber TYPE adrnr,
name1 TYPE ad_name1,
postcode TYPE ad_pstcd1,
city1 TYPE ad_city1,
street TYPE ad_street,
housenum TYPE ad_hsnm1,
telnum TYPE ad_tlnmbr1,
faxnum TYPE ad_fxnmbr1,
END OF y_addr.
TYPES: BEGIN OF y_custnam,
adrnr TYPE adrnr,
name2 TYPE ad_name1,
END OF y_custnam.
TYPES: BEGIN OF y_kna1,
kunnr TYPE kunnr,
adrnr TYPE adrnr,
name1 TYPE name1,
END OF y_kna1.
TYPES: BEGIN OF y_knb1,
kunnr TYPE kunnr,
bukrs TYPE bukrs,
busab TYPE busab,
END OF y_knb1.
TYPES: BEGIN OF y_clv,
dtrev TYPE dtrev_cm,
nxtrv TYPE nxtrv_cm,
klimk TYPE klimk,
END OF y_clv.
TYPES: BEGIN OF y_ccname,
sname TYPE t001s-sname,
END OF y_ccname.
*TYPES DECLARATION FOR DESIGING SCRIPT
TYPES : BEGIN OF y_adrc,
addrnumber LIKE adrc-addrnumber,
name1 LIKE adrc-name1,
post_code1 LIKE adrc-post_code1,
city1 LIKE adrc-city1,
street LIKE adrc-street,
house_num1 LIKE adrc-house_num1,
tel_number LIKE adrc-tel_number,
nation LIKE adrc-nation ,
fax_number LIKE adrc-fax_number,
country LIKE adrc-country,
END OF y_adrc.
*TO GET C1 (CUSTOMER NAME IN RUSSIAN
TYPES : BEGIN OF y_adrc1,
addrnumber LIKE adrc-addrnumber,
name1 LIKE adrc-name1,
nation LIKE adrc-nation,
END OF y_adrc1.
*TO GET C7
TYPES :BEGIN OF y_t001s,
bukrs LIKE t001s-bukrs, "Company Code
busab LIKE t001s-busab,
sname LIKE t001s-sname,
END OF y_t001s.
CONSTANTS:
c_printer LIKE itcpp-tddevice VALUE 'PRINTER',
c_true(1) TYPE c VALUE 'X',
c_1(1) TYPE n VALUE '1',
c_pdf_format(3) TYPE c VALUE 'PDF',
c_u LIKE soos1-recesc VALUE 'U',
c_recipient_name LIKE soos1-recnam VALUE 'U-',
c_english LIKE sy-langu VALUE 'E',
c_f LIKE sood1-objsns VALUE 'F',
c_int(3) TYPE c VALUE 'INT',
c_main(4) TYPE c VALUE 'ITEM',
c_main_window(4) TYPE c VALUE 'MAIN',
c_header(6) TYPE c VALUE 'HEADER',
c_minus_sign(1) TYPE c VALUE '-',
c_document_type LIKE sood-objtp VALUE 'EXT',
c_space(1) TYPE c VALUE ' '.
DATA t_result LIKE itcpp.
DATA :w_t001 TYPE t001,
w_custo TYPE y_custo,
w_knkk TYPE y_knkk,
w_cust TYPE y_cust,
w_customer TYPE y_customer,
w_report_display TYPE y_report_display,
w_addr TYPE y_addr,
w_custnam TYPE y_custnam,
w_adrt TYPE y_adrt,
w_adr6 TYPE y_adr6,
w_kna1 TYPE y_kna1,
w_knb1 TYPE y_knb1,
w_clv TYPE y_clv,
w_ccname TYPE y_ccname.
DATA: w_error_found(1) TYPE c,
w_key_date_text(30) TYPE c,
w_total(10) TYPE p DECIMALS 2,
w_htddevice LIKE itcpp-tddevice.
DATA: E_PROFILE LIKE SOPRD.
DATA: t_t001 TYPE STANDARD TABLE OF y_t001,
t_custo TYPE STANDARD TABLE OF y_custo,
t_knkk TYPE STANDARD TABLE OF y_knkk,
t_cust TYPE STANDARD TABLE OF y_cust,
t_customer TYPE STANDARD TABLE OF y_customer,
t_report_display TYPE STANDARD TABLE OF y_report_display,
t_addr TYPE STANDARD TABLE OF y_addr,
t_custnam TYPE STANDARD TABLE OF y_custnam,
t_adrt TYPE STANDARD TABLE OF y_adrt,
t_adr6 TYPE STANDARD TABLE OF y_adr6,
t_kna1 TYPE STANDARD TABLE OF y_kna1,
t_knb1 TYPE STANDARD TABLE OF y_knb1,
t_clv TYPE STANDARD TABLE OF y_clv,
t_ccname TYPE STANDARD TABLE OF y_ccname.
DATA : number LIKE spell,
amount(1000) TYPE c.
For storing error log
DATA: BEGIN OF t_error OCCURS 0,
kunnr LIKE kna1-kunnr,
comm(30) TYPE c,
END OF t_error.
For storing customer's email address
DATA: BEGIN OF t_email OCCURS 0,
smtp_addr LIKE adr6-smtp_addr,
END OF t_email.
To be used in the function to send a layout via email
DATA: t_otfdata LIKE itcoo OCCURS 0 WITH HEADER LINE,
t_htline LIKE tline OCCURS 0 WITH HEADER LINE.
DATA DECLARATIONS FOR DESIGING SCRIPT
DATA : it_t001 TYPE STANDARD TABLE OF y_t001,
wa_t001 TYPE y_t001.
DATA : it_adrc TYPE STANDARD TABLE OF y_adrc,
wa_adrc type y_adrc.
DATA : it_adrc1 TYPE STANDARD TABLE OF y_adrc1,
wa_adrc1 TYPE y_adrc1.
DATA : it_knb1 TYPE STANDARD TABLE OF y_knb1,
wa_knb1 TYPE y_knb1.
DATA : it_kna1 TYPE STANDARD TABLE OF y_kna1,
wa_kna1 TYPE y_kna1.
DATA : it_knkk TYPE STANDARD TABLE OF y_knkk,
wa_knkk TYPE y_knkk.
DATA : it_knkk1 TYPE STANDARD TABLE OF y_knkk1,
wa_knkk1 TYPE y_knkk1.
DATA : it_t001s TYPE STANDARD TABLE OF y_t001s,
wa_t001s TYPE y_t001s.
*DATA STATEMENTS FOR EMAIL ADDRESSES
DATA : it_adrt TYPE TABLE OF y_adrt,
wa_adrt TYPE y_adrt,
wa_email LIKE t_email.
*DATA : it_adr6 TYPE TABLE OF y_adr6,
wa_adr6 TYPE y_adr6,
DATA : counter TYPE i,
counter1 TYPE i,
c5 LIKE spell.
SELECTION-SCREEN BEGIN OF BLOCK clcn WITH FRAME TITLE text-200.
SELECTION-SCREEN SKIP.
PARAMETERS: p_bukrs LIKE t001-bukrs OBLIGATORY, "COMPANY CODE
p_kkber LIKE t001-kkber OBLIGATORY. "CREDIT CONTROL AREA
SELECT-OPTIONS: s_kunnr FOR knb1-kunnr OBLIGATORY, "CUSTOMER NUMBER
s_datum FOR sy-datum OBLIGATORY DEFAULT sy-datum. "DATE OF CREDIT LIMIT UPDATE
SELECTION-SCREEN SKIP.
PARAMETERS : p_simul AS CHECKBOX DEFAULT 'X'. "RUN IN SIMULATION MODE
SELECTION-SCREEN SKIP.
PARAMETERS : p_lemail LIKE adr6-smtp_addr. " EMAIL
SELECTION-SCREEN END OF BLOCK clcn.
AT SELECTION-SCREEN.
PERFORM f0100_validate_bukrs. "* For Company Code.
PERFORM f0200_validate_kkber. "* For Credit Control Area.
PERFORM f0300_validate_kunnr. "* For Customer Number
PERFORM f0400_validate_datum. "* For Date of Credit Limit Update
PERFORM f0500_validate_simul. "* For simulation mode and e-mail address
*======================================================================
START-OF-SELECTION.
PERFORM f1000_get_customer. "** COLLECT INFO FOR REPORT DISPLAY
IF p_simul is initial AND NOT P_lemail IS INITIAL.
PERFORM F1000_CHECK_GATEWAY_CONNECTION.
ENDIF.
IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL.
PERFORM f3000_process_data_script USING t_report_display.
ENDIF.
END-OF-SELECTION.
IF NOT p_simul IS INITIAL.
PERFORM f2000_display_customer USING t_report_display.
ENDIF.
FORM f0100_validate_bukrs.
DATA : w_bukrs TYPE bukrs.
VALIDATION OF P_BUKRS
SELECT SINGLE bukrs
FROM t001
INTO w_bukrs
WHERE bukrs EQ p_bukrs.
IF sy-subrc NE 0.
MESSAGE e999(zf) WITH 'Invalid Company Code' p_bukrs. "(E01).
*AUTHORIZATION CHECK
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD p_bukrs
ID 'ACTVT' FIELD '03'.
IF sy-subrc NE 0.
MESSAGE e999(zf) WITH 'No Authorization for company code' p_bukrs."(e06).
ENDIF.
ENDIF.
ENDFORM. " F0100_VALIDATE_BUKRS
*Eject
*& Form F0200_VALIDATE_KKBER
*-> CREDIT CONTROL AREA AUTHORITY CHECK
FOR CREDIT CONTROL AREA.
FORM f0200_validate_kkber.
DATA : w_kkber LIKE t001-kkber.
SELECT SINGLE kkber
FROM t001
INTO w_kkber
WHERE bukrs EQ p_bukrs
AND kkber EQ p_kkber.
IF sy-subrc NE 0.
MESSAGE e999(zf) WITH
'Credit Control Area' p_kkber 'not defined for Company Code' p_bukrs."(e02).
MESSAGE e999 WITH text-e02 p_kkber .
ENDIF.
ENDFORM. "F0200_VALIDATE_KKBER
*& Form F0300_VALIDATE_KUNNR
*-> CUSTOMER NUMBER AUTHORITY CHECK
FORM f0300_validate_kunnr.
VALIDATION OF S_KUNNR
DATA : w_kunnr TYPE kunnr,
w_bukrs TYPE bukrs.
IF s_kunnr IS INITIAL .
MESSAGE e999 WITH 'Enter Customer Number'(e04).
SUBMIT (sy-cprog) VIA SELECTION-SCREEN.
ENDIF.
LOOP AT s_kunnr.
CLEAR : w_kunnr,
w_bukrs.
IF NOT s_kunnr-low IS INITIAL.
SELECT SINGLE kunnr bukrs
FROM knb1 INTO (w_kunnr ,w_bukrs)
WHERE kunnr EQ s_kunnr-low
AND bukrs EQ p_bukrs.
IF sy-subrc NE 0.
MESSAGE e999(zf) WITH 'Customer S_KUNNR-LOW not defined in company code' p_bukrs."(e03).
ENDIF.
ENDIF. "if not s_kunnr-low is initial.
IF NOT s_kunnr-high IS INITIAL.
CLEAR : w_kunnr,
w_bukrs.
SELECT SINGLE kunnr bukrs
FROM knb1 INTO (w_kunnr , w_bukrs)
WHERE kunnr EQ s_kunnr-high
AND bukrs EQ p_bukrs.
IF sy-subrc NE 0.
MESSAGE e999(zf) WITH 'Customer S_KUNNR-HIGH not defined in company code' p_bukrs."(e03).
ENDIF.
ENDIF. "if not s_kunnr-high is initial.
ENDLOOP. " loop at s_kunnr
ENDFORM. " F0200_VALIDATE_KUNNR
*& Form F0400_VALIDATE_DATUM
*-> DATE OF CREDIT LIMIT UPDATE
FORM f0400_validate_datum.
IF s_kunnr IS INITIAL AND s_datum IS INITIAL.
MESSAGE e999 WITH 'Enter either Date of CL update or Customer number.'(e04).
ENDIF.
ENDFORM. "F0400_VALIDATE_DATUM
*& Form F1000_GET_CUSTOMER
text
--> p1 text
<-- p2 text
FORM f1000_get_customer .
DATA : w_kunnr LIKE knkk-kunnr,
w_kkber LIKE knkk-kkber.
IF s_datum IS NOT INITIAL.
SELECT objectid
FROM cdhdr
INTO TABLE t_cust
WHERE objectclas IN ('KLIM','DTREV','NXTRV')
AND change_ind IN ('U','I')
AND udate IN s_datum.
WHERE ( objectclas EQ 'KLIM' OR objectclas EQ 'DTREV' OR objectclas EQ 'NXTRV')
AND ( change_ind EQ 'U' OR change_ind EQ 'I')
AND udate IN s_datum .
ENDIF.
IF sy-subrc NE 0.
MESSAGE s999 WITH 'There is no data for selected period'(e07).
ELSE.
MOVE t_cust TO t_customer.
ENDIF.
SORT t_customer BY kunnr.
IF NOT t_customer[] IS INITIAL.
SELECT kunnr
kkber
dtrev
nxtrv
klimk
dbwae
FROM knkk
INTO TABLE t_knkk
FOR ALL ENTRIES IN t_customer
WHERE kunnr = t_customer-kunnr
AND kkber = p_kkber.
ELSE.
MESSAGE e999 WITH text-e07.
ENDIF.
IF sy-subrc NE 0.
ENDIF.
SORT t_knkk BY kunnr kkber.
IF NOT t_knkk[] IS INITIAL.
SELECT kunnr
name1
FROM kna1
INTO TABLE t_custo
FOR ALL ENTRIES IN t_knkk
WHERE kunnr = t_knkk-kunnr.
ENDIF.
IF sy-subrc = 0.
ENDIF.
SORT t_custo BY kunnr kkber.
LOOP AT t_custo INTO w_custo.
CLEAR w_knkk.
READ TABLE t_knkk INTO w_knkk WITH KEY kunnr = w_custo-kunnr
BINARY SEARCH.
IF sy-subrc = 0.
w_report_display-kunnr = w_custo-kunnr.
w_report_display-name = w_custo-name.
w_report_display-dtrev = w_knkk-dtrev.
w_report_display-nxtrv = w_knkk-nxtrv.
w_report_display-klimk = w_knkk-klimk.
w_report_display-dbwae = w_knkk-dbwae.
APPEND w_report_display TO t_report_display .
ENDIF.
ENDLOOP.
ENDFORM. " F1000_GET_CUSTOMER
*& Form F2000_DISPLAY_CUSTOMER
text
-->P_T_REPORT_DISPLAY text
FORM f2000_display_customer USING p_t_report_display.
DATA: no TYPE n VALUE 1.
DATA: t_data TYPE STANDARD TABLE OF y_report_display.
t_data = p_t_report_display.
DATA : w_data LIKE LINE OF t_data .
ULINE (118).
WRITE:/ sy-vline,
8 'CREDIT LIMIT CHANGE NOTIFICATION REPORT ON',
sy-datum , 118 sy-vline.
ULINE (118).
WRITE:/ sy-vline,'NO'(008) ,
10 sy-vline, 11 'CUSTOMER NUMBER',
28 sy-vline, 29 'CUSTOMER NAME', 43 sy-vline,
44 'CREDIT LIMIT VALID', 63 sy-vline ,
64 'CREDIT LIMIT AMOUNT', 85 sy-vline, 86 'CURRENCY',
95 sy-vline , 96 'Notification Status',118 sy-vline.
ULINE (118).
WRITE:/ sy-vline,43 sy-vline, 44 'FROM', 53 sy-vline,
56 'TILL', 63 sy-vline, 118 sy-vline .
ULINE (118).
LOOP AT t_data INTO w_data.
WRITE:/ sy-vline, no,
10 sy-vline, 11 w_data-kunnr ,
28 sy-vline, 29 w_data-name, 43 sy-vline, 44 w_data-dtrev,
53 sy-vline, 56 w_data-nxtrv ,63 sy-vline ,64 w_data-klimk,
85 sy-vline, 86 w_data-dbwae,
95 sy-vline , 118 sy-vline.
no = no + 1.
ULINE (118).
ENDLOOP.
ENDFORM. " F2000_DISPLAY_CUSTOMER
*& Form F3000_PROCESS_DATA_SCRIPT
text
-->P_T_REPORT_DISPLAY text
FORM f3000_process_data_script USING p_t_report_display.
DATA: t_data TYPE STANDARD TABLE OF y_report_display.
t_data = p_t_report_display.
DATA : w_data LIKE LINE OF t_data .
DATA: temp_is_negative(1) TYPE c,
temp_text(20) TYPE c,
temp_sname LIKE t001s-sname,
temp_email LIKE adr6-smtp_addr.
DATA : number LIKE spell,
amount(255) TYPE c.
PERFORM f3100_initialize_settings.
LOOP AT t_data INTO w_data.
AT NEW kunnr.
CLEAR w_error_found.
IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL.
PERFORM f3300_open_form.
data: wa_t001 like line of t001
DATA : begin of wa_t001,
adrnr like t001-adrnr,
end of wa_t001.
SELECT SINGLE
adrnr FROM t001 INTO wa_t001
WHERE bukrs = p_bukrs.
DATA: BEGIN OF wa_adrc,
addrnumber LIKE adrc-addrnumber,
name1 LIKE adrc-name1,
post_code1 LIKE adrc-post_code1,
city1 LIKE adrc-city1,
street LIKE adrc-street,
house_num1 LIKE adrc-house_num1,
tel_number LIKE adrc-tel_number,
nation LIKE adrc-nation ,
fax_number LIKE adrc-fax_number,
country LIKE adrc-country,
END OF wa_adrc.
SELECT SINGLE
addrnumber
name1
post_code1
city1
street
house_num1
tel_number
nation
fax_number
country
FROM adrc
INTO corresponding fields of wa_adrc
WHERE addrnumber EQ wa_t001-adrnr AND
nation EQ ' '.
PERFORM f3700_write_form.
DATA: wa_kna1 LIKE LINE OF t_kna1,
wa_adrcc LIKE LINE OF it_adrc.
SELECT SINGLE
kunnr
adrnr FROM kna1
INTO wa_kna1
WHERE kunnr = w_data-kunnr.
IF sy-subrc EQ 0.
SELECT SINGLE
addrnumber
name1
FROM adrc
INTO wa_adrcc
WHERE addrnumber = wa_kna1-adrnr
AND nation = ' '.
ENDIF.
PERFORM f3701_write_form.
DATA : wa_knkk LIKE LINE OF t_knkk.
DATA : counter TYPE i,
counter1 TYPE i.
IF sy-subrc EQ 0.
SELECT SINGLE KUNNR
DTREV
NXTRV
KLIMK FROM KNKK INTO WA_KNKK WHERE
KUNNR EQ W_DATA-KUNNR.
ENDIF.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = w_knkk-klimk
CURRENCY = ' '
FILLER = ' '
language = sy-langu
IMPORTING
in_words = number.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
amount = number-word.
PERFORM f3702_write_form.
DATA: wa_knb1 LIKE LINE OF t_knb1.
IF sy-subrc EQ 0.
SELECT SINGLE
busab
FROM knb1
INTO wa_knb1
WHERE kunnr = w_data-kunnr
AND bukrs = p_bukrs.
ENDIF.
DATA : wa_t001s LIKE LINE OF it_t001s.
IF sy-subrc EQ 0.
SELECT SINGLE bukrs
busab
sname
FROM t001s
INTO wa_t001s
WHERE bukrs = wa_knb1-bukrs
AND busab = wa_knb1-busab.
ENDIF.
PERFORM f3703_write_form.
PERFORM f3704_write_form.
IF counter1 < counter.
PERFORM f3705_write_form.
ENDIF.
PERFORM f3706_close_form.
ENDIF.
ENDAT.
IF w_error_found EQ c_true.
ENDIF.
AT END OF kunnr.
PERFORM F3400_WRITE_FORM USING C_TOTAL C_MAIN_WINDOW.
PERFORM F3500_CLOSE_FORM.
IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL. "Email setting
PERFORM f3200_get_email_addr USING w_data-kunnr.
PERFORM f3600_send_data_via_email USING w_data-kunnr.
ENDIF.
ENDAT.
ENDLOOP.
WRITE:/ ' E-Mail is sent to the customer'.
ENDFORM. " F3000_PROCESS_DATA_SCRIPT
*& Form F3100_INITIALIZE_SETTINGS
text
--> p1 text
<-- p2 text
FORM f3100_initialize_settings .
SELECT SINGLE spld
INTO itcpo-tddest
FROM usr01
WHERE bname EQ sy-uname.
IF sy-subrc NE 0.
itcpo-tddest = 'LOCAL'.
ENDIF.
w_htddevice = c_printer.
itcpo-tddest = ''.
itcpo-tdrdidev = ''.
itcpo-tdsenddate = sy-datum.
itcpo-tdsendtime = sy-uzeit.
itcpo-tdschedule = 'IMM'.
itcpo-tdimmed = ' '.
itcpo-tdnewid = c_true. "PRINT: New spool request
itcpo-tdlifetime = c_1. "PRINT: Spool retention period
itcpo-tdgetotf = c_true.
IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL. "Email setting
itcpo-tdgetotf = c_true.
ENDIF.
ENDFORM. " F3100_INITIALIZE_SETTINGS
*& Form f0500_validate_simul
text
--> p1 text
<-- p2 text
FORM f0500_validate_simul .
IF p_simul IS INITIAL AND p_lemail IS INITIAL. "Email setting
MESSAGE e999(zf) WITH 'Enter Email address'. "(e05).
ENDIF.
ENDFORM. " f0500_validate_simul
*& Form F3600_SEND_DATA_VIA_EMAIL
text
-->P_W_DATA_KUNNR text
FORM f3600_send_data_via_email USING p_w_data_kunnr.
DATA: fle1(2) TYPE p,
fle2(2) TYPE p,
off1 TYPE p,
hltlines TYPE i,
temp_filesize TYPE i,
hfeld(500) TYPE c,
header(50) TYPE c,
htabix LIKE sy-tabix,
x_sent_to_all LIKE sonv-flag.
DATA: BEGIN OF x_objcont OCCURS 0.
INCLUDE STRUCTURE soli.
INCLUDE STRUCTURE SOLISTI1.
DATA: END OF x_objcont.
DATA: BEGIN OF x_object_hd_change.
INCLUDE STRUCTURE sood1.
DATA: END OF x_object_hd_change.
DATA: BEGIN OF x_receivers OCCURS 0.
INCLUDE STRUCTURE soos1.
INCLUDE STRUCTURE SOMLRECI1.
DATA: END OF x_receivers.
DATA: BEGIN OF x_objhead OCCURS 1.
INCLUDE STRUCTURE soli.
DATA: END OF x_objhead.
**Data: begin of objpack occurs 0.
include structure SOPCKLSTI1.
**Data: end of objpack.
**Data: begin of email_data occurs 0.
include structure SODOCCHGI1.
**Data: end of email_data.
Converts the layout set to PDF format
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = c_pdf_format
IMPORTING
bin_filesize = temp_filesize
TABLES
otf = t_otfdata
lines = t_htline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc NE 0.
w_error_found = c_true.
t_error-kunnr = p_w_data_kunnr.
t_error-comm = 'Error in conversion to PDF format.'(e08).
APPEND t_error.
CLEAR t_error.
EXIT.
ENDIF.
Convert the PDF file into an internal table which to be used in the
function that will send a PDF file to a email address
DESCRIBE TABLE t_htline LINES hltlines.
DESCRIBE FIELD T_HTLINE LENGTH FLE1 IN BYTE MODE.
DESCRIBE FIELD t_htline LENGTH fle1
IN CHARACTER MODE.
DESCRIBE FIELD X_OBJCONT LENGTH FLE2 IN BYTE MODE.
DESCRIBE FIELD x_objcont LENGTH fle2
IN CHARACTER MODE.
CLEAR x_objcont.
REFRESH x_objcont.
LOOP AT t_htline.
htabix = sy-tabix.
MOVE t_htline TO hfeld+off1.
IF htabix = hltlines.
fle1 = STRLEN( t_htline ).
ENDIF.
off1 = off1 + fle1.
IF off1 GE fle2.
CLEAR x_objcont.
x_objcont = hfeld(fle2).
APPEND x_objcont.
SHIFT hfeld BY fle2 PLACES.
off1 = off1 - fle2.
ENDIF.
IF htabix = hltlines.
IF off1 GT 0.
CLEAR x_objcont.
x_objcont = hfeld(off1).
APPEND x_objcont.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT t_email.
x_receivers-receiver = t_email-smtp_addr.
x_receivers-rec_type = c_u.
APPEND x_receivers.
ENDLOOP.
x_receivers-receiver = p_lemail.
x_receivers-rec_type = c_u.
APPEND x_receivers.
DESCRIBE TABLE x_objcont LINES sy-tfill.
READ TABLE x_objcont INDEX sy-tfill.
email_data-doc_size = ( sy-tfill - 1 ) * 255 + STRLEN( x_objcont ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = sy-tfill.
objpack-doc_type = 'RAW'.
APPEND objpack.
email_data-obj_descr = 'Notification'.
APPEND email_data.
IF x_receivers[] IS NOT INITIAL.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = email_data
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
TABLES
packing_list = objpack
object_header = email_fname
contents_bin = email_text
contents_txt = x_objcont
receivers = x_receivers.
endif.
CLEAR x_objhead.
REFRESH x_objhead.
CLEAR x_object_hd_change.
x_object_hd_change-objnam = 'EMAIL'(t04).
header = 'Procter & Gamble'(t05).
x_object_hd_change-objdes = header. "Title
x_object_hd_change-objla = c_english. "Language
x_object_hd_change-objsns = c_f.
x_object_hd_change-objlen = temp_filesize.
x_object_hd_change-file_ext = c_pdf_format.
Transfer the email address to an internal table which will be used
in the function that will send a PDF file to a email address
CLEAR x_receivers.
REFRESH x_receivers.
LOOP AT t_email.
x_receivers-sndex = c_true.
x_receivers-sndpri = c_1.
x_receivers-recesc = c_u.
x_receivers-recnam = c_recipient_name.
Populate the email address of the customer
x_receivers-recextnam = t_email-smtp_addr.
x_receivers-recesc = c_english.
x_receivers-sndart = c_int.
APPEND x_receivers.
ENDLOOP.
x_receivers-sndex = c_true.
x_receivers-sndpri = c_1.
x_receivers-recesc = c_u.
x_receivers-recnam = c_recipient_name.
Populate the Local mail address
x_receivers-recextnam = p_lemail.
x_receivers-recesc = c_english.
x_receivers-sndart = c_int.
APPEND x_receivers.
Calling a SAP function to send out email with attachment of PDF file
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = x_object_hd_change
object_type = c_document_type
outbox_flag = c_true
IMPORTING
sent_to_all = x_sent_to_all
TABLES
objcont = x_objcont
objhead = x_objhead
receivers = x_receivers
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
x_error = 20
OTHERS = 21.
IF sy-subrc NE 0.
w_error_found = c_true.
t_error-kunnr = p_w_data_kunnr.
t_error-comm = 'Error in sending email.'(e09).
APPEND t_error.
CLEAR t_error.
ELSEIF sy-subrc EQ 0.
COMMIT WORK.
*Transmit Mail
SUBMIT rsconn01 WITH mode = c_int
WITH output = c_space
AND RETURN.
ENDIF.
ENDFORM. " F3600_SEND_DATA_VIA_EMAIL
*& Form F3200_GET_EMAIL_ADDR
text
-->P_T_REPORT_DISPLAY text
FORM f3200_get_email_addr USING p_w_data_kunnr.
REFRESH t_customer.
REFRESH t_adrt.
REFRESH t_email.
DATA: t_data TYPE STANDARD TABLE OF y_report_display.
t_data = p_t_report_display.
DATA : w_data LIKE LINE OF t_data .Sending mail with attachment
This program will allowed you to send email with attachment.
First, specify the attachment file from your local hardisk and execute.
Next, specify the sender email address and click the send button.
report y_cr17_mail.
data method1 like sy-ucomm.
data g_user like soudnamei1.
data g_user_data like soudatai1.
data g_owner like soud-usrnam.
data g_receipients like soos1 occurs 0 with header line.
data g_document like sood4 .
data g_header like sood2.
data g_folmam like sofm2.
data g_objcnt like soli occurs 0 with header line.
data g_objhead like soli occurs 0 with header line.
data g_objpara like selc occurs 0 with header line.
data g_objparb like soop1 occurs 0 with header line.
data g_attachments like sood5 occurs 0 with header line.
data g_references like soxrl occurs 0 with header line.
data g_authority like sofa-usracc.
data g_ref_document like sood4.
data g_new_parent like soodk.
data: begin of g_files occurs 10 ,
text(4096) type c,
end of g_files.
data : fold_number(12) type c,
fold_yr(2) type c,
fold_type(3) type c.
parameters ws_file(4096) type c default 'c:\debugger.txt'.
Can me any file fromyour pc ....either xls or word or ppt etc ...
g_user-sapname = sy-uname.
call function 'SO_USER_READ_API1'
exporting
user = g_user
PREPARE_FOR_FOLDER_ACCESS = ' '
importing
user_data = g_user_data
EXCEPTIONS
USER_NOT_EXIST = 1
PARAMETER_ERROR = 2
X_ERROR = 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.
fold_type = g_user_data-outboxfol+0(3).
fold_yr = g_user_data-outboxfol+3(2).
fold_number = g_user_data-outboxfol+5(12).
clear g_files.
refresh : g_objcnt,
g_objhead,
g_objpara,
g_objparb,
g_receipients,
g_attachments,
g_references,
g_files.
method1 = 'SAVE'.
g_document-foltp = fold_type.
g_document-folyr = fold_yr.
g_document-folno = fold_number.
g_document-objtp = g_user_data-object_typ.
*g_document-OBJYR = '27'.
*g_document-OBJNO = '000000002365'.
*g_document-OBJNAM = 'MESSAGE'.
g_document-objdes = 'sap-img.com testing by program'.
g_document-folrg = 'O'.
*g_document-okcode = 'CHNG'.
g_document-objlen = '0'.
g_document-file_ext = 'TXT'.
g_header-objdes = 'sap-img.com testing by program'.
g_header-file_ext = 'TXT'.
call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = sy-uname
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header
FOLMEM_DATA =
RECEIVE_DATA =
File from the pc to send...
method1 = 'ATTCREATEFROMPC'.
g_files-text = ws_file.
append g_files.
call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = g_owner
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header
method1 = 'SEND'.
g_receipients-recnam = 'MK085'.
g_receipients-recesc = 'B'.
g_receipients-sndex = 'X'.
append g_receipients.
call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = g_owner
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header.
*-- End of Program
also try this one for background scheduling the same
Sending mail with attachment report in Background
Pay attention because its working with output list from spool converted to pdf.
=================================================================================
z_send_email_fax_global
FUNCTION-POOL z_gfaian_mail_fax. MESSAGE-ID ..
WORK TABLE AREAS
TABLES: tsp01.
INTERNAL TABLES
DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
lt_note_text LIKE STANDARD TABLE OF soli WITH HEADER LINE,
lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
TYPES: BEGIN OF y_files,
file(60) TYPE c,
END OF y_files.
DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
DATA: l_objcont LIKE soli OCCURS 0 WITH HEADER LINE.
DATA: l_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
STRUCTURES
DATA: folder_id LIKE soodk,
object_id LIKE soodk,
link_folder_id LIKE soodk,
g_document LIKE sood4,
g_header_data LIKE sood2,
g_folmem_data LIKE sofm2,
g_header_data LIKE sood2,
g_receive_data LIKE soos6,
g_ref_document LIKE sood4,
g_new_parent LIKE soodk,
l_folder_id LIKE sofdk,
v_email(50).
DATA: hd_dat like sood1.
VARIABLES
DATA: client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type.
DATA: numbytes TYPE i,
arc_idx LIKE toa_dara,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
is_otf.
DATA: outbox_flag LIKE sonv-flag VALUE X,
store_flag LIKE sonv-flag,
delete_flag LIKE sonv-flag,
owner LIKE soud-usrnam,
on LIKE sonv-flag VALUE X,
sent_to_all LIKE sonv-flag,
g_authority LIKE sofa-usracc,
w_objdes LIKE sood4-objdes.
DATA: c_file LIKE rlgrap-filename,
n_spool(6) TYPE n.
DATA: cancel.
DATA: desired_type LIKE sood-objtp,
real_type LIKE sood-objtp,
attach_type LIKE sood-objtp,
otf LIKE sood-objtp VALUE OTF, SAPscript Ausgabeformat
ali LIKE sood-objtp VALUE ALI. ABAP lists
CONSTANTS
CONSTANTS: ou_fol LIKE sofh-folrg VALUE O,
c_objtp LIKE g_document-objtp VALUE RAW,
c_file_ext LIKE g_document-file_ext VALUE TXT.
=================================================================================
z_send_email_fax2
FUNCTION z_faian_mail_fax2.
Interface local:
* IMPORTING
* REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
* REFERENCE(FAX_MAIL_NUMBER) TYPE SO_NAME
* REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
* REFERENCE(OBJECT_TYPE) TYPE SO_ESCAPE
* TABLES
* LT_BODY_EMAIL STRUCTURE SOLI
* EXCEPTIONS
* ERR_NO_ABAP_SPOOLJOB
Fist part: Verify if the spool really exists
SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
IF sy-subrc NE 0.
RAISE err_no_abap_spooljob. doesnt exist
ELSE.
client = tsp01-rqclient.
name = tsp01-rqo1name.
CALL FUNCTION RSTS_GET_ATTRIBUTES
EXPORTING
authority = SP01′
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF objtype(3) = OTF.
desired_type = otf.
ELSE.
desired_type = ali.
ENDIF.
CALL FUNCTION RSPO_RETURN_SPOOLJOB
EXPORTING
rqident = src_spoolid
desired_type = desired_type
IMPORTING
real_type = real_type
TABLES
buffer = l_objcont
EXCEPTIONS
no_such_job = 14
type_no_match = 94
job_contains_no_data = 54
no_permission = 21
can_not_access = 21
read_error = 54.
IF sy-subrc EQ 0.
attach_type = real_type.
ENDIF.
CALL FUNCTION SO_FOLDER_ROOT_ID_GET
EXPORTING
owner = sy-uname
region = ou_fol
IMPORTING
folder_id = l_folder_id
EXCEPTIONS
OTHERS = 5.
fill out informations about the header of the email
CLEAR: g_document.
g_document-foltp = l_folder_id-foltp.
g_document-folyr = l_folder_id-folyr.
g_document-folno = l_folder_id-folno.
g_document-objtp = c_objtp.
g_document-objdes = header_mail.
g_document-file_ext = c_file_ext.
g_header_data-objdes = header_mail.
CALL FUNCTION SO_DOCUMENT_REPOSITORY_MANAGER
EXPORTING
method = SAVE
office_user = sy-uname
IMPORTING
authority = g_authority
TABLES
objcont = lt_body_email
attachments = lt_attachments
CHANGING
document = g_document
header_data = g_header_data
EXCEPTIONS
OTHERS = 1.
folder_id-objtp = l_folder_id-foltp.
folder_id-objyr = l_folder_id-folyr.
folder_id-objno = l_folder_id-folno.
object_id-objtp = c_objtp.
object_id-objyr = g_document-objyr.
object_id-objno = g_document-objno.
link_folder_id-objtp = l_folder_id-foltp.
link_folder_id-objyr = l_folder_id-folyr.
link_folder_id-objno = l_folder_id-folno.
REFRESH lt_rec_tab.
CLEAR lt_rec_tab.
lt_rec_tab-sel = X.
lt_rec_tab-recesc = object_type. This field for FAX/MAIL
lt_rec_tab-recnam = U-.
lt_rec_tab-deliver = X.
lt_rec_tab-not_deli = X.
lt_rec_tab-read = X.
lt_rec_tab-mailstatus = E.
lt_rec_tab-adr_name = fax_mail_number.
lt_rec_tab-sortfield = fax_mail_number.
lt_rec_tab-recextnam = fax_mail_number.
lt_rec_tab-sortclass = 5′.
APPEND lt_rec_tab.
lt_rec_tab-recextnam = fax_mail_number.
lt_rec_tab-recesc = object_type.
lt_rec_tab-sndart = INT.
lt_rec_tab-sndpri = 1.
APPEND lt_rec_tab.
lt_files-file = c_file.
APPEND lt_files.
begin of insertion by faianf01
hd_dat-objdes = header_mail.
CALL FUNCTION SO_ATTACHMENT_INSERT
EXPORTING
object_id = object_id
attach_type = attach_type
object_hd_change = hd_dat
owner = sy-uname
TABLES
objcont = l_objcont
objhead = l_objhead
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
object_type_not_exist = 17
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
x_error = 1000.
IF sy-subrc > 0.
ENDIF.
end of insertion by faianf01
send email from SAPOFFICE
CALL FUNCTION SO_OBJECT_SEND
EXPORTING
folder_id = folder_id
object_id = object_id
outbox_flag = outbox_flag
link_folder_id = link_folder_id
owner = sy-uname
check_send_authority = X
TABLES
receivers = lt_rec_tab
note_text = lt_note_text
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
component_not_available = 1
folder_no_authorization = 5
folder_not_exist = 6
forwarder_not_exist = 8
object_no_authorization = 13
object_not_exist = 14
object_not_sent = 15
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
too_much_receivers = 73
user_not_exist = 35.
ENDIF.
ENDFUNCTION.
=================================================================================
z_send_email_fax
FUNCTION ZCBFS_SEND_MAIL.
Interface local:
* IMPORTING
* REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
* REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
* TABLES
* LIST_FAX_MAIL_NUMBER STRUCTURE SOLI
* EXCEPTIONS
* ERR_NO_ABAP_SPOOLJOB
DATA: vg_achou(1) TYPE n.
Fist part: Verify if the spool really exists
vg_achou = 1.
DO 60 TIMES.
SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
IF sy-subrc IS INITIAL.
CLEAR vg_achou.
EXIT.
ELSE.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
IF vg_achou = 1.
RAISE err_no_abap_spooljob. doesnt exist
ENDIF.
client = tsp01-rqclient.
name = tsp01-rqo1name.
CALL FUNCTION RSTS_GET_ATTRIBUTES
EXPORTING
authority = SP01′
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF objtype(3) = OTF.
desired_type = otf.
ELSE.
desired_type = ali.
ENDIF.
CALL FUNCTION RSPO_RETURN_SPOOLJOB
EXPORTING
rqident = src_spoolid
desired_type = desired_type
IMPORTING
real_type = real_type
TABLES
buffer = l_objcont
EXCEPTIONS
no_such_job = 14
type_no_match = 94
job_contains_no_data = 54
no_permission = 21
can_not_access = 21
read_error = 54.
IF sy-subrc EQ 0.
attach_type = real_type.
ENDIF.
CALL FUNCTION SO_FOLDER_ROOT_ID_GET
EXPORTING
owner = sy-uname
region = ou_fol
IMPORTING
folder_id = l_folder_id
EXCEPTIONS
OTHERS = 5.
fill out informations about the header of the email
CLEAR: g_document.
g_document-foltp = l_folder_id-foltp.
g_document-folyr = l_folder_id-folyr.
g_document-folno = l_folder_id-folno.
g_document-objtp = c_objtp.
g_document-objdes = header_mail.
g_document-file_ext = c_file_ext.
g_header_data-objdes = header_mail.
CALL FUNCTION SO_DOCUMENT_REPOSITORY_MANAGER
EXPORTING
method = SAVE
office_user = sy-uname
IMPORTING
authority = g_authority
TABLES
attachments = lt_attachments
CHANGING
document = g_document
header_data = g_header_data
EXCEPTIONS
OTHERS = 1.
folder_id-objtp = l_folder_id-foltp.
folder_id-objyr = l_folder_id-folyr.
folder_id-objno = l_folder_id-folno.
object_id-objtp = c_objtp.
object_id-objyr = g_document-objyr.
object_id-objno = g_document-objno.
link_folder_id-objtp = l_folder_id-foltp.
link_folder_id-objyr = l_folder_id-folyr.
link_folder_id-objno = l_folder_id-folno.
REFRESH lt_rec_tab.
LOOP AT LIST_FAX_MAIL_NUMBER.
lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
lt_rec_tab-recesc = U.
lt_rec_tab-sndart = INT.
lt_rec_tab-sndpri = 1.
APPEND lt_rec_tab.
ENDLOOP.
lt_files-file = c_file.
APPEND lt_files.
hd_dat-objdes = header_mail.
CALL FUNCTION SO_ATTACHMENT_INSERT
EXPORTING
object_id = object_id
attach_type = attach_type
object_hd_change = hd_dat
owner = sy-uname
TABLES
objcont = l_objcont
objhead = l_objhead
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
object_type_not_exist = 17
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
x_error = 1000.
IF sy-subrc > 0.
ENDIF.
send email from SAPOFFICE
CALL FUNCTION SO_OBJECT_SEND
EXPORTING
folder_id = folder_id
object_id = object_id
outbox_flag = outbox_flag
link_folder_id = link_folder_id
owner = sy-uname
TABLES
receivers = lt_rec_tab
note_text = lt_note_text
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
component_not_available = 1
folder_no_authorization = 5
folder_not_exist = 6
forwarder_not_exist = 8
object_no_authorization = 13
object_not_exist = 14
object_not_sent = 15
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
too_much_receivers = 73
user_not_exist = 35.
ENDFUNCTION.
regards,
srinivas
<b>*reward for useful answers*</b> -
Error while opening PDF in mail attachment
Hi All,
In smartform i am sending a mail with attachemnt as PDF file,there is one more option like preview of smartform .
issue is like i am able to see the preview of the same record but when it is sent in mail attachement,and while opening PDF its showing error that file can not be open it is corrupted.
Please help.
Mona Singh.Dear Sandra
That was my problem: binary data was incorrectly converted (often because of Unicode systems).
I returned
bin_filesize = v_len_in
bin_file = l_binfile
from the function module CONVERT_OTF, then converted the xstring data (l_binfile) into an internal table (t_objbin) to send to the mail send function with the following function module:
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_binfile
IMPORTING
output_length = v_lines_bin
TABLES
binary_tab = t_objbin.
Many thanks for your help.
Best regards
Patricia -
Dynamic file name as mail attachment in receiver Mail Adapter?
Hi,
Can any one tell the possibility of attaching file as a mail attachment without using mail Package with dynamic filename.
Business requirement is to send error response as mail attachment with dynamic name.
Ex: Error_Response_20110802_13.24 where 20110802 is Date and next part represents time stamp.
File attachment name should change dynamically in Mail receiver Adapter. Thanks
Regards,
Sreeramulu Konjeti.there is no standard way.
you will have to write a module to get this in place.
other ways are;
XI Mail Adapter: An approach for sending emails with attachment with help of Java mapping - /people/stefan.grube/blog/2007/04/17/xi-mail-adapter-an-approach-for-sending-emails-with-attachment-with-help-of-java-mapping
Dynamic name in the mail attachment - pseudo "variable substitution" :
/people/michal.krawczyk2/blog/2006/02/23/xi-dynamic-name-in-the-mail-attachment--pseudo-variable-substitution -
Sending XI-Content as Mail Attachement with specific Filename
Hi,
I want to send the Message-Content as a mail attachment with a specific Filename (e.g. 2005-08-31.csv). The content is a CSV File, not a XML
In the scenario an IDOC is sent to the XI mapped in a CSV-File (via Java-Mapping) and should be send as a Mail Attachment.
Is this possible and how?
Thank you for your help
ThomasHi Thomas,
You can influence the filename with the ModuleTransformBean. You need at least SP9 for this feature.
In the Mail Receiver Channel got to tab "Module"
As first module (before the mail module) enter:
localejbs/AF_Modules/MessageTransformBean as Local Enterprise Bean with any key
For this module key you can use in the module configuration following entries:
Transform.ContentDisposition inline|attachment;filename=<filename>
Transform.ContentDescription <Filename>
Transform.ContentType <MimeType>/<SubType>;name="<filename>"
If you want to send an attachment, use:
Transform.ContentDisposition attachment;filename="MyFile.csv"
Transform.ContentDescription MyFile
Transform.ContentType text/plain;name="MyFile.csv"
If you use the Mail Package, you can set the file name that way:
<ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">
<Subject>Hello</Subject>
<From>[email protected]</From>
<To>[email protected]</To>
<Content_Type>text/plain;name="MyFile.csv"</Content_Type>
<Content>Here comes the CSV Data</Content>
</ns:Mail>
Hope that helps,
Stefan -
Problem in Reading Mail Attachement
I'm facing a problem while reading mail attachments. Java-mail returns null disposition for the below message,but this message has attachment javamail is not considering the mail attachment .I'm using java-mail 1.3.Can anybody help me to solve this problem ?
Return-Path: prvs=00548bd8bd=[email protected]
Received: from PRODTM1.TRUST.UASC.AO ([172.28.2.143])
by trust.uasc.net
; Mon, 14 Mar 2011 11:07:04 +0000
X-TM-IMSS-Message-ID:<[email protected]>
Received: from gw.northport.com.my ([202.188.31.130]) by trust.uasc.net ([172.28.2.144])
with ESMTP (TREND IMSS SMTP Service 7.1) id 45727fb90003495a ; Mon, 14 Mar 2011 11:06:52 +0000
Received: from [192.1.10.13] (port=59768 helo=nmbsmtp-01.northport.com.my)
by gw.northport.com.my with esmtp (Exim 4.69)
(envelope-from <[email protected]>)
id 1Pz5bs-0003EO-0A; Mon, 14 Mar 2011 19:06:48 +0800
X-CTCH-RefID: str=0001.0A090205.4D7DF6C8.0116,ss=1,fgs=0
Date: Mon, 14 Mar 2011 19:05:50 +0800 (SST)
From: AMTedi-Container Svcs <[email protected]>
Message-ID: <[email protected]>
Mime-Version: 1.0
To: [email protected], [email protected],
[email protected], [email protected]
Subject: CODCT1UAS
Content-Type: multipart/mixed; boundary="-"
X-TM-AS-Product-Ver: IMSS-7.1.0.1394-6.5.0.1024-18010.003
X-TM-AS-Result: No--4.942-5.0-31-1
X-imss-scan-details: No--4.942-5.0-31-1If you were assuming that every message would have a valid body part
and that they would tell you definitively which parts you should consider to
be "attachments", ya, that won't work. The disposition is a hint at best.
It can be wrong. It might not even be there. -
<satellite:form method="post" id="contact-form" enctype="multipart/form-data">
<input type="file" name="adjunto" />
</satellite:form>
FTValList ftListaFichero = new FTValList(1);
ftListaFichero.setValBLOB(ics.GetVar("adjunto_file"), ics.GetBin("adjunto"));
<mail:send
to="<%=to_emailaddress %>"
from="<%=from_emailaddress%>"
subject="Subject"
body="<%=body %>" >
<mail:attachment value='<%=ftListaFichero.getVal(ics.GetVar("adjunto_file"))%>'/>
</mail:send>
http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/mail-attachment.html
http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/mail-send.html
Regards,Simplest might well be to use javamail API instead of the two tags that Sites provides, e.g. see email - Sending mail attachment using Java - Stack Overflow for a full example.
Phil -
How to send the Adobe page as mail attachement from webdynpro...
Hi Experts,
How to send the Adobe page as external mail attachment from webdynpro automatically (for example: If I input the data for sales order in a view and created the sales order, if the sales order is created then have to place the created sales order number and the some details in a adobe form and should send as external mail and have to specifying the body as "Sales order created and details can be found in the attached adobe form" from webdynpro).
Do the needful.
Thanks & regards,
Ravi.Hi ravi,
See the WDA forum for the how to attach a file in webdynpro component for the attachments. -
Hello we have problem with mail after we got the new update Ios6 for Ipad3, Mail attachment can't read all info when receiving in xcl document dates show 0000.All IPad 3 don't work. Please any one have the same problem?Or any fix available.Thanks.Saca61
Mike,
I have the exact same problem. I have tried deleting mail messages but still can't seem to find the appropriate one to delete because the message number does not seem to correspond to Apple Mail's numbering system. Have you had any luck with this?
[email protected] -
Mail attachement content trnsfer encoding 8bit , 7bit
Good morning to everybody.
I have a problem reading mail attachement.
When the attachement is 8bit encoded the exadecimal char "3D" is write in a file as "0D". This is wrong
When the attachement is 7bit encoded the exadecimal char "3D" is write in a file as "3D" . Thi is right
Is there anyone who knows why of this beaviour?
Many thanksI'm using the msgshow.java that is the example included in the java mail library.
Attachement downloaded with JavaMail (the bad one):
�� 3D ==> 0D (CR)
2007-05-15;18.11.26;978;000469,00;380;Italy
;LUISA SPAGNOLI NAPOLI IT;34009575;8036527 ;5651;00;
Attachement downloaded with outlook (the good one):
�� 3D not translated
2007-05-15;18.11.26;978;000469,00;380;Italy =
;LUISA SPAGNOLI NAPOLI IT;34009575;8036527 ;5651;00;
Here the properties of the mail message:
Microsoft Mail Internet Headers Version 2.0
Received: from EXSMTP-IN2.sede.corp.sanpaoloimi.com ([10.244.7.21]) by EVS01.sede.corp.sanpaoloimi.com with Microsoft SMTPSVC(6.0.3790.2499);
Mon, 28 May 2007 08:09:14 +0200
Received: from secgw-b-e02.intesabci.it ([172.19.0.27]) by EXSMTP-IN2.sede.corp.sanpaoloimi.com with Microsoft SMTPSVC(6.0.3790.2499);
Mon, 28 May 2007 08:09:13 +0200
Received: MHUBINT
Received: FW
Received: from mail1.ssb.it ([192.106.129.13])
by mailbox.intesabci.it with SMTP id l4S696n5006757
for <[email protected]>; Mon, 28 May 2007 08:09:09 +0200
Received: (qmail 11377 invoked by uid 509); 28 May 2007 06:02:04 -0000
Received: from 127.0.0.1 by Imhotep (envelope-from <[email protected]>, uid 501) with qmail-scanner-2.01
(spamassassin: 3.1.3.
Clear:RC:1(127.0.0.1):.
Processed in 0.078893 secs); 28 May 2007 06:02:04 -0000
Mon, 28 May 2007 08:02:03 +0200 (CEST)
(Postfix) with SMTP id 6798F34257;Mon, 28 May 2007 08:02:03 +0200 (CEST)
to: <[email protected]>,
from: <[email protected]>
subject: 28 May 2007 08:00 PS12 FROD-ATM1
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="P=_NextPart_000_01BD3BAF.A762FD80"
Date: Mon, 28 May 07 08:00:27 B
Message-Id: <[email protected]>
Return-Path: [email protected]
X-OriginalArrivalTime: 28 May 2007 06:09:13.0674 (UTC) FILETIME=[B707A2A0:01C7A0EE]
--P=_NextPart_000_01BD3BAF.A762FD80
CONTENT-TYPE: TEXT/PLAIN; CHARSET="US-ASCII"
Content-Transfer-Encoding: 8bit
--P=_NextPart_000_01BD3BAF.A762FD80
Content-Type: text/plain; charset=us-ascii; name="SPIMI.TXT"
Content-Disposition: attachment
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mailbox.intesabci.it id l4S696n5006757
--P=_NextPart_000_01BD3BAF.A762FD80
CONTENT-TYPE: TEXT/PLAIN; CHARSET="US-ASCII"
Content-Transfer-Encoding: 8bit �������� I think the problem is here
P=_NextPart_000_01BD3BAF.A762FD80 -
Problems with specifying File Extension of E-Mail attachment
Hi everybody
I have a problem that seems to be so simple that it almost drives me crazy that I cannot find a solution for it.
I need to send the content of an internal table (some lines) as a mail attachment to a specified mail address.
The format should be normal ASCII, so when I open it with any text editor (e.g. Notepad), I want to have all my lines there (including CR/LF).
The problem now is - The extension of this mail attachment must be ".key", so the attached file should have the name "L_12345.key" (for example).
For E-Mailing I use FM "SO_NEW_DOCUMENT_ATT_SEND_API1".
This part works fine, also the attachment part works in general. (I receive the mail and I receive the attachment).
BUT I get either an attachment with the name "L_12345.txt" or "L_12345.key.txt" and in correct format, or I get an attachment "L_12345.key", where the name is correct but format is wrong (no CR/LF - everything in one line).
Example:
=======
Attachment-Content should be:
Line 1
Line 2
Line 3
Name of Attachment should be: L_12345.key
What I tried:
TEST 1 **
Declare Attachment in Packing list. ..
ls_packing_list-transf_bin = ' '.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 0.
ls_packing_list-body_start = 7. "Startline of Attachment
ls_packing_list-body_num = 3. "No of Attachment lines
ls_packing_list-doc_type = 'RAW'.
ls_packing_list-doc_size = 3 * 255.
ls_packing_list-obj_name = 'ATT01'.
ls_packing_list-obj_descr = 'L_12345' "Attachment name
APPEND ls_packing_list TO lt_packing_list.
==> Result: Attachment Filename = L_12345.txt
==> File as I need it (ASCII with CR/LF), but extension wrong
Line 1
Line 2
Line 3
TEST 2 **
Same as TEST 1, but with:
ls_packing_list-obj_descr = 'L_12345.KEY' "Attachment name
==> Result: Attachment Filename = L_12345.KEY.txt
==> File as I need it (ASCII with CR/LF), but extension wrong
Line 1
Line 2
Line 3
TEST 3 **
Declare Attachment in Packing list. ..
ls_packing_list-transf_bin = ' '.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 0.
ls_packing_list-body_start = 7. "Startline of Attachment
ls_packing_list-body_num = 3. "No of Attachment lines
ls_packing_list-doc_type = 'KEY'.
ls_packing_list-doc_size = 3 * 255.
ls_packing_list-obj_name = 'ATT01'.
ls_packing_list-obj_descr = 'L_12345'. "Attachment name
APPEND ls_packing_list TO lt_packing_list.
==> Result: Attachment Filename = L_12345.KEY
==> File Format is wrong:
Line 1 Line 2 Line3
I have tried several other Extensions (DOC_TYPE), it seems, that the File format is only correct with "RAW", but it seems with "RAW" SAP adds ".txt" as extension to the filename.
Does anyone know how I can achieve having an e-mail attachment with multiple text lines and name "<anyname>.key"
Any help (if possible with example code ?) would be highly appreciated.
Many thanks
Haraldhi,
check the following code.
*& Form send_email
FORM send_email.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS: con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
*Body of mail
CLEAR objtxt.
CLEAR objtxt[].
objtxt = 'Dear abc'.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
objtxt = 'Attached herewith is the detail list of materials.'.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
objtxt = 'Regards,'.
APPEND objtxt.
objtxt = 'Admin'.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
*Mail description
CLEAR docdata.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
docdata-obj_name = 'List'.
docdata-obj_descr = 'List of materials'.
docdata-obj_langu = sy-langu.
*Packing list for main document
CLEAR objpack.
CLEAR objpack[].
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
*Attachment data
CLEAR objbin.
CLEAR objbin[].
CONCATENATE
'field1' 'field2' 'field3' 'field4'
INTO objbin SEPARATED BY ','.
CONCATENATE con_cret objbin INTO objbin.
APPEND objbin.
LOOP AT it_material_list INTO wa_material_list.
MOVE-CORRESPONDING wa_material_list TO wa_char_material_list.
CONCATENATE
wa_char_material_list-field1
wa_char_material_list-field2
wa_char_material_list-field3
wa_char_material_list-field4
INTO objbin SEPARATED BY con_tab.
CONCATENATE con_cret objbin INTO objbin.
APPEND objbin.
CLEAR objbin.
CLEAR wa_char_employee_list.
ENDLOOP.
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
*Packing list for attachment document
CLEAR objpack.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'. "check these values
objpack-head_start = 1. "check these values
objpack-head_num = 1. "check these values
objpack-body_start = 1. "check these values
objpack-body_num = tab_lines.
objpack-doc_type = 'KEY'.
objpack-obj_name = 'Attachment'.
objpack-obj_descr = 'Report.KEY'.
APPEND objpack.
*Email receiver's list
CLEAR reclist.
CLEAR reclist[].
reclist-receiver = mail_id.
reclist-rec_type = 'U'.
APPEND reclist.
*Function module to send email with an attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
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.
ENDFORM. "send_email
Edited by: vikram shah on Sep 25, 2008 5:28 PM
Maybe you are looking for
-
Before re-installing Firefox 19, I mistakenly took backup of my profile from a folder - C:\Documents and Settings\garan14\Local Settings\Application Data\Mozilla\Firefox\Profiles and not from C:\Documents and Settings\garan14\Application Data\Mozilla
-
Need of blocking sales orders?
Hai all, why do we block sales orders, and where can we find these information(tables), indicating that a particular sales order has been blocked, can anybody give me complete scenario of blocking sales orders.
-
I have to migrate a database from SQLServer 7.0 to Oracle 8i. I make it from the SQLServer console,and there's no problem.But there are some tables with several "Long" type fields,and there's an error showing me that Oracle only supports one "Long" f
-
How do I restore Email inbox function?
For the past week, my Ipad2 has not been displaying inbox Yahoo messages but shows spinning circle "checking for mail". I can view messages in other mailboxes but inbox continues to freeze at "downloading 1 of 18". I rebooted but find no other way
-
Leopard Server - Time Machine Backup - Full
IHi, I have Leopard Server (10.5.2) running on a Mac Pro. Its is setup with 1 Boot Drive and a pair Mirrored Data Drives. It also has a large External Drive that the Data from the Mirrored Drives is backed up onto via Time Machine. The Boot Drive is