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: 

mail, output of spool as an excel attachment

Former Member
0 Kudos

Hello All,

I'm required to schedule a report, and e-mail the output as an excel attachment.

I have gone through many threads, but could'nt find a solution.

Queries:

1) usage of FM 'SAP_CONVERT_TO_XLS_FORMAT' .

Am i supposed to have a physical file on my system, in which i'll get converted data to excel, to be passed as a parameter.

2) Is there any preference on using the FM

'SO_NEW_DOCUMENT_ATT_SEND_API1' and 'SO_DOCUMENT_SEND_API1'.

Thanks.

Ushma.

Edited by: Ushma Jain on Jun 6, 2009 1:54 PM

1 ACCEPTED SOLUTION

former_member205763
Active Contributor
0 Kudos

if u have an output internal table as report output, u can directly convert the output internal table to xls without considering converting spool to excel.

"document information
  w_doc_chng-obj_name = text-005.            " Excel
  w_doc_chng-obj_descr = text-006.           "Excel For not deleted planned Orders
  w_doc_chng-sensitivty = text-007.          " F ->Functional object
  w_doc_chng-doc_size = ( message_lines - 1 ) * 255 + STRLEN( wa_imessage-line ).  " calculating total size of doc


  " displaying planned order no , material , plant in the excel

  CONCATENATE 'PLANNED ORDER' 'MATERIAL' 'PLANT' INTO wa_objbin SEPARATED BY c_tab.
  APPEND wa_objbin TO it_objbin.

  CLEAR : wa_objbin.
  LOOP AT it_not_del INTO wa_not_del.
    CONCATENATE wa_not_del-plnum wa_not_del-matnr wa_not_del-pwwrk INTO wa_objbin SEPARATED BY c_tab.
    CONCATENATE c_ret wa_objbin INTO wa_objbin.
    APPEND wa_objbin TO it_objbin.
  ENDLOOP.

  DESCRIBE TABLE it_objbin LINES v_lines_bin.   " no of lines for excel data


  " pack the data as RAW
  CLEAR wa_it_objpack-transf_bin.                     "Obj. to be transported not in binary form
  wa_it_objpack-head_start = 1.                   "Start line of object header in transport packet
  wa_it_objpack-head_num = 0.                     "Number of lines of an object header in object packet
  wa_it_objpack-body_start = 1.                   "Start line of object contents in an object packet
  wa_it_objpack-body_num = message_lines.         "Number of lines of the mail body
  wa_it_objpack-doc_type = text-008.           "RAW
  APPEND wa_it_objpack TO it_objpack.


Edited by: Kartik Tarla on Jun 6, 2009 5:41 PM

Edited by: Kartik Tarla on Jun 6, 2009 5:42 PM

38 REPLIES 38

former_member205763
Active Contributor
0 Kudos

if u have an output internal table as report output, u can directly convert the output internal table to xls without considering converting spool to excel.

"document information
  w_doc_chng-obj_name = text-005.            " Excel
  w_doc_chng-obj_descr = text-006.           "Excel For not deleted planned Orders
  w_doc_chng-sensitivty = text-007.          " F ->Functional object
  w_doc_chng-doc_size = ( message_lines - 1 ) * 255 + STRLEN( wa_imessage-line ).  " calculating total size of doc


  " displaying planned order no , material , plant in the excel

  CONCATENATE 'PLANNED ORDER' 'MATERIAL' 'PLANT' INTO wa_objbin SEPARATED BY c_tab.
  APPEND wa_objbin TO it_objbin.

  CLEAR : wa_objbin.
  LOOP AT it_not_del INTO wa_not_del.
    CONCATENATE wa_not_del-plnum wa_not_del-matnr wa_not_del-pwwrk INTO wa_objbin SEPARATED BY c_tab.
    CONCATENATE c_ret wa_objbin INTO wa_objbin.
    APPEND wa_objbin TO it_objbin.
  ENDLOOP.

  DESCRIBE TABLE it_objbin LINES v_lines_bin.   " no of lines for excel data


  " pack the data as RAW
  CLEAR wa_it_objpack-transf_bin.                     "Obj. to be transported not in binary form
  wa_it_objpack-head_start = 1.                   "Start line of object header in transport packet
  wa_it_objpack-head_num = 0.                     "Number of lines of an object header in object packet
  wa_it_objpack-body_start = 1.                   "Start line of object contents in an object packet
  wa_it_objpack-body_num = message_lines.         "Number of lines of the mail body
  wa_it_objpack-doc_type = text-008.           "RAW
  APPEND wa_it_objpack TO it_objpack.


Edited by: Kartik Tarla on Jun 6, 2009 5:41 PM

Edited by: Kartik Tarla on Jun 6, 2009 5:42 PM

former_member205763
Active Contributor
0 Kudos

code continued as above

" pack the data as excel
  wa_it_objpack-transf_bin = text-009.      " X
  wa_it_objpack-head_start = 1.
  wa_it_objpack-head_num = 1.
  wa_it_objpack-body_start = 1.
  wa_it_objpack-body_num = v_lines_bin.         "no of lines of it_not_del to give no of undeleted planned orders
  wa_it_objpack-doc_type = text-010.         " XLS ->  excel fomat
  wa_it_objpack-obj_name = text-011.         " EXCEL ATTACHMENT

  " attachment name
  CONCATENATE text-012 '.XLS' INTO wa_it_objpack-obj_descr.      " PLANNED ORDERS
  wa_it_objpack-doc_size = v_lines_bin * 255.
  APPEND wa_it_objpack TO it_objpack.

  " creating email id
  CONCATENATE p_email text-017  INTO v_mailaddr.   "@firmenich.com

* e-mail receivers.
  CLEAR wa_it_reclist.
  wa_it_reclist-receiver = v_mailaddr.
  wa_it_reclist-express =  text-009.                      " X
  wa_it_reclist-rec_type = text-013.                      " U ->  Internet address
  APPEND wa_it_reclist TO it_reclist.


  " sending mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = it_objpack
      contents_bin               = it_objbin
      contents_txt               = imessage
      receivers                  = it_reclist
    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.

  COMMIT WORK.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ELSE.
    MESSAGE i397.     "E-mail Sent successfully !!
  ENDIF.

0 Kudos

Hello Kartik,

We hav to hard code the column headings, is it possible to program other way?

Thanks.

Ushma

Edited by: Ushma Jain on Jul 18, 2009 10:09 AM

0 Kudos

I don't get it : why can't you hard code?

0 Kudos

Could you please provide an example of what you want to generate ? For example:


MATERIAL NO;DATE;QUANTITY
19438065;20090804;20.000

0 Kudos

Hello Sandra,

Thanks for going through the post and replying.

But there ar many things to it.

1) I have to code it not for one report, but for a number of reports.

2) Besides, the number of columns are large ( 80 columns ), so typing( coding) each column is tedius and error prone.

I'm looking for a generic way.

If any suggestions , please do reply.

Thanks.

Ushma.

0 Kudos

Hello Sandra,

Thanks for going through the post and replying.

But there ar many things to it.

1) I have to code it not for one report, but for a number of reports.

2) Besides, the number of columns are large ( 80 columns ), so typing( coding) each column is tedius and error prone.

I'm looking for a generic way.

If any suggestions , please do reply.

Thanks.

Ushma.

0 Kudos

hi USHA jAIN,

80 columns in Excel you need to take special care other wise data will be truncated after 256 char!!

Regards

sas

Former Member
0 Kudos

hi..i think we cant control the output format in the email..it depend on what the basis people setting in the transaction code SCOT..double clicking the internet mail and from there you can choose the format to be sent out through email..available option are PDF format, HTML, XLS and TXT. Communicate with the basis people..hope this will help

0 Kudos

Hello,

Can your please elaborate it more.

Thanks.

Ushma

venkat_o
Active Contributor
0 Kudos

<font color=blue>Hi,

Check this sample program. It works. Change accordigly.

<pre>

report zvenkat_mail_xls_attach.

----


" Data retrieval related declarations

----


types:

begin of t_emp_dat,

pernr type pa0001-pernr,

persg type pa0001-persg,

persk type pa0001-persk,

plans type pa0001-plans,

stell type pa0001-stell,

end of t_emp_dat.

data:

w_emp_data type t_emp_dat.

data:

i_emp_data type standard table of t_emp_dat.

----


" Mail related declarations

----


"Variables

data :

g_sent_to_all type sonv-flag,

g_tab_lines type i.

"Types

types:

t_document_data type sodocchgi1,

t_packing_list type sopcklsti1,

t_attachment type solisti1,

t_body_msg type solisti1,

t_receivers type somlreci1.

"Workareas

data :

w_document_data type t_document_data,

w_packing_list type t_packing_list,

w_attachment type t_attachment,

w_body_msg type t_body_msg,

w_receivers type t_receivers.

"Internal Tables

data :

i_document_data type standard table of t_document_data,

i_packing_list type standard table of t_packing_list,

i_attachment type standard table of t_attachment,

i_body_msg type standard table of t_body_msg,

i_receivers type standard table of t_receivers.

parameters:p_mail type char120.

----


"Start-of-selection.

----


start-of-selection.

perform get_data.

perform build_xls_data_table.

----


"End-of-selection.

----


end-of-selection.

perform send_mail.

&----


"Form get_data from PA0001

&----


form get_data.

select pernr

persg

persk

plans

stell

from pa0001

into corresponding fields of table i_emp_data

up to 4 rows.

endform. " get_data

&----


"Form build_xls_data_table

&----


form build_xls_data_table.

"If you have Unicode check active in program attributes then

"you will need to declare constants as follows.

class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>horizontal_tab,

con_cret type c value cl_abap_char_utilities=>cr_lf.

concatenate 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'

into w_attachment

separated by con_tab.

concatenate con_cret

w_attachment

into w_attachment.

append w_attachment to i_attachment.

clear w_attachment.

loop at i_emp_data into w_emp_data.

concatenate w_emp_data-pernr

w_emp_data-persg

w_emp_data-persk

w_emp_data-plans

w_emp_data-stell

into w_attachment

separated by con_tab.

concatenate con_cret w_attachment

into w_attachment.

append w_attachment to i_attachment.

clear w_attachment.

endloop.

endform. "build_xls_data_table

&----


"Form send_mail

"----


"PACKING LIST

"This table requires information about how the data in the

"tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to

"be distributed to the documents and its attachments.The first

"row is for the document, the following rows are each for one

"attachment.

&----


form send_mail .

"Subject of the mail.

w_document_data-obj_name = 'MAIL_TO_HEAD'.

w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

"Body of the mail

perform build_body_of_mail

using:space,

'Hi,',

'I am fine. How are you? How are you doing ? ',

'This program has been created to send simple mail',

'with Subject,Body with Address of the sender. ',

'Regards,',

'Venkat.O,',

'SAP HR Technical Consultant.'.

"Write Packing List for Body

describe table i_body_msg lines g_tab_lines.

w_packing_list-head_start = 1.

w_packing_list-head_num = 0.

w_packing_list-body_start = 1.

w_packing_list-body_num = g_tab_lines.

w_packing_list-doc_type = 'RAW'.

append w_packing_list to i_packing_list.

clear w_packing_list.

"Write Packing List for Attachment

w_packing_list-transf_bin = 'X'.

w_packing_list-head_start = 1.

w_packing_list-head_num = 1.

w_packing_list-body_start = 1.

describe table i_attachment lines w_packing_list-body_num.

w_packing_list-doc_type = 'XLS'.

w_packing_list-obj_descr = 'Excell Attachment'.

w_packing_list-obj_name = 'XLS_ATTACHMENT'.

w_packing_list-doc_size = w_packing_list-body_num * 255.

append w_packing_list to i_packing_list.

clear w_packing_list.

"Fill the document data and get size of attachment

w_document_data-obj_langu = sy-langu.

read table i_attachment into w_attachment index g_tab_lines.

w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ).

"Receivers List.

w_receivers-rec_type = 'U'. "Internet address

w_receivers-receiver = p_mail.

w_receivers-com_type = 'INT'.

w_receivers-notif_del = 'X'.

w_receivers-notif_ndel = 'X'.

append w_receivers to i_receivers .

clear:w_receivers.

"Function module to send mail to Recipients

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = w_document_data

put_in_outbox = 'X'

commit_work = 'X'

importing

sent_to_all = g_sent_to_all

tables

packing_list = i_packing_list

contents_bin = i_attachment

contents_txt = i_body_msg

receivers = i_receivers

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.

if sy-subrc = 0 .

message i303(me) with 'Mail has been Successfully Sent.'.

else.

wait up to 2 seconds.

"This program starts the SAPconnect send process.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " send_mail

&----


" Form build_body_of_mail

&----


form build_body_of_mail using l_message.

w_body_msg = l_message.

append w_body_msg to i_body_msg.

clear w_body_msg.

endform. " build_body_of_mail

</pre>

Thanks

venkat.O<font>

Sandra_Rossi
Active Contributor
0 Kudos

1) PC file is mandatory for this FM, it generates a true Excel format file, so it can be run only interactively. To generate an excel file on application server, you must generate a text format file (CSV). To generate it generically, use something like this:


DATA gt_itab TYPE TABLE OF t000.
DATA gt_csv TYPE TABLE OF string.
SELECT * FROM t000 INTO TABLE gt_itab.
PERFORM convert_itab_to_csv USING gt_itab ';' CHANGING gt_csv.
*----------------------------------------------------------------------*
FORM convert_itab_to_csv 
      USING 
        it_any              TYPE ANY TABLE
        i_column_separator  TYPE clike
      CHANGING 
        et_csv              TYPE STANDARD TABLE.
  FIELD-SYMBOLS <ls_any> TYPE ANY.
  FIELD-SYMBOLS <l_any> TYPE ANY.
  DATA l_field_num TYPE i.
  DATA l_string TYPE string.
  DATA l_big_char TYPE c LENGTH 255.
  REFRESH et_csv.
  LOOP AT it_any ASSIGNING <ls_any>.
    l_field_num = 0.
    CLEAR l_string.
    DO.
      ADD 1 TO l_field_num.
      ASSIGN COMPONENT l_field_num OF STRUCTURE <ls_any> TO <l_any>.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      WRITE <l_any> TO l_big_char LEFT-JUSTIFIED.
      IF l_field_num = 1.
        l_string = l_big_char.
      ELSE.
        CONCATENATE l_string i_column_separator l_big_char INTO l_string.
      ENDIF.
    ENDDO.
    APPEND l_string TO et_csv.
  ENDLOOP.
ENDFORM.

2) SO_NEW_DOCUMENT_ATT_SEND_API1 is just a wrapper of SO_DOCUMENT_SEND_API1 (first one calls second one with some default values and all other parameters are passed as is)

0 Kudos

Hello Sandra,

Thanks for the code, but i'm supposed to schedule the report as a background job and the output should be mailed to the recepients.

Thanks.

Ushma

0 Kudos

Hi,

Just create a job in sm36. Associate your report to the job name with start date and end date and also the time you want to execute.

Regards,

Dhasarathy.

0 Kudos

With my code, you get easily the data in CSV format as you wanted. Now what do you need exactly? If you don't know how to send it as an attachment, please look at the threads, this question has been asked many many times.

0 Kudos

Hello Sandra,

Sorry for the time gap in between and thanks a lot for the code,it is very insightful.

Now i'm facing another problem, i have to work with internal atable and not standard database tables.

When i pass internal table to it_any ( ur code) and try to assign it to field-symbol , i'm not successful as it is deep strutucre.

( LOOP AT it_any ASSIGNING <ls_any> )

I'm not able to extract value of each component, it gives a short dump.

If there's a way out do suggest.

Thanks for your efforts.

Ushma.

0 Kudos

welcome back

you're right, it works only with a flat character structure. So, before calling this (my) routine, I suggest you to simply map the fields you want in the CSV, from your complex internal table into a flat character internal table. If you have some questions, please explain exactly with an example, what you have in your complex internal table and what you want to put in the CSV.

0 Kudos

Hello Sandra,

How r u doing.

I have all types of fields in my internal table.

Is there a way to handle such tables i was just wondering how r they doing while creating alv report.

I need to find some generic way.

Besides, i'm horizontal tab as separator and mailing it.

When i open my attachment in excel, 'FIle not in recoginzable format' error is reported.

Can u give me any help in this.

To give u some insight:

" following code is for inserting each field of internal table in content_bin.

This is part of code.

i'm bringing the value of each field of internal table in variable l_string.

DATA: wa_content_bin TYPE TABLE OF solisti1 WITH HEADER LINE.

DATA: strl1 TYPE i,

strl2 TYPE i.

strl1 = strlen( l_string ).

strl2 = strlen( wa_content_bin ).

strl1 = strl1 + strl2.

if strl1 < 253.

CONCATENATE wa_content_bin l_string INTO wa_content_bin SEPARATED BY c_tab.

else.

CONCATENATE wa_content_bin c_tab INTO wa_content_bin.

APPEND wa_content_bin to content_bin.

clear wa_content_bin.

clear content_bin.

wa_content_bin = l_string.

ENDIF.

" packing list

DESCRIBE TABLE content_bin LINES excel_lines.

PACK_LIST-TRANSF_BIN = 'X'.

PACK_LIST-HEAD_START = 1.

PACK_LIST-HEAD_NUM = 1.

PACK_LIST-BODY_START = 1.

PACK_LIST-BODY_NUM = EXCEL_LINES.

PACK_LIST-DOC_TYPE = 'XLS'.

PACK_LIST-OBJ_NAME = 'abcXLS'.

PACK_LIST-obj_descr = 'ABC XLS'.

PACK_LIST-DOC_SIZE = EXCEL_LINES * 255.

APPEND PACK_LIST.

CLEAR PACK_LIST.

I have used function 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

I sincerely thank you for all your support till date, i have reached somewhere in this issue.

Warm regards and thanks.

Ushma.

0 Kudos

could you open your file with notepad, and paste here the 1000 first characters?

0 Kudos

HI!!,

Here it is.

D i v i s i o n S a l e s G r p . S a l e s O f f i c e C u s t o m e r N o . P a r t y " s N a m e C r e a t i o n D a t e E n q u i r y N o . E n q u i r y D a t e Q u o t a t i o n N o . Q u o t a t i o n D a t e M a t e r i a l N o . I n q u i r y M / C M o d e l Q t y . Q u o . M / C M o d e l Q u o . Q t y P r i c e Q u o . V a l . S t r e e t S t r e e t 1 S t r e e t 2 S t r e e t 3 C i t y P i n P h o n e F a x E - m a i l C o n t a c t P e r s o n M o b i l e N o C o n t a c t i n t e x t E n q u i r y S t a t u s S a l e s D i s t r i c t R e a s o n f o r R e j e c t i o n P . O . N o . I n q . P . O . N o . Q u o t a t i o n

P r o j e c t s S a w i n g M a c h i n e s I n d o r e 1 7 3 I s p a t I n d u s t r i e s 0 4 . 0 4 . 2 0 0 8 1 0 0 0 0 4 9 6 0 4 . 0 4 . 2 0 0 8 0 0 . 0 0 . 0 0 0 0 6 0 0 0 0 0 3 2 I T L - P r o j e c t 1 . 0 0 0 0 . 0 0 0 0 . 0 0 A A A A A A A A A A A A A A A A A A A A A A A A A A B B B B B B B B B B B B B B B B B B B B B B B B B B B B B C C C C C C C C C C C C C C C C C C C C C C C C C C C C C D D D D D D D D D D D D D D D D D D D D D D D D D D M u m b a i 1 1 0 0 0 0 0 7 3 1 - 2 5 2 9 2 6 2 8 8 6 4 2 3 5 5 3 3 8 7 C h a n d u _ l a l @ i t l . c o . i n V i s h a l S h a r m a 9 4 1 2 3 5 3 6 7 1 O P E N W E S T 1 2 3 1 4

P r o j e c t s S a w i n g M a c h i n e s I n d o r e 1 7 3 I s p a t I n d u s t r i e s 0 5 . 0 4 . 2 0 0 8 1 0 0 0 0 4 9 8 0 5 . 0 4 . 2 0 0 8 0 0 . 0 0 . 0 0 0 0 6 0 0 0 0 0 3 2 I T L - P r o j e c t 1 . 0 0 0 0 . 0 0 0 0 . 0 0 A A A A A A A A A A A A A A A A A A A A A A A A A A B B B B B B B B B B B B B B B B B B B B B B B B B B B B B C C C C C C C C C C C C C C C C C C C C C C C C C C C C C D D D D D D D D D D D D D D D D D D D D D D D D D D M u m b a i 1 1 0 0 0 0 0 7 3 1 - 2 5 2 9 2 6 2 8 8 6 4 2 3 5 5 3 3 8 7 C h a n d u _ l a l @ i t l . c o . i n V i s h a l S h a r m a 9 4 1 2 3 5 3 6 7 1 O P E N W E S T 1 2 3 4 1

P r o j e c

0 Kudos

Hi!!,

Is ,this what you needed?

Sorry, if i have disappointed you.

Thanks.

Ushma

0 Kudos

Sorry, I didn't see your answer, thank you

Your file seems to be unicode, but the first 2 bytes must indicate the encoding (below in hexadecimal), maybe it is the problem (I made a test, Excel makes an error if you don't provide these 2 bytes):


FEFF    UTF-16, big-endian       cl_abap_char_utilities=>BYTE_ORDER_MARK_BIG 
FFFE    UTF-16, little-endian    cl_abap_char_utilities=>BYTE_ORDER_MARK_LITTLE 

Note: I don't see the tabs in your answer, it's normal, I assume they are present of course.

0 Kudos

HI!!,

Thanks, but where shall i put this code.

Am i supposed to put it in beginning of content bin table.

eg:

DATA: c_big TYPE c VALUE cl_abap_char_utilities=>BYTE_ORDER_MARK_BIG,

c_little TYPE c VALUE cl_abap_char_utilities=>BYTE_ORDER_MARK_LITTLE.

CONCATENATE C_BIG C_LITTLE FIELDCATLOG-seltext_m INTO WA_CONTENT_BIN SEPARATED BY SPACE.

  • wa_content_bin is work area for table content_bin.

But this is not helping.

PS: can there may be version problem as well.

Thanks.

Ushma.

0 Kudos

you didn't understand, have a look at wikipedia what endianness means, you must choose the one that fits your server endianness. See cl_abap_char_utilities=>endian (B or L). Use the right code according to the system endianness (either C_BIG or C_LITTLE)

0 Kudos

Hello Sandra,

I have some idea about endianness, but was'nt aware that it was causing the problem.

I checked with basis people, they said we are using little endian.

But where to put the code.

I have declared the variable c_little as type c, having value cl_abap_char_utilities=>BYTE_ORDER_MARK_LITTLE.

I tried putting it as first byte of my excel file.

CONCATENATE c_little FIELDCATLOG-seltext_m INTO wa_content_bin SEPARATED BY space.

  • fieldcatlog-seltext_m has value for my 1st col. heading.

Still it is not working.

Thanks and Regards.

Ushma

0 Kudos

it can't work as you do. The mark is X type (2 bytes of hex value FFFE). If you move it to a C variable of 1 character, this variable will have value 'F' ! You must do something like that:


DATA : BEGIN OF struc,
  x2 type x length 2,
  c1 TYPE c LENGTH 20,
  end of struc.
struc-x2 = Cl_abap_char_utilities=>BYTE_ORDER_MARK_LITTLE.
struc-c1 = 'A'.

0 Kudos

Hi Sandra,

I'm not sure about the site rules, but i really appreciate your prompt response.

I surely have a long way to go, to reach your level.

Coming to my issue:

The second Field , in which u store 'A' , is meant for what?

Did u meant i can put the data( excel file content) in it?

If yes, then how do i send it as attachment,

if not, how do i club, the two data types in one?

Thanks.

Ushma

0 Kudos

Hi Ushma,

If you want to send spool as an attchment

then while your are creating a job in SM36 you click on Spool Reciepent List add the names to whom it needs to be sent.

Thanks

Aravind

0 Kudos

Hi Ushma,

If you want to send spool as an attchment

then while your are creating a job in SM36 you click on Spool Reciepent List add the names to whom it needs to be sent.

Thanks

Aravind

0 Kudos

My code cannot be used directly as given. Another way :


data l_xstring type xstring.
data l_BYTE_ORDER_MARK type string.
l_xstring = Cl_abap_char_utilities=>BYTE_ORDER_MARK_LITTLE.
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
  EXPORTING
    im_xstring        = l_xstring
   IM_ENCODING       = 'DEFAULT'
 IMPORTING
   EX_STRING         = L_BYTE_ORDER_MARK.

CONCATENATE l_BYTE_ORDER_MARK TEXT into TEXT.

0 Kudos

HI!!,

On putting the above code, i'm getting an error message:

' Error occured during character conversion.

Thanks.

0 Kudos

sorry, it's probably because you have a unicode system and I only tested it on an ascii system.

Let be more direct. Please could you generate a file with hexa values FFFE4100 (little endian : letter A), and open it with excel to be sure it works.


DATA l_filename TYPE string VALUE 'c:\zzz.csv'.
DATA l_xstring  TYPE xstring.
l_xstring = 'FFFE4100'.
PERFORM write_bin_file USING l_filename l_xstring.
FORM write_bin_file
      USING
        i_filename      TYPE string
        i_file_xstring  TYPE xstring.

  TYPES xx(50) TYPE x.
  DATA lt_xstring TYPE TABLE OF xx.
  DATA l_length TYPE i.

  CALL METHOD cl_swf_utl_convert_xstring=>xstring_to_table
    EXPORTING
      i_stream = i_file_xstring
    IMPORTING
      e_table  = lt_xstring
    EXCEPTIONS
      OTHERS   = 3.

  l_length = XSTRLEN( i_file_xstring ).

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize = l_length
      filename     = i_filename
      filetype     = 'BIN'
    CHANGING
      data_tab     = lt_xstring
    EXCEPTIONS
      OTHERS       = 3.

ENDFORM.                    "write_bin_file

0 Kudos

Hey ,

It works perfectly fine.

now what to do next.

0 Kudos

Good Now I'm a little stuck to concatenate an X field (the byte order mark) and the string of characters. Could you ask a new question in the forum so that to get help from other people (we're a little abandoned here!) ;-). Thx

0 Kudos

Hi!!,

Yes sure , i can ask another question, as to how to put encoding bytes in my attachment.

Btw, are u a certified abaper :).

Thanks a lot , for all the help , and looking forward for many more ;).

Best Wishes and regards.

Ushma.

ps: i hope u were aware, that i was not using csv file format.

working with c_tab( horizontal tab) and creating my output.

Edited by: Ushma Jain on Aug 25, 2009 1:06 PM

0 Kudos

you know, "c"sv (comma) or "t"sv (tab), it's rather the same

A last thing for adding the byte order mark, before asking the question : in your code, just before attaching the "csv" file to the mail, you may convert the file from text to bytes, then add the byte order mark :

0 Kudos

HI!!! Sandra,

Thanks a lot for all your help. I appreciate it a lot and looking for more help

As per your suggestion i was searching on net and found a link , which solved my problem.

the link is

http://thilanka.owain.org/2008/12/to-send-email-with-attachment-abap.html

It has complete program.

Thanks.

Ushma

0 Kudos

Hi Ushma,

thank you for using CL_BCS, [searching before posting|https://forums.sdn.sap.com/search.jspa?objID=f50&q=mail%2Coutputofspoolasanexcelattachment+++] and closing the thread.

Regards,

Clemens