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

csv attachment

Former Member
0 Likes
732

Hi,

I need to send csv attachment to external mail.

csv format which is opened with excel worksheet. what all scenarios i need to take care?

TYPE should be RAW or WIN?

3 REPLIES 3
Read only

Former Member
0 Likes
551

Nihi,

I need a create a excel file (or tab delimited file) and send it as attachment by mail to the user (in background processing). I use SO_NEW_DOCUMENT_ATT_SEND_API1. I have a problem, that 1 Excel line is splited into 2 lines in mail, because there is more then 255 chars in Excel line.

Can anybody help me?

report y_cr17_mail .

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

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

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

Don't forget to reward if useful...

Read only

0 Likes
551

more than 255 char can be taken care of

just write like this...

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.

clear it_attach.

concatenate a b c d e f separated by con_tab into it_attach.

concatenate con_cret it_attach into it_attach.

append it_attach.

clear it_attach.

concatenate g h i j separated by con_tab into it_attach.

concatenate con_tab it_attach into it_attach.

append it_attach.

clear it_attach.

concatenate k l m n separated by con_tab into it_attach.

concatenate con_tab it_attach into it_attach.

append it_attach.

Read only

Former Member
0 Likes
551

Hi,

Use CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

REPORT ZTEST_EMAIL_SEND_ATTACH_PDF.

class CL_ABAP_CHAR_UTILITIES definition load.

constants:v_nl type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>newline,

v_ht type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>horizontal_TAB,

v_bs type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>CR_LF.

data: begin of i_records occurs 0,

data(30) type c,

reason(225) type c,

end of i_records.

DATA: v_dest LIKE tsp01-rqdest,

v_handle LIKE sy-tabix,

v_spool_id LIKE tsp01-rqident,

v_rc TYPE c,

v_errmessage(100) TYPE c,

v_text(200) TYPE c,

i_pdf type standard table of tline.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

START-OF-SELECTION.

i_records-data = '1002'.

i_records-reason = 'date is empty'.

append i_records.

clear i_records.

i_records-data = '1005'.

i_records-reason = 'time is empty'.

append i_records.

clear i_records.

loop at i_records.

concatenate i_records-data i_records-reason into objbin-line separated by ','.

concatenate v_nl objbin-line into objbin-line.

append objbin.

clear: i_records, objbin.

endloop.

perform f_mail_send.

&----


*& Form f_mail_send

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f_mail_send .

DATA: i_email TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_mess TYPE TABLE OF solisti1 WITH HEADER LINE,

w_subject TYPE so_obj_des,

  • w_name TYPE so_obj_nam.

w_name TYPE char30.

i_email-receiver = 'userid@domain.com'.

APPEND i_email.

i_mess-line = 'This is a test message. Customer Statements'.

APPEND i_mess.

w_name = 'Statements_345594_344455_conv'.

w_subject = 'Your Customer Statement for'.

PERFORM send_mail_out_raw TABLES i_email

i_mess

USING w_subject

w_name.

endform. " f_mail_send

&----


*& Form send_mail_out_raw

&----


  • text

----


  • -->PI_EMAIL text

  • -->PI_MESS text

  • -->PI_PDF text

  • -->PV_SUBJECT text

  • -->PV_NAME text

----


FORM send_mail_out_raw TABLES pi_email STRUCTURE somlreci1

pi_mess STRUCTURE solisti1 "Message

USING pv_subject TYPE so_obj_des

pv_name TYPE char30.

DATA :

li_receivers TYPE STANDARD TABLE OF somlreci1,

li_head TYPE STANDARD TABLE OF solisti1,

li_packing_list TYPE STANDARD TABLE OF sopcklsti1,

li_pdf TYPE STANDARD TABLE OF solisti1.

DATA : lst_doc_data TYPE sodocchgi1,

lw_lines TYPE i,

lw_name(34) TYPE c,

lw_subject TYPE sodocchgi1-obj_descr.

DATA : lst_pemail TYPE somlreci1,

lst_pmess TYPE solisti1,

lst_receivers TYPE somlreci1,

lst_head TYPE solisti1,

lst_packing_list TYPE sopcklsti1,

lst_mess TYPE solisti1.

lw_subject = pv_subject.

lw_name = pv_name.

CONCATENATE lw_name '.csv' INTO lw_name.

CONDENSE lw_name NO-GAPS.

  • Fill the email content

DESCRIBE TABLE pi_mess LINES lw_lines.

  • Populate the subject/generic message attributes

lst_doc_data-obj_langu = sy-langu.

lst_doc_data-obj_name = lw_name.

lst_doc_data-obj_descr = lw_subject.

READ TABLE pi_mess INTO lst_mess INDEX lw_lines.

lst_doc_data-doc_size = ( lw_lines - 1 ) * 255 +

STRLEN( lst_mess ).

  • Describe the body of the message

REFRESH li_packing_list.

lst_packing_list-transf_bin = space.

lst_packing_list-head_start = 1.

lst_packing_list-head_num = 0.

lst_packing_list-body_start = 1.

lst_packing_list-body_num = lw_lines.

lst_packing_list-doc_type = 'RAW'.

lst_packing_list-doc_size = ( lw_lines - 1 ) * 255 +

STRLEN( lst_mess ).

APPEND lst_packing_list TO li_packing_list.

CLEAR lst_packing_list.

  • Create attachment

CLEAR lw_lines.

DESCRIBE TABLE objbin LINES lw_lines.

lst_packing_list-transf_bin = 'X'.

lst_packing_list-head_start = 1.

lst_packing_list-head_num = 1.

lst_packing_list-body_start = 1.

lst_packing_list-body_num = lw_lines.

lst_packing_list-doc_type = 'CSV'.

lst_packing_list-obj_descr = lw_subject.

lst_packing_list-obj_name = lw_name.

lst_packing_list-doc_size = ( lw_lines ) * 255.

APPEND lst_packing_list TO li_packing_list.

  • Header

REFRESH li_head.

CLEAR lst_head. REFRESH li_head.

lst_head-line = lw_name. APPEND lst_head TO li_head.

  • Add the recipients email address

REFRESH li_receivers.

LOOP AT pi_email INTO lst_pemail.

lst_receivers-receiver = lst_pemail-receiver.

lst_receivers-rec_type = 'U'.

lst_receivers-com_type = 'INT'.

APPEND lst_receivers TO li_receivers.

CLEAR lst_receivers.

ENDLOOP.

*Send mail to external address

  • CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

  • EXPORTING

  • document_data = lst_doc_data

  • put_in_outbox = 'X'

  • commit_work = 'X'

  • TABLES

  • packing_list = li_packing_list

  • object_header = li_head

  • contents_bin = objbin

  • contents_txt = pi_mess

  • receivers = li_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.

<b>CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>

EXPORTING

document_data = lst_doc_data

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = li_packing_list

OBJECT_HEADER = li_head

CONTENTS_BIN = objbin

CONTENTS_TXT = pi_mess

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = li_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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. "Send_mail

Regards