05-05-2008 8:44 AM
Hi ,
I am having a report which displays 96 columns using ALV list display.
The final internal table say it_out holds the entire 96 columns whose horizontal scrolling width exceeds 1023 characters.
Now when this report is executed in background, the content of this internal table (96 columns) needs to be sent as an excel attachment to certain people.
for sending the attachment as an email, I am using the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' but its interface parameter (tables) "contents_txt" can support only 255 chara length.
So if the internal table's horizontal length is more than 255 characters then the rest would be truncated and in this case its happening the same.
hence, please suggest a FM or any other technique which does not have any length restriction while sending an attachment as an email.
Thanks in advance
Ramesh
05-05-2008 8:53 AM
Please try using class CL_BCS. Reply in below link can help you understand the usage: [Sending Mail using class CL_BCS|https://forums.sdn.sap.com/click.jspa?searchID=11420638&messageID=5104141]
05-05-2008 11:40 AM
Hi Eswar,
thanks for ur reply.
The eg which u had given using the method ADD_ATTACHMENT of the class/interface "CL_DOCUMENT_BCS" uses the interface parameter "I_ATT_CONTENT_TEXT" of type "SOLI_TAB" whose length is Char 255 only.
Hence all content beyond 255 will be truncated.
Is there any other method/FM by which we can achieve this functionality.
Thanks in advance
Ramesh
05-06-2008 2:26 AM
Please try executing the code in a temporary program, check the result and let me know if you still have problem with the length. Observe the code in routine PREPARE_ATTACHMENT which handles the length.
05-06-2008 7:04 AM
The routine prepare_attachment which u have mentioned is inside which class ?
I am not able to find it in class * cl_BCS *.
awaiting ur reply
regards
Ramesh
05-06-2008 7:15 AM
Have you really gone through the code in the link i have provided you earlier? PREPARE_ATTACHMENT is a subroutine of the custom code in the link. Have you got any problem executing the same code?
05-06-2008 7:28 AM
Hi,
I did go through prepare_attachment subroutine which u have mentioned .
That subroutine uses the table i_attach of type soli_tab whose length is 255 chara.
Hence this cannot cater to my requirement.
In short I would require a FM which would send email to an external mail id as weel as SAP Inbox with an excel attachment, the internal table which holds the excel attachment should not have any length restriction eg could be of type string since my excel attachment file's horizontal width is more than 1023 chara.
regards
Ramesh
05-06-2008 8:29 AM
I wish you can understand my second reply for the thread. I have asked you to copy the code in the link to a temporary program, execute and check the attachment in the mail and let me know if it is not more than 255 characters. If you are still in the impression that i havent understood your problem is with the width of the list then my friend i am sorry i can not help you any more. Good Luck.
05-06-2008 8:38 AM
Hi,
I have made a temp program with that code, executed it , but the contents beyond 255 are truncated.
I beleive u can understand the issue.
regards
Ramesh
05-06-2008 8:42 AM
Hi,
Have a look on the below mentioned code hope this helps...
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.
Regds
Seema
05-06-2008 10:12 AM
Hi,
Thanks for your feedback. Have modified the custom code to test that it works for length above 255 characters.
Check below code and see if it helps
PARAMETERS: p_mail TYPE ad_smtpadr OBLIGATORY.
DATA: i_str TYPE TABLE OF string,
wa_str TYPE string.
DATA: g_text TYPE char255. " Text
DATA: g_lines TYPE i,
g_size TYPE sood-objlen. " Size of Attachment
* Mail related
DATA: i_content TYPE soli_tab, " Mail content
i_attach TYPE soli_tab. " Attachment
DATA: l_send_request TYPE REF TO cl_bcs,
" E-Mail Send Request
l_document TYPE REF TO cl_document_bcs,
" E-Mail Attachment
l_recipient TYPE REF TO if_recipient_bcs,
" Distribution List
l_sender TYPE REF TO if_sender_bcs,
" Address of Sender
l_uname TYPE salrtdrcpt,
" Sender Name(SY-UNAME)
l_bcs_exception TYPE REF TO cx_document_bcs,
" BCS Exception
l_addr_exception TYPE REF TO cx_address_bcs,
" Address Exception
l_send_exception TYPE REF TO cx_send_req_bcs.
" E-Mail sending Exception
*
*Constants------------------------------------------------------------*
CONSTANTS: c_cr(1) TYPE c VALUE cl_abap_char_utilities=>cr_lf,
" Line Feed for End-Of_line
c_ext TYPE soodk-objtp VALUE 'XLS'. " XLS Extension
CONSTANTS: c_alpha TYPE string
VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
START-OF-SELECTION.
DO 20 TIMES.
CONCATENATE wa_str c_alpha INTO wa_str.
APPEND wa_str TO i_str.
ENDDO.
* Preparing body of the Mail
MOVE 'Mail Body' TO g_text.
APPEND g_text TO i_content.
* Preparing contents of attachment with Change Log
PERFORM prepare_attachment.
* Creates persistent send request
TRY.
l_send_request = cl_bcs=>create_persistent( ).
* Creating Document
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = 'Test Data' ).
DESCRIBE TABLE i_attach LINES g_lines.
* Size to multiplied by 2 for UNICODE enabled systems
g_size = g_lines * 2 * 255.
* Adding Attachment
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = c_ext
i_attachment_size = g_size
i_attachment_subject = 'Excel Document'
i_att_content_text = i_attach[].
* Add document to send request
CALL METHOD l_send_request->set_document( l_document ).
* Get Sender Object
l_uname = sy-uname.
l_sender = cl_sapuser_bcs=>create( l_uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
* E-Mail
TRANSLATE p_mail TO LOWER CASE.
l_recipient = cl_cam_address_bcs=>create_internet_address( p_mail )
.
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'U'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
*Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).
CALL METHOD l_send_request->send( ).
COMMIT WORK.
CATCH cx_document_bcs INTO l_bcs_exception.
CATCH cx_send_req_bcs INTO l_send_exception.
CATCH cx_address_bcs INTO l_addr_exception.
ENDTRY.
*&---------------------------------------------------------------------
*
*& Form PREPARE_ATTACHMENT
*&---------------------------------------------------------------------
*
FORM prepare_attachment .
DATA: l_text TYPE string. " Text Content for Mail Attachment
DATA: l_len TYPE i,
l_start TYPE i,
l_end TYPE i,
l_pos TYPE i.
LOOP AT i_str INTO wa_str.
CONCATENATE c_cr wa_str INTO wa_str.
l_len = STRLEN( wa_str ).
IF l_len > 255.
l_start = 0.
l_end = 255.
WHILE l_start < l_len.
l_pos = l_end - l_start.
APPEND wa_str+l_start(l_pos) TO i_attach.
l_start = l_end.
l_end = l_start + 255.
IF l_end > l_len.
l_end = l_len.
ENDIF.
ENDWHILE.
ELSE.
APPEND wa_str TO i_attach.
ENDIF.
ENDLOOP.
ENDFORM. " PREPARE_ATTACHMENT