‎2008 Oct 28 10:40 AM
Hi,
i try to Add attachment to mail the i send (i use class bcs) ,
and i have
document->add_attachment( EXPORTING i_attachment_type = 'RAW' " First Attachment
i_attachment_subject = 'attach1.txt'
i_att_content_text = lt_attach ).
‎2008 Oct 28 10:44 AM
HI ,
Sorry i don't complete my first massge .
when i run the progarm i get dump.
this is what i get:
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_REF_IS_INITIAL', was not
caught and
therefore caused a runtime error.
The reason for the exception is:
An attempt was made to access a component (variable: "DOCUMENT") with a 'ZERO
object reference (points to 'nothing').
An object reference must point to an object (an instance of a class)
before it can be used to access a component.
Either the reference has not yet been set or it was set to 'ZERO' using
a CLEAR statement.
APPEND 'Test Attachment' TO lt_attach.
document->add_attachment( EXPORTING i_attachment_type = 'RAW' " First Attachment
i_attachment_subject = 'Test'
i_att_content_text = lt_attach
i_attachment_size = '21' ).what i miss here?
Best Regards
‎2008 Oct 28 10:43 AM
Hello Ferry
Have you had already a look at sample report BCS_EXAMPLE_5 ?
REPORT bcs_example_5.
* This example shows how to send
* - a simple text provided in an internal table of text lines
* - and an attached MS word document provided in internal table
* - to some internet email address.
*
* All activities done via facade CL_BCS!
...
Regards
Uwe
‎2008 Oct 28 10:44 AM
‎2008 Oct 28 10:44 AM
HI ,
Sorry i don't complete my first massge .
when i run the progarm i get dump.
this is what i get:
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_REF_IS_INITIAL', was not
caught and
therefore caused a runtime error.
The reason for the exception is:
An attempt was made to access a component (variable: "DOCUMENT") with a 'ZERO
object reference (points to 'nothing').
An object reference must point to an object (an instance of a class)
before it can be used to access a component.
Either the reference has not yet been set or it was set to 'ZERO' using
a CLEAR statement.
APPEND 'Test Attachment' TO lt_attach.
document->add_attachment( EXPORTING i_attachment_type = 'RAW' " First Attachment
i_attachment_subject = 'Test'
i_att_content_text = lt_attach
i_attachment_size = '21' ).what i miss here?
Best Regards
‎2008 Oct 28 10:47 AM
document->add_attachment( EXPORTING i_attachment_type = 'RAW' " First Attachment
i_attachment_subject = 'Test'
i_att_content_text = lt_attach
i_attachment_size = '12' ). "try with 12also check the example mentioned above by UWE it is a good example.
Did you create the document object..?
Edited by: Vijay Babu Dudla on Oct 28, 2008 6:48 AM
‎2008 Oct 28 10:50 AM
Hello Ferry
Before using the document instance you need to create it:
*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
FORM main.
try.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document from internal table with text
APPEND 'Hello world!' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'test created by BCS_EXAMPLE_2' ).
* add attachment to document
* BCS expects document content here e.g. from document upload
* binary_content = ...
CALL METHOD document->add_attachment
EXPORTING i_attachment_type = 'DOC'
i_attachment_subject = 'My attachment'
i_att_content_hex = binary_content.
* add document to send request
CALL METHOD send_request->set_document( document ).
...
Regards
Uwe
‎2008 Oct 28 10:52 AM
Hi Vijay ,
Thanks,
i try to Change the number like u write and i have the same error .
Regards
‎2008 Oct 28 11:06 AM
did you check the example program BCS_EXAMPLE_5, if you are still getting the error post the code. did you call the method create_document inside your program.
‎2008 Oct 28 11:15 AM
Hi Uwe ,
thanks i Try your code (bcs_example_5) and i don't get dump!
the problem now is that i dont get the attchment (i get the mail) ,maybe u have idea ?
‎2008 Oct 28 11:24 AM
try to pass some attachement and see.
CALL METHOD document->add_attachment
EXPORTING i_attachment_type = 'DOC'
i_attachment_subject = 'My attachment'
i_att_content_hex = binary_content. "if you don;t have any content in this
"you will not get any attachment.
‎2008 Oct 28 11:28 AM
Hi Vijay,
Thanks,
what i add to my code is exactly this:
APPEND 'Hello world!' TO lt_attach.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_attach
i_length = '12'
i_subject = 'test created by BCS_EXAMPLE_2' ).
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'DOC'
i_attachment_subject = 'My attachment'
i_att_content_hex = binary_content.
* add document to send request
CALL METHOD send_request->set_document( document ).How i bring content to binary_content ?
P.S. when i add the line :
CALL METHOD send_request->set_document( document ).i still get the dump that i had before.
Best Regards
‎2008 Oct 28 11:32 AM
show the complete code. the example working fine for me, i am getting the attachment also. but it is empty one. do one thing copy the code exacly and check. some where you are doing a mistake.
if you are not able to proceed show your code once.
‎2008 Oct 28 11:57 AM
Hi Vigay,
&----
*& Report YY_SEND_MAIL
*&
&----
*&
*&
&----
REPORT yy_send_mail.
TYPE-POOLS abap.
DATA: lo_send_request TYPE REF TO cl_bcs,
send_request TYPE REF TO cl_bcs,
lo_document TYPE REF TO cl_document_bcs,
lo_recipient TYPE REF TO cl_cam_address_bcs,
lo_exception TYPE REF TO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lt_attach TYPE soli_tab, " Attachment content
lt_flds TYPE TABLE OF w3fields WITH HEADER LINE,
document TYPE REF TO cl_document_bcs,
bcs_exception TYPE REF TO cx_bcs,
lv_error_txt TYPE string,
lt_header TYPE TABLE OF w3head WITH HEADER LINE,
lt_html TYPE TABLE OF w3html WITH HEADER LINE,
ls_tab_header TYPE w3head.
DATA: binary_content TYPE solix_tab.
DATA : lt_comp_tab TYPE abap_component_tab WITH HEADER LINE,
tab_ref TYPE REF TO data,
line_ref TYPE REF TO data,
line_type TYPE REF TO cl_abap_structdescr,
tab_type TYPE REF TO cl_abap_tabledescr,
data_describer TYPE REF TO cl_abap_datadescr.
FIELD-SYMBOLS : <table> TYPE table,
<line> TYPE any,<field> TYPE any.
PARAMETERS : table TYPE tabname DEFAULT 'HRP1001' ,
fld1 TYPE fieldname DEFAULT 'OTYPE',
fld2 TYPE fieldname DEFAULT 'OBJID',
mailto TYPE adr6-smtp_addr .
------For Dynmic Selection of table & fields -
TRY.
lt_comp_tab-name = fld1.
lt_comp_tab-type ?= cl_abap_datadescr=>describe_by_data( field1 ).
APPEND lt_comp_tab.
lt_comp_tab-name = fld2.
lt_comp_tab-type ?= cl_abap_datadescr=>describe_by_data( field2 ).
APPEND lt_comp_tab.
CATCH cx_sy_move_cast_error.
EXIT.
ENDTRY.
TRY.
line_type ?= cl_abap_structdescr=>create( lt_comp_tab[] ).
tab_type ?= cl_abap_tabledescr=>create( line_type ).
CATCH cx_sy_move_cast_error.
ENDTRY.
CREATE DATA : tab_ref TYPE HANDLE tab_type,
line_ref TYPE HANDLE line_type.
ASSIGN tab_ref->* TO <table>.
ASSIGN line_ref->* TO <line>.
--
perform select_data_from_table.
MOVE : 'Table Data' TO ls_tab_header-text,
'Arial' TO ls_tab_header-font,
'2' TO ls_tab_header-size.
LOOP AT lt_comp_tab.
MOVE lt_comp_tab-name TO lt_header-text.
MOVE : sy-tabix TO lt_header-nr,
'red' TO lt_header-bg_color.
APPEND lt_header.
ENDLOOP.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
EXPORTING
table_header = ls_tab_header
TABLES
html = lt_html[]
fields = lt_flds[]
row_header = lt_header[]
itable = <table>.
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_html[]
i_subject = 'Table' ).
APPEND 'Hello world!' TO lt_attach.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_attach
i_length = '12'
i_subject = 'test created by BCS_EXAMPLE_2' ).
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'DOC'
i_attachment_subject = 'My attachment'
i_att_content_hex = binary_content.
add document to send request
CALL METHOD send_request->set_document( document ).
lo_send_request->set_document( lo_document ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_express = 'X' ).
lo_send_request->set_send_immediately( 'X' ).
lv_sent_to_all = lo_send_request->send( 'X' ).
COMMIT WORK.
ENDTRY.
‎2008 Oct 28 12:11 PM
"comment the below line
"CALL METHOD send_request->set_document( document ). "since no object send_request
"in your example
lo_send_request->set_document( lo_document ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_express = 'X' ).
lo_send_request->set_send_immediately( 'X' ).
lv_sent_to_all = lo_send_request->send( 'X' ).
COMMIT WORK.
ENDTRY.
‎2008 Oct 28 12:24 PM
Hi Vijay ,
Thanks ,
i do that but still don't get the attchment,maybe u have other idea?
Regards
‎2008 Oct 28 12:27 PM
Hi Ferry,
You are using two instances of classes
1) cl_document_bcs ( lo_document & document ) &
2) cl_bcs ( lo_send_request & send_request ).
You are getting the dump bcoz u r creating the instance lo_send_request but using the instance send_request !!!.
Same is being done with the instances of cl_document_bcs.
use any one(only one) of the two instances...
Check the corrected code below, Here i have attached the same
html file.
TYPE-POOLS abap.
DATA: lo_send_request TYPE REF TO cl_bcs,
send_request TYPE REF TO cl_bcs,
lo_document TYPE REF TO cl_document_bcs,
lo_recipient TYPE REF TO cl_cam_address_bcs,
lo_exception TYPE REF TO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lt_attach TYPE soli_tab, " Attachment content
lt_flds TYPE TABLE OF w3fields WITH HEADER LINE,
document TYPE REF TO cl_document_bcs,
bcs_exception TYPE REF TO cx_bcs,
lv_error_txt TYPE string,
lt_header TYPE TABLE OF w3head WITH HEADER LINE,
lt_html TYPE TABLE OF w3html WITH HEADER LINE,
ls_tab_header TYPE w3head.
DATA: binary_content TYPE solix_tab.
DATA : lt_comp_tab TYPE abap_component_tab WITH HEADER LINE,
tab_ref TYPE REF TO data,
line_ref TYPE REF TO data,
line_type TYPE REF TO cl_abap_structdescr,
tab_type TYPE REF TO cl_abap_tabledescr,
data_describer TYPE REF TO cl_abap_datadescr.
FIELD-SYMBOLS : <table> TYPE table,
<line> TYPE ANY,<field> TYPE ANY.
PARAMETERS : table TYPE tabname DEFAULT 'HRP1001' ,
fld1 TYPE fieldname DEFAULT 'OTYPE',
fld2 TYPE fieldname DEFAULT 'OBJID',
mailto TYPE adr6-smtp_addr .
TRY.
lt_comp_tab-name = fld1.
lt_comp_tab-type ?= cl_abap_datadescr=>describe_by_data( fld1 ).
APPEND lt_comp_tab.
lt_comp_tab-name = fld2.
lt_comp_tab-type ?= cl_abap_datadescr=>describe_by_data( fld2 ).
APPEND lt_comp_tab.
CATCH cx_sy_move_cast_error.
EXIT.
ENDTRY.
TRY.
line_type ?= cl_abap_structdescr=>create( lt_comp_tab[] ).
tab_type ?= cl_abap_tabledescr=>create( line_type ).
CATCH cx_sy_move_cast_error.
ENDTRY.
CREATE DATA : tab_ref TYPE HANDLE tab_type,
line_ref TYPE HANDLE line_type.
ASSIGN tab_ref->* TO <table>.
ASSIGN line_ref->* TO <line>.
SELECT * FROM (table) INTO CORRESPONDING FIELDS OF TABLE <table> UP TO 10 ROWS.
MOVE : 'Table Data' TO ls_tab_header-text,
'Arial' TO ls_tab_header-font,
'2' TO ls_tab_header-size.
LOOP AT lt_comp_tab.
MOVE lt_comp_tab-name TO lt_header-text.
MOVE : sy-tabix TO lt_header-nr,
'red' TO lt_header-bg_color.
APPEND lt_header.
ENDLOOP.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
EXPORTING
table_header = ls_tab_header
TABLES
html = lt_html[]
fields = lt_flds[]
row_header = lt_header[]
itable = <table>.
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_html[]
i_subject = 'Table' ).
lo_document->add_attachment( i_attachment_type = 'HTM'
i_attachment_subject = 'My attachment'
i_att_content_text = lt_html[] ).
lo_send_request->set_document( lo_document ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_express = 'X' ).
lo_send_request->set_send_immediately( 'X' ).
lv_sent_to_all = lo_send_request->send( 'X' ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.Cheers,
Jose.
‎2008 Oct 28 12:41 PM
HI Jose,
Thanks ! ,
when i copy your program to new i get the attachment , i try to find the diff now.
i don't understand way i don't get it because i remove the line of the code like Vijay says and i still don't get it in my code.
i get the attachment in HTM file maybe u can give example how can i get it with word/excel ?
Best Regards
‎2008 Oct 28 12:53 PM
i just looked for the line which caused the dump. the bcs example is very informative check it once.
‎2008 Oct 28 1:04 PM
HI Vijay,
Thanks i do it now.
now i have other problem when i write words in the attachment i see it in the word document with space and with strange square between the words maybe u have idea ?
e.g. if i write Hello world i get just the word hello with square between the words.when i do copy paste it don't bring the square.
H e l l o
Regards
‎2008 Oct 28 1:10 PM
that is binary format. if you have some word document you can send it. in otherway you can try some thing like this..
data: text_content type soli_tab.
append 'THis is attachemnt' to text_content.
append 'THis is attachemnt' to text_content.
append 'THis is attachemnt' to text_content
CALL METHOD document->add_attachment
EXPORTING i_attachment_type = 'TXT'
i_attachment_subject = 'My attachment'
I_ATT_CONTENT_TEXT = text_content.
‎2008 Oct 28 1:23 PM
Hi Ferry,
IF u see that std example(BCS_EXAMPLE_5), its written
* add attachment to document
* BCS expects document content here e.g. from document upload
* binary_content = ...So i tried to upload an existing word file from presentation server
and attach it to our mail..it works
But if u want the content of the attachment to be genetated at
runtime(thru ur code),guess its going to be complicated( binary
content ). So its better to use a txt attachment as described in
above post.
DATA: send_request TYPE REF TO cl_bcs,
lt_text TYPE bcsy_text, " Message body
lt_attach TYPE solix_tab, " Attachment content
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO cl_cam_address_bcs,
bcs_exception TYPE REF TO cx_bcs,
lv_error_txt TYPE string,
sent_to_all TYPE os_boolean,
gt_filetable TYPE filetable,
gv_filename TYPE string,
gv_filesize TYPE i,
gv_return TYPE i,
gv_useraction TYPE i.
PARAMETERS p_mailid TYPE adr6-smtp_addr.
*File Open Dialog
cl_gui_frontend_services=>file_open_dialog( CHANGING file_table = gt_filetable
rc = gv_return
user_action = gv_useraction ).
CHECK gv_return GT cl_gui_frontend_services=>action_ok AND
gv_useraction EQ cl_gui_frontend_services=>action_ok.
READ TABLE gt_filetable INTO gv_filename INDEX 1.
*File Upload
cl_gui_frontend_services=>gui_upload( EXPORTING filename = gv_filename
filetype = 'BIN'
IMPORTING filelength = gv_filesize
CHANGING data_tab = lt_attach ).
TRY.
send_request = cl_bcs=>create_persistent( ).
APPEND 'Test message' TO lt_text.
document = cl_document_bcs=>create_document( i_type = 'RAW'
i_text = lt_text
i_subject = 'Check this' ).
document->add_attachment( EXPORTING i_attachment_type = 'DOC'
i_attachment_subject = 'attachment.doc'
i_att_content_hex = lt_attach ).
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( p_mailid ).
send_request->add_recipient( i_recipient = recipient
i_express = 'X' ).
send_request->set_send_immediately( 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
lv_error_txt = bcs_exception->get_text( ).
WRITE:`Error : ` , lv_error_txt.
EXIT.
ENDTRY.Cheers,
Jose.
‎2008 Oct 28 1:59 PM
HI Vijay ,
Thanks,
i try with TXT and its work fine the problem with office document ,When i put DOC,
i get the square between the word u have idea to solve this issue?
Regards
‎2008 Oct 28 2:19 PM
HI Jose,
Thanks this is exactly what i want,
I have 2 last question i open a New thread for that .
‎2011 Mar 07 5:15 PM
Hello Vijay,
My req is to convert smart form into word document and add as an attachment to the mail. The mail should be sent to all the mail id's present in a target group of campaign element.
My queries are
1) Is it possible to send a mail with word doc as an attachment. ? If yes, please provide sample code.( I searched in sdn. Didnt find anything.I am getting mail with word doc as attachment but while opening that document, its throwing the error).
2)How to send a mail to multiple mail id's at a time?
Thanks,
Srinivas.
‎2011 Mar 07 5:26 PM
Word cannot start the converter mswrd632.
This is the error which i m getting.