2014 Apr 07 8:16 AM
Hi,
I'm using the BCS class for sending HTM format email so i use the below code for that its working,
DATA: gr_document TYPE REF TO cl_document_bcs,
gr_document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = t_html
i_importance = '5'
i_subject = gc_subject ).
Next task is to send the image so i'm creating an another object to the same class, below code
*--------------------------------------------------------------------*
*Image from MIME
*--------------------------------------------------------------------*
DATA: o_mr_api TYPE REF TO if_mr_api.
DATA is_folder TYPE boole_d.
DATA l_img1 TYPE xstring.
DATA l_img2 TYPE xstring.
DATA l_loio TYPE skwf_io.
DATA: lo_document TYPE REF TO cl_document_bcs.
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
CALL METHOD o_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/ZDEMO/tick.png'
IMPORTING
e_is_folder = is_folder
e_content = l_img1
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
CALL METHOD o_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/ZDEMO/Delete.png'
IMPORTING
e_is_folder = is_folder
e_content = l_img2
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
*Convert XSTRING to ITAB
DATA :lt_hex1 TYPE solix_tab,
lt_hex2 TYPE solix_tab,
ls_hex LIKE LINE OF lt_hex1,
lv_img1_size TYPE sood-objlen,
lv_img2_size TYPE sood-objlen.
CLEAR : lt_hex1, lt_hex2, ls_hex, lv_img1_size, lv_img2_size.
WHILE l_img1 IS NOT INITIAL.
ls_hex-line = l_img1.
APPEND ls_hex TO lt_hex1.
SHIFT l_img1 LEFT BY 255 PLACES IN BYTE MODE.
ENDWHILE.
WHILE l_img2 IS NOT INITIAL.
ls_hex-line = l_img2.
APPEND ls_hex TO lt_hex2.
SHIFT l_img2 LEFT BY 255 PLACES IN BYTE MODE.
ENDWHILE.
*Findthe Size of the image
DESCRIBE TABLE lt_hex1 LINES lv_img1_size.
DESCRIBE TABLE lt_hex2 LINES lv_img2_size.
lv_img1_size = lv_img1_size * 255.
lv_img2_size = lv_img2_size * 255.
*--------------------------------------------------------------------*
*Attach Images
*--------------------------------------------------------------------*
clear: lo_document.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'png' " Document Class for Attachment
i_attachment_subject = 'img1' " Attachment Title
i_attachment_size = lv_img1_size " Size of Document Content
i_att_content_hex = lt_hex1 " Content (Binary)
).
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'png' " Document Class for Attachment
i_attachment_subject = 'img2' " Attachment Title
i_attachment_size = lv_img2_size " Size of Document Content
i_att_content_hex = lt_hex2 " Content (Binary)
).
but it throws the dump " Access using NULL object reference is not possible" when i tries to access for method add_attachment...
Thanks,
Siva
2014 Apr 07 8:23 AM
Hi,
You need to create the object instance using "CREATE OBJECT <ur object instance name> type ref to <the class for which instance needs to be created>
and then call the respective methods of class.
Br,
Maju
2014 Apr 07 8:34 AM
2014 Apr 07 8:35 AM
Hello, extract from your code:
clear: lo_document.
lo_document->add_attachment(
Just invalidate/free the object reference, and in next line you are calling it's method... If the instance is not created you can not call it's instance methods, only statics methods can be called.
Instead of the clear statement you need to create the object.
Br
Bohuslav
2014 Apr 07 8:42 AM
Thanks now the system doesn't throw dump, but email code is not sending mail.
2014 Apr 07 8:45 AM
do you perform commit work explicitly after sending the mail? if yes check SOST transaction
2014 Apr 07 11:28 AM
Yes there is commit work after that, Below code
gr_document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = t_html
i_importance = '5'
i_subject = gc_subject ).
*--------------------------------------------------------------------*
*Image from MIME
*--------------------------------------------------------------------*
DATA: o_mr_api TYPE REF TO if_mr_api.
DATA is_folder TYPE boole_d.
DATA l_img1 TYPE xstring.
DATA l_img2 TYPE xstring.
DATA l_loio TYPE skwf_io.
DATA: lo_document TYPE REF TO cl_document_bcs.
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
CALL METHOD o_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/ZDEMO/tick.png'
IMPORTING
e_is_folder = is_folder
e_content = l_img1
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
CALL METHOD o_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/ZDEMO/Delete.png'
IMPORTING
e_is_folder = is_folder
e_content = l_img2
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
*Convert XSTRING to ITAB
DATA :lt_hex1 TYPE solix_tab,
lt_hex2 TYPE solix_tab,
ls_hex LIKE LINE OF lt_hex1,
lv_img1_size TYPE sood-objlen,
lv_img2_size TYPE sood-objlen.
CLEAR : lt_hex1, lt_hex2, ls_hex, lv_img1_size, lv_img2_size.
WHILE l_img1 IS NOT INITIAL.
ls_hex-line = l_img1.
APPEND ls_hex TO lt_hex1.
SHIFT l_img1 LEFT BY 255 PLACES IN BYTE MODE.
ENDWHILE.
WHILE l_img2 IS NOT INITIAL.
ls_hex-line = l_img2.
APPEND ls_hex TO lt_hex2.
SHIFT l_img2 LEFT BY 255 PLACES IN BYTE MODE.
ENDWHILE.
*Findthe Size of the image
DESCRIBE TABLE lt_hex1 LINES lv_img1_size.
DESCRIBE TABLE lt_hex2 LINES lv_img2_size.
lv_img1_size = lv_img1_size * 255.
lv_img2_size = lv_img2_size * 255.
*--------------------------------------------------------------------*
*Attach Images
*--------------------------------------------------------------------*
create object lo_document type cl_document_bcs.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'png' " Document Class for Attachment
i_attachment_subject = 'img1' " Attachment Title
i_attachment_size = lv_img1_size " Size of Document Content
i_att_content_hex = lt_hex1 " Content (Binary)
).
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'png' " Document Class for Attachment
i_attachment_subject = 'img2' " Attachment Title
i_attachment_size = lv_img2_size " Size of Document Content
i_att_content_hex = lt_hex2 " Content (Binary)
).
"Add document to send request
CALL METHOD gr_send_request->set_document( gr_document ).
TRY.
CALL METHOD gr_send_request->SET_SEND_IMMEDIATELY
EXPORTING
I_SEND_IMMEDIATELY = 'X'.
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
DATA: LO_SENDER TYPE REF TO IF_SENDER_BCS VALUE IS INITIAL.
TRY.
LO_SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ). "sender is the logged in user
* Set sender to send request
gr_send_request->SET_SENDER(
EXPORTING
I_SENDER = LO_SENDER ).
* CATCH CX_ADDRESS_BCS.
****Catch exception here
ENDTRY.
"Send email
CALL METHOD gr_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = gv_sent_to_all ).
IF gv_sent_to_all = 'X'.
WRITE 'Email sent!'.
ENDIF.
"Commit to send email
COMMIT WORK.
"Exception handling
CATCH cx_bcs INTO gr_bcs_exception.
WRITE:
'Error!',
'Error type:',
gr_bcs_exception->error_type.
ENDTRY.
2014 Apr 07 12:25 PM
ok looks ~ good, do you get the message 'Email sent!'? please try to change code temporarily, but don't forget to remove it later:
IF gv_sent_to_all = 'X'.
WRITE 'Email sent!'.
ELSE.
break-point.
ENDIF.
what tells you the SOST transaction, aren't there some mails waiting to be sent? do you have SCOT transaction configured? (SMTP node) maybe it's not more likely basis problem
2014 Apr 07 1:15 PM
Hi,
Its not basis problem, before the dump its works fine, email sending was working properly.
And checked in SOST transaction there is no request, with specified email id.
Thanks,
Siva
2014 Apr 07 4:36 PM
Hi Riha,
Exception is got at the add_attachment method.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'png' " Document Class for Attachment
i_attachment_subject = 'img1' " Attachment Title
i_attachment_size = lv_img1_size " Size of Document Content
i_att_content_hex = lt_hex1 " Content (Binary)
).
inside that method it calls the FM CALL FUNCTION 'SO_ATTACHMENT_INSERT_API1'
where the exception throw ed DOCUMENT_NOT_EXIST = 1.
Thanks,
Siva
2014 Apr 07 5:05 PM
It's gr_document not lo_document...
same as:
gr_document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = t_html
i_importance = '5'
i_subject = gc_subject ).
and not sure if u need a create object lo_document..
2014 Apr 07 5:30 PM
Hi,
Check lt_hex1 and lt_hex2 are populated before calling the add_attachment method.
2014 Apr 07 7:13 PM
Hi, Venkat Krishna is right, why do you have two instances of CL_DOCUMENT_BCS, it's probably mistake. Append the attachments to the gr_document.
Also I don't see where you initialize gr_send_request object. It should be like this:
| gr_send_request = CL_BCS=>CREATE_PERSISTENT( ). |
gr_send_request->SET_DOCUMENT( I_DOCUMENT = MR_DOC ).
A good document related to the sending mails using CL_DOCUMENT_BCS class is there. IF you can, take it a while to understand single steps you do, it's not long.
Br
Bohuslav
2014 Apr 08 1:20 PM
Thanks Bohuslav!
Can try this:
data: gr_bcs_exception TYPE REF TO cx_bcs.
TRY.
gr_document = cl_bcs=>create_persistent( ).
TRY.
gr_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_text
i_subject = lv_subject ).
CATCH cx_bcs INTO lo_bcs_exception.
l_text = gr_bcs_exception->get_text( ).
ENDTRY.
CATCH cx_bcs INTO lo_bcs_exception.
l_text = gr_bcs_exception->get_text( ).
ENDTRY.
2014 Apr 09 8:11 AM
Hi All,
Problem solved .. I debugged the method add_attachment where the images goes is blank ... And attachment is going as blank value and it should be RAW.
So i referred the same gr_document-> add_attachment and working fine
Thanks,
Siva
2014 Apr 09 8:16 AM
2014 Apr 09 8:46 AM
2014 Apr 09 10:57 AM
2014 Apr 09 10:57 AM