2008 Apr 24 5:17 PM
I am using CL_BCS class for sending mail. I have txt file with coma delimited, i need to send this as email attachment. Everything is okay , but attachment extension is showing as .TXT instead of .CSV
How to change this.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = psubject ).
call method document->add_attachment
exporting
i_attachment_type = 'RAW'
i_attachment_subject = 'Y_GEMR_REPORT.CSV'
i_att_content_text = i_attach[].
Here in the mail it is showing attachment showing as Y_GEMR_REPORT.CSV.TXT
Any Info?.
2008 Apr 24 8:21 PM
Hi a®s ,
Check the below code
FIELD-SYMBOLS: <lfs_table>, " Internal table structure
<lfs_con>. " Field Content
DATA: l_text TYPE char1024. " Text content for mail attachment
DATA: l_con(50) TYPE c. " Field Content in character format
* Columns to be tab delimeted
LOOP AT i_mara ASSIGNING <lfs_table>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
TO <lfs_con>.
IF sy-subrc NE 0.
CONCATENATE c_cr l_text INTO l_text.
APPEND l_text TO i_attach.
EXIT.
ELSE.
CLEAR: l_con.
MOVE <lfs_con> TO l_con.
CONDENSE l_con.
IF sy-index = 1.
CLEAR: l_text.
MOVE l_con TO l_text.
ELSE.
CONCATENATE l_text l_con INTO l_text
SEPARATED BY ','. "For comma separated file
ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
* Preparing body of the Mail
MOVE 'Material Details attached' TO l_text.
APPEND l_text TO i_content.
* Creating Document
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = 'Material Details' ).
DESCRIBE TABLE i_mara LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
l_size = l_lines * 2 * 255.
* Adding Attachment
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = 'CSV' "For CSV file Extension
i_attachment_size = l_size
i_attachment_subject = 'Material Details'
i_att_content_text = i_attach[].
Hope this helps.
Thanks,
Balaji
Edited by: Balaji Ganapathiraman on Apr 25, 2008 12:52 AM
I am using CL_BCS class for sending mail. I have txt file with coma delimited, i need to send this as email attachment. Everything is okay , but attachment extension is showing as .TXT instead of .CSV
How to change this.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = psubject ).
call method document->add_attachment
exporting
i_attachment_type = 'RAW'
i_attachment_subject = 'Y_GEMR_REPORT.CSV'
i_att_content_text = i_attach[].
Here in the mail it is showing attachment showing as Y_GEMR_REPORT.CSV.TXT
Any Info?.
2008 Apr 24 6:48 PM
I'm not using the type 'RAW' but I'm always using the real extension type for the documents I'm sending like this:
CALL METHOD ir_document->add_attachment
EXPORTING
i_attachment_type = lv_type
i_attachment_subject = lv_subject
i_attachment_size = lv_size
I_ATTACHMENT_LANGUAGE = SPACE
I_ATT_CONTENT_TEXT =
i_att_content_hex = lt_content
I_ATTACHMENT_HEADER =
and lv_type is determined like this:
lv_type = lw_file_access_info-file_name+lv_length(3).
and for create_document I do this:
Create document.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_text
i_length = l_strlen
Edited by: Micky Oestreich on Apr 24, 2008 7:51 PM
2008 Apr 24 6:55 PM
Mike thanks for your reply.
I tried to use i_attachment_type with values CSV XLS WIN but after using these my attachments contents are coming in a single line on one column. its not siting properly in different columns.
But if i am using RAW in the attachment data sits properly in column if you are opening in excel. Only thing user need to do is while saving the attachment from the mail they need to rename attachment as .CSV , then everything is okay.
a®
2008 Apr 24 7:37 PM
2008 Apr 24 7:41 PM
I'll have a closer look at my coding, I'll try and get back to you today.
2008 Apr 24 8:15 PM
Try i_attachment_type as 'XLS' and provide file name in i_attachment_subject.
As you said this is causing entire row wrapping up into single column, solution for this is usage of CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB as delimiter while constructing your excel file.
G@urav.
2008 Apr 24 8:29 PM
a®s,
before sending the data I convert all the files to binary data using the standard function modules from function group SCMS_CONV.
First I determine if the file content is Binary or not. If binary I use FM 'SCMS_BINARY_TO_XSTRING' and 'SCMS_XSTRING_TO_BINARY' (just to get the correct format of the binary_tab for use later on.
If file content is not binary I convert to binary using 'SCMS_TEXT_TO_BINARY'.
The binary data returned (LT_CONTENT) from these function modules I use in:
TRY.
CALL METHOD ir_document->add_attachment
EXPORTING
i_attachment_type = lv_type
i_attachment_subject = lv_subject
i_attachment_size = lv_size
I_ATTACHMENT_LANGUAGE = SPACE
I_ATT_CONTENT_TEXT =
i_att_content_hex = LT_CONTENT
I_ATTACHMENT_HEADER =
.
CATCH cx_document_bcs .
ENDTRY.
Hope this helps, works for me for sending all sorts of attachments (whether it be XLS, PDF, DOC, TXT, etc).
BTW: In the subject I'm not using the EXTENSION anymore, just the name of the file WITHOUT extension.
Edited by: Micky Oestreich on Apr 24, 2008 9:31 PM
2008 Apr 24 8:56 PM
Mike,
I will get back to you tommorow regarding your reply.
Gaurav,
Your soluation fills whole contents in a single cell . in the attachment and columns are not sits properly in each cell
Balaji,
Your salso the same result as mentioned for Gaurav.
Thanks for your time
a®
2008 Apr 24 9:02 PM
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB as delimiter is giving me data in proper columns..
How are you creating your file? Are you uploading it from some location?
G@urav.
2008 Apr 24 9:12 PM
Gaurav,
I am using coma delimiter for CSV.
and also tried with
loop at i_spldata into wa_spldata.
move wa_spldata to wa_repdata.
concatenate wa_repdata-field1 ','
wa_repdata-field2 ','
wa_repdata-field3 ','
wa_repdata-field4 ','
wa_repdata-field5 ','
wa_repdata-field6 ','
wa_repdata-field7 ','
wa_repdata-field8 ','
wa_repdata-field9 ','
into i_objtxt.
condense i_objtxt no-gaps.
append i_objtxt..
endloop.
endif.
if not i_objtxt[] is initial.
loop at i_objtxt.
move i_objtxt to wa_attach.
append wa_attach to i_attach.
endloop.
endif.
then i tried with
loop at i_spldata into wa_spldata.
move wa_spldata to wa_repdata.
concatenate wa_repdata-field1 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field2 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field3 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field4 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field5 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field6 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field7 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field8 cl_abap_char_utilities=>horizontal_tab
wa_repdata-field9 cl_abap_char_utilities=>horizontal_tab
into i_objtxt.
append i_objtxt..
endloop.
But results in the attachment as showing as .XLS but contains sits in single column
I am also tried to open the excel with version 2000, 2003, 2007 but all are giving same thing
a®
2008 Apr 24 9:23 PM
I tried something like this..
DATA: XLS_FILE TYPE STRING,
v_delimiter TYPE CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
WITH SMART LINEFEED.
IF SY-SUBRC = 0.
loop at it_final.
CONCATENATE I_FINAL-VBELN I_FINAL-POSNR I_FINAL-AUART
I_FINAL-VKORG I_FINAL-KUNNR I_FINAL-NAME I_FINAL-KUNNR1
I_FINAL-CUST_NAME I_FINAL-CITY1 I_FINAL-REGION I_FINAL-COUNTRY
VSBED_VTEXT I_FINAL-SDABW_DESC I_FINAL-VSTEL I_FINAL-VTEXT
I_FINAL-SPART I_FINAL-ARKTX CKWMENG I_FINAL-EMP
I_FINAL-REQ_EDATU I_FINAL-REQ_WADAT I_FINAL-PLND_WADAT
I_FINAL-INCOM I_FINAL-FAKSK I_FINAL-LIFSK I_FINAL-CREDIT
INTO XLS_FILE SEPARATED BY V_DELIMITER.
TRANSFER XLS_FILE TO P_FILE.
ENDLOOP.
CLOSE DATASET P_FILE.
endif.The file i got is perfectly splitted into columns.
G@urav.
2008 Apr 24 9:36 PM
Gaurav,
I am generating the file and sending without writing anywhere. I tried to write to Unix and read and send it working fine. But here users don't have to right to write their files in the unix directory.
so i could not able to use that logic.
Thanks anyway for your reply.
a®
2008 May 12 5:00 PM
2011 Sep 13 2:37 PM
Hi a@s,
Can you post how this problem was fixed.. we are experiencing the same issue like .TXT being append to attachment name..
Thanks.
2011 Sep 13 3:19 PM
2008 Apr 24 8:00 PM
2008 Apr 24 8:11 PM
Venkat,
The link you have given have nothing related to changing attachment extension.
a®
2008 Apr 24 8:21 PM
Hi a®s ,
Check the below code
FIELD-SYMBOLS: <lfs_table>, " Internal table structure
<lfs_con>. " Field Content
DATA: l_text TYPE char1024. " Text content for mail attachment
DATA: l_con(50) TYPE c. " Field Content in character format
* Columns to be tab delimeted
LOOP AT i_mara ASSIGNING <lfs_table>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
TO <lfs_con>.
IF sy-subrc NE 0.
CONCATENATE c_cr l_text INTO l_text.
APPEND l_text TO i_attach.
EXIT.
ELSE.
CLEAR: l_con.
MOVE <lfs_con> TO l_con.
CONDENSE l_con.
IF sy-index = 1.
CLEAR: l_text.
MOVE l_con TO l_text.
ELSE.
CONCATENATE l_text l_con INTO l_text
SEPARATED BY ','. "For comma separated file
ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
* Preparing body of the Mail
MOVE 'Material Details attached' TO l_text.
APPEND l_text TO i_content.
* Creating Document
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = 'Material Details' ).
DESCRIBE TABLE i_mara LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
l_size = l_lines * 2 * 255.
* Adding Attachment
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = 'CSV' "For CSV file Extension
i_attachment_size = l_size
i_attachment_subject = 'Material Details'
i_att_content_text = i_attach[].
Hope this helps.
Thanks,
Balaji
Edited by: Balaji Ganapathiraman on Apr 25, 2008 12:52 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |