Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

EMAIL ATTACHMENT NOT IN RIGHT FORMAT

Former Member
0 Likes
2,298

Hi,

Can anyone help me on my program that requires email with attachment. I have completed the codes that sends the email however the attachment has a bad format.

The attachment should be in text format, contains a table data, which should be seperated by tabs and carriage return. I had tested this in other boxes where it was working well however in ECC60, the attachment shows a long strip of string seperated by tabs and a wierd character (a box?) that signifies a carriage return. The width of the text file became 1022 characters until carriage return (for another row?).

The contents of the attachment is stored in an internal table, which is used for FM SO_NEW_DOCU*. I had seen some solutions/codes of other threads however the solution does not suit on my problem. I had also applied some codes for active unicode enabled programs on the concatenation with a hex type (tab or carriage return)to the string unto the internal table, such us for variables of type x, applied some type casting and the class cl_abap_char_utilities. Still, it doesn't work on the attachment. What seems to be the problem?

There is also a solution where I get to change the value of a field of a standard table. However we are not authorized to do so.

6 REPLIES 6
Read only

Former Member
0 Likes
1,519

Hi

<b>Here is custom sample code for E-mail purpose</b>

*---------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Report ZSEND
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report zsend .

tables: kna1.

* data for send function
data doc_data like sodocchgi1.
data object_id like soodk.
data objcont like soli occurs 10 with header line.
data receiver like somlreci1 occurs 1 with header line.

select * from kna1 where anred like 'C%'.
write:/ kna1-kunnr, kna1-anred.

* send data internal table
concatenate kna1-kunnr kna1-anred
into objcont-line separated by space.

append objcont.
endselect.

* insert receiver (sap name)
refresh receiver.
clear receiver.
move: sy-uname to receiver-receiver,
'X' to receiver-express,
'B' to receiver-rec_type.
append receiver.

* insert mail description
write 'Sending a mail through abap'
to doc_data-obj_descr.

call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = doc_data
importing
new_object_id = object_id
tables
object_content = objcont
receivers = receiver
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.


*---------------------------------------------------------*

Hope this will help.

Please reward suitable points.

Regards

- Atul

Read only

Former Member
0 Likes
1,519

Hi,

You need use the CL_ABAP_CHAR_UTILITIES=>CR_LF for a Line break in the Atachment,

you have the data in the internal table, so after completing the firstline add the above line feed class and append the internal table,you need to append this for every line break

Regards

Sudheer

Read only

Former Member
0 Likes
1,519

Hi,

Is it possible to use a text format on the Function Module "O_NEW_DOCUMENT_ATT_SEND_API1" in ECC 6.0? Beacuse alot of your examples are using XLS Format attachments. I had been attaching text fomat file in the mail and when I open the text attachment, the expected format is not satisfied. Still the result is a long string (max1022 char). It should be a tab-delimited text file.

Read only

0 Likes
1,519

Hi

<b>Yes it is possible..

Instead of 'XLS' you can use 'TXT' or 'ASC' (Ascii format) depending on your requirement.</b>

Hope this will help.

Please reward suitable points.

Regards

- Atul

Read only

Former Member
0 Likes
1,519

Hi

<b>All the possible attachment types

which can be used in this function module - SO_NEW_DOCUMENT_SEND_API1

for attachment purpose

in ECC 6.0 Version are as follows -></b>


-------------------------------------
Type        Description
---------------------------------------
ALI   ABAP list document        
ARC   Archive object (image)    
BCS   External Document Storage 
BIN   Binary document           
DLI   Distribution list         
EXT   PC document               
FAX   Fax                       
FOL   Folder                    
GRA   SAP Business Graphics     
OBJ   Business object           
OFO   Object folder             
OTF   OTF document              
R3I   IDoc                      
RAW   SAP editor document       
SCR   SAPscript document        
URL   Link to Internet/Intranet 
WIM   Work item                 
XXL   Document for list viewer 

Hope this will help.

Please reward suitable points.

Regards

- Atul

Read only

Former Member
0 Likes
1,519

Hi

Try this code

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: pFile Like rlgrap-filename.

At Selection-Screen On Value-Request For pFile.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = space

DEF_PATH = pFile

MASK = 'All files'

IMPORTING

FILENAME = pFile.

Start-of-selection.

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

EXPORTING

user = g_user

IMPORTING

user_data = g_user_data.

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-objdes = 'testing by program'.

*g_document-folrg = 'O'.

*g_document-objlen = '0'.

*g_document-file_ext = 'TXT'.

g_header-objdes = 'Checking email 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.

method1 = 'ATTCREATEFROMPC'.

g_files-text = pfile.

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.

HOpe this helps.

Regds,

Seema