Application Development 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: 

Sending Text-File more than 255 characters VIA MAIL.

Former Member
0 Kudos

Hi Experts,

iám trying to send a text-file from my application server via Mail.

The Function Modul which i found is "SO_NEW_DOCUMENT_ATT_SEND_API1".

The Disadvantages for this FM is, that i cant sending mail directly from Application Server.

-> First i must upload my tex-file in a internal table and must give him.

-> If i have a row´s in my text-file which have more than 255 Characters, than it will not work because this FM allowed only 255 Characters.

What can i do?

Have anyone another idea, because i had search in sdn but nothing found!!!

Thanks in forward.

1 ACCEPTED SOLUTION

P561888
Active Contributor
0 Kudos

Hi ,

See the example code below, we have to use the FM 'TEXT_SPLIT', this will split at 255 and prepare new line.

Final table for the FM SO_NEW DOCUMENT_ATT_SEND_API is i_attach.

LOOP AT i_email.

CONCATENATE i_email-matnr

i_email-werks

i_email-lgort

i_email-kunnr

i_email-name1

i_email-vbeln

i_email-posnr

i_email-lfimg

i_email-pkconf

i_email-cost

i_email-curr

i_email-sal_order

i_email-sal_itm

i_email-ord_qty

i_email-bu

i_email-prctr

i_email-usg_ind

i_email-ord_reas

i_email-accp_dat

i_email-instal_date

i_email-dismat_date

INTO l_string SEPARATED BY con_tab.

WHILE l_string <> space.

CALL FUNCTION 'TEXT_SPLIT'

EXPORTING

length = 255

text = l_string

IMPORTING

LINE = i_attach

REST = l_string.

IF l_string = space.

CONCATENATE i_attach con_cret INTO i_attach.

APPEND i_attach.

CLEAR i_attach.

ELSE.

APPEND i_attach.

CLEAR i_attach.

ENDIF.

ENDWHILE.

Thanks and Regards,

Bharani

15 REPLIES 15

Former Member
0 Kudos

Hi,

The reason is because the itab for attachment in the mail is less than 255 length. Hence we have to convert the original data of attachment, and put into a proper table of the required length.

you can try using fm

SX_TABLE_LINE_WIDTH_CHANGE

before putting the contents in the email itab.

regards,

amit m.

P561888
Active Contributor
0 Kudos

Hi ,

See the example code below, we have to use the FM 'TEXT_SPLIT', this will split at 255 and prepare new line.

Final table for the FM SO_NEW DOCUMENT_ATT_SEND_API is i_attach.

LOOP AT i_email.

CONCATENATE i_email-matnr

i_email-werks

i_email-lgort

i_email-kunnr

i_email-name1

i_email-vbeln

i_email-posnr

i_email-lfimg

i_email-pkconf

i_email-cost

i_email-curr

i_email-sal_order

i_email-sal_itm

i_email-ord_qty

i_email-bu

i_email-prctr

i_email-usg_ind

i_email-ord_reas

i_email-accp_dat

i_email-instal_date

i_email-dismat_date

INTO l_string SEPARATED BY con_tab.

WHILE l_string <> space.

CALL FUNCTION 'TEXT_SPLIT'

EXPORTING

length = 255

text = l_string

IMPORTING

LINE = i_attach

REST = l_string.

IF l_string = space.

CONCATENATE i_attach con_cret INTO i_attach.

APPEND i_attach.

CLEAR i_attach.

ELSE.

APPEND i_attach.

CLEAR i_attach.

ENDIF.

ENDWHILE.

Thanks and Regards,

Bharani

Former Member
0 Kudos

Thanks for your helps,

but the first idea with the FM "SX_TABLE_LINE_WIDTH_CHANGE" was not possible.

The row in my text-file has 728 characters and it is separated by comma.

I dont now, but is it possible to send a mail directly with a attachement, that i can give to a FM the Path/link from the Text-File???

Than the FM can get this file directly from the Application Server and can sending!

Is this idea possible?

P561888
Active Contributor
0 Kudos

Hi,

TEXT_SPLIT can split the 728 char to first 255 then again , it will see the remaining 255 char if it reach the last then carriage return and line feed will be added to the line, that means it is the end of line.

Thanks and Regards,

Bharani

Former Member
0 Kudos

Thank you Bharani,

but look in my textfield is the row separated by commas like:

9000;0,00;EUR;SPAIN;......... and this row is 750 characters long.

I need this separation for excel. If i make a split with 255 characters, than i have 3 rows for 1 complete row.

But if i open this text-file with excel, than excel will think that this 3 rows are all new rows.

0 Kudos

I think if the data is passed as binary, it can be resolved. Check if this wiki helps.....

http://wiki.sdn.sap.com/wiki/display/Snippets/Tosendamailattachmentwithmorethan255charactersinaline

Former Member
0 Kudos

Hello Satyajit,

i have understand your example, but if i send my internal table with Binary-Format, how can the user open the Attachement-File??

In this File is a CSV-Format with separation ";".

Can the Receiver directly still open this File in Excel, when i send it in Binary-Format??

0 Kudos

There should be no problems with the file contents. Try it once....

Also, I'm not sure if there is an function module/class which can directly send the file from application server as an email attachment. As per my knowledge, in any case we need to read the data into internal table and then send it as an attachment.

Former Member
0 Kudos

Sorry,

but it not works with Binary-Format.

Because if i create a Binary-Format an sending this as attachment-File, than the receiver cant open this file in Excel.

The Receiver must become a txt, csv or excel-file.

But problem is, that i cant sending a attachement with more than 255 characters per line.

I have become also a idea to work with Function Modul u201CSX_TABLE_LINE_WIDTH_CHANGEu201D, but how will it works??

I have a internal table with one column-name = "line".

And this Internal table can have many rows, Each of these rows have more than 255 characters.

If someone know the usage for this Function Modul, than please show me a simple coding.

0 Kudos

I'm not sure about this problem. Could you please attach relevant sections of your code...............

Former Member
0 Kudos

TYPES: BEGIN OF struc_list,

line TYPE string,

END OF struc_list.

DATA: op_liste TYPE STANDARD TABLE OF struc_list,

wa_liste TYPE struc_list,

li_contents-line TYPE xstring,

li_contents_hex TYPE STANDARD TABLE OF solix WITH HEADER LINE,

i_contents_hex TYPE STANDARD TABLE OF solix WITH HEADER LINE,

t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

e_document_data LIKE sodocchgi1,

t_contents_txt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

The Table *opliste*_ have many entry(rows) and each of them are ca. 750 Characters long.

Input in the Table *opliste*_:

Row 1: Company Code;WRBTR1;Currency1;WRBTR2;Currency2;WRBTR3;Currency3;.................

Row 2: 9000;0,00;EUR;0,00;EUR;0,00;EUR;0,00;EUR;0,00;EUR;................

Row 3: ....................

..............

Reason for Separation ";":

The Receiver of this text-file, should open it with Excel. They need it only for Excel-calculation.

But problem now is, that i can only sending text-files with maximum 255 Characters per Row.

And the idea with Binary-Format cant be opened with Excel.

**********************************Email Sending with attachment***********************************

*Converting the table contents for attachment to xstring

LOOP AT op_liste INTO wa_liste.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = wa_liste-line

IMPORTING

buffer = li_contents-line

EXCEPTIONS

failed = 1

OTHERS = 2.

*Converting the table contents from xstring to binary

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = li_contents-line

  • APPEND_TO_TABLE = 'I_CONTENTS_HEX'

TABLES

binary_tab = li_contents_hex.

LOOP AT li_contents_hex.

APPEND li_contents_hex TO i_contents_hex .

ENDLOOP.

ENDLOOP.

DESCRIBE TABLE i_contents_hex LINES tab_lines.

                  • Data-Information for Mail

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

t_packing_list-body_num = tab_lines.

t_packing_list-doc_type = 'BIN'.

t_packing_list-obj_name = 'ANLAGE'.

t_packing_list-doc_size = tab_lines * 2000.

t_packing_list-obj_descr = 'Protokoll'.

APPEND t_packing_list.

e_document_data-obj_name = 'TEST'.

e_document_data-obj_descr = 'OPLISTE Excel-Format'.

t_contents_txt = 'Sehr geehrte Damen und Herren, Hallo, usw'.

APPEND t_contents_txt.

t_receivers-receiver = 'John.Debtorsap.com'.

t_receivers-rec_type = 'U'.

APPEND t_receivers.

  • FM called for sending the mail to the intended recipients

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = e_document_data

  • put_in_outbox = 'X'

commit_work = 'X'

  • IMPORTING

  • sent_to_all = sent_to_all

TABLES

packing_list = t_packing_list

  • object_header = i_objhead

  • contents_hex = i_contents_hex

contents_txt = t_contents_txt

receivers = t_receivers.

0 Kudos

Concatenate all the lines in the internal table to one string using line feed of CL_ABAP_CHAR_UTILITIES after each line. Then convert the string to xstring and xstring to binary, instead of converting each line separately...

Former Member
0 Kudos

... can you give me a coding as an example?

And after each row at end of a line i must put the Class CL_ABAP_CHAR_UTILITIES????

For what and how you will put it?

Please try to send me a coding, that iám able to relate your ideas.

Edited by: ETN_58 on Dec 1, 2010 1:22 PM

0 Kudos

Hi ..

I am geting same problem that sening the text file attachment mail in background in which more than 255 char row length is required. But after 255 char the program turncate the rest text in attached file data.

Please help me out...

DavidLY
Advisor
Advisor
0 Kudos

Hello,

Check also SAP note 190669.

Regards,

David