0% found this document useful (0 votes)
256 views6 pages

Need Help Sending Email Attachment in CSV Format U... - SAP Community

Uploaded by

heavy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views6 pages

Need Help Sending Email Attachment in CSV Format U... - SAP Community

Uploaded by

heavy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

28/4/24, 16:34 Need help sending email attachment in CSV format u...

- SAP Community

Need help sending email attachment in CSV format using method

SFactor
Explorer

‎07-19-2008 3:00 PM

Pr
0 Kudos

Hi, I need to send an email with an attachment in CSV format.

I have a comma delimited file (290 characters). I am using a method ( cl_hrrcf_services_mail-


>send_web_mail), but when I send the mail the attachment is empty.

I know a lot of developers use function module

'SO_NEW_DOCUMENT_ATT_SEND_API1'.

Has anybody use method method cl_hrrcf_services_mail to do this? Any ideas on how I can do this will be
appreciated.

Thanks

Margariet

SAP Managed Tags:


ABAP Development

Reply 3 REPLIES

Former Member

‎07-19-2008 3:16 PM

0 Kudos

Hi,

Check this sample code: It calls a smartforms, generates a PDF and sends as attachment to external mailbox.

REPORT ytest_email.

* This example shows how to send


* - a simple text provided in an internal table of text lines
* - to some internet email address.
*
* All activities done via facade CL_BCS!

INCLUDE rlb_invoice_data_declare.

DATA: send_request TYPE REF TO cl_bcs.


DATA: text TYPE bcsy_text.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO cl_sapuser_bcs.

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 1/6
28/4/24, 16:34 Need help sending email attachment in CSV format u... - SAP Community
DATA:
DATA : recipient TYPE REF TO if_recipient_bcs
if_recipient_bcs..
DATA:
DATA : bcs_exception TYPE REF TO cx_bcs
cx_bcs..
DATA:
DATA : sent_to_all TYPE os_boolean.
os_boolean.

START-OF-SELECTION.
START-OF-SELECTION .

main.
PERFORM main .

*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
main.
FORM main .

DATA:
DATA : ls_bil_invoice TYPE lbbil_invoice.
lbbil_invoice.
DATA:
DATA : lf_fm_name rs38l_fnam.
TYPE rs38l_fnam .
DATA:
DATA : ls_control_param ssfctrlop.
TYPE ssfctrlop .
DATA:
DATA : ls_composer_param TYPE ssfcompop.
ssfcompop.
DATA:
DATA : ls_recipient swotobjid.
TYPE swotobjid .
DATA:
DATA: ls_sender TYPE swotobjid.
swotobjid.
DATA:
DATA: lf_formname tdsfname.
TYPE tdsfname .
DATA:
DATA : ls_addr_key addr_key.
LIKE addr_key .
DATA:
DATA : ls_dlv
ls_dlv--land vbrk-
LIKE vbrk -land1
land1. .
DATA:
DATA : ls_job_info ssfcrescl.
TYPE ssfcrescl .

DATA:
DATA : I_CUST TYPE SCUSTOM
SCUSTOM.
.
DATA:
DATA: I_BOOK TYPE TY_BOOKINGS,
TY_BOOKINGS,
TY_CONNECTIONS.
I_CONN TYPE TY_CONNECTIONS .

DATA:
DATA : W_I_SIZE TYPE I,
I_DOCS TYPE TABLE OF DOCS,
DOCS,
I_LINES TYPE TABLE OF TLINE.
TLINE.

DATA:
DATA: I_OTF TYPE TSFOTF.
TSFOTF.

DATA:
DATA : I_BIN TYPE SOLIX_TAB
SOLIX_TAB..

data:
data : gd_buffer type string
string,,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE
LINE,,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.
LINE.
.

DATA:
DATA : WA_LINES LIKE LINE OF I_LINES
I_LINES,,
I_BIN.
WA_PDF LIKE LINE OF I_BIN .

DATA:
DATA : PDF_CONTENT TYPE SOLIX_TAB.
SOLIX_TAB.
DATA:
DATA : LP_PDF_SIZE TYPE SO_OBJ_LEN.
SO_OBJ_LEN.

data:
data : w_xstr xstring,
type xstring ,
w_len type i.

TRY.
TRY .

* SF_EXAMPLE_01

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'


EXPORTING formname = 'SF_EXAMPLE_01'
* variant = ' '
* direct_call = ' '
IMPORTING fm_name = lf_fm_name
EXCEPTIONS no_form = 1
no_function_module = 2
OTHERS = 3.
sy-
IF sy -subrc <> 0.
* error handling

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 2/6
28/4/24, 16:34 Need help sending email attachment in CSV format u... - SAP Community
ENDIF.

ls_control_param-getotf = 'X'.
ls_control_param-NO_DIALOG = 'X'.

* call smartform invoice


CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
* mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = space
CUSTOMER = I_CUST
BOOKINGS = I_BOOK
CONNECTIONS = I_CONN
is_repeat = repeat
importing job_output_info = ls_job_info
* document_output_info =
* job_output_options =
EXCEPTIONS formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc = 0.

I_OTF = LS_JOB_INFO-OTFDATA[].

endif.

CALL FUNCTION 'CONVERT_OTF_2_PDF'


* EXPORTING
* USE_OTF_MC_CMD = 'X'
* ARCHIVE_INDEX =
IMPORTING
BIN_FILESIZE = w_i_size
TABLES
OTF = I_OTF
DOCTAB_ARCHIVE = I_docs
LINES = I_LINES
* EXCEPTIONS
* ERR_CONV_NOT_POSSIBLE = 1
* ERR_OTF_MC_NOENDMARKER = 2
* OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* Transfer the 132-long strings to 255-long strings


LOOP AT i_lines into wa_lines.
TRANSLATE wa_lines USING '~'.
CONCATENATE gd_buffer wa_lines INTO gd_buffer.
ENDLOOP.

TRANSLATE gd_buffer USING '~'.

DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 3/6
28/4/24, 16:34 Need help sending email attachment in CSV format u... - SAP Community
EXIT.
EXIT .
ENDIF.
ENDIF .
ENDDO.
ENDDO .

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'


EXPORTING
INPUT_LENGTH = w_i_size
FIRST_LINE = 0
LAST_LINE = 0
IMPORTING
BUFFER = w_xstr
TABLES
BINARY_TAB = it_mess_att
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
SY-
IF SY -SUBRC <> 0.
SY-
MESSAGE ID SY -MSGID TYPE SY
SY-
-MSGTY NUMBER SY
SY--MSGNO
SY-
WITH SY -MSGV1 SY
SY-
-MSGV2 SY-
SY-MSGV3 SY-
SY-MSGV4
MSGV4.
.
ENDIF.
ENDIF.

CL_DOCUMENT_BCS=>
PDF_CONTENT = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX
XSTRING_TO_SOLIX(
( IP_XSTRING = w_xstr ).
* -------- create persistent send request ------------------------
cl_bcs=>
send_request = cl_bcs =>create_persistent
create_persistent(( ).

* -------- create and set document -------------------------------


* create document from internal table with text
* APPEND 'Hello world!' TO text.
document = cl_document_bcs=>
cl_document_bcs=>create_document
create_document(
(
i_type = 'RAW'
i_TEXT = TEXT
i_length = '21'
i_subject = 'FORM TEST' ).

**add attachment to document


CALL METHOD document->
document->add_attachment
add_attachment
EXPORTING i_attachment_type = 'PDF'
i_attachment_subject = 'MY ORDER CONFIRMATION'
* i_attachment_size = W_len
i_att_content_hex = pdf_content .

*
*
* add document to send request
send_request->
CALL METHOD send_request ->set_document
set_document(( document ).
*
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
*
* sender = cl_sapuser_bcs=>create( sy-uname ).
* CALL METHOD send_request->set_sender
* EXPORTING
* i_sender = sender.
*
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
cl_cam_address_bcs=>
recipient = cl_cam_address_bcs =>create_internet_address
create_internet_address((
'give email address here' ).
*
* add recipient with its respective attributes to send request
send_request->
CALL METHOD send_request ->add_recipient
add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
'X'.
*
*
cl_sapuser_bcs=>
recipient = cl_sapuser_bcs =>create
create(( sy
sy--uname ).

send_request->
CALL METHOD send_request ->add_recipient
add_recipient
EXPORTING

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 4/6
28/4/24, 16:34 Need help sending email attachment in CSV format u... - SAP Community
i_recipient = recipient
i_express = 'X'.
'X'.
*
*
*
* ---------- send document ---------------------------------------
send_request->
CALL METHOD send_request ->send
send((
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
'X'.
IF sent_to_all = 'X' .
text-003
WRITE text- 003.
.
ENDIF.
ENDIF.

WORK.
COMMIT WORK .

* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
bcs_exception.
CATCH cx_bcs INTO bcs_exception .
WRITE:
WRITE : text-
text-001
001.
.
WRITE:
WRITE : text-
text-002
002,
, bcs_exception
bcs_exception->
->error_type
error_type..
EXIT.
EXIT .

ENDTRY.
ENDTRY .

ENDFORM.
ENDFORM . "main

SAP Managed Tags:


ABAP Development

Reply

SFactor
Explorer

‎07-25-2008 11:11 AM

0 Kudos

Hi

When I open the attachment all my data is in one line and the format is not correct.

My internal table is comma delimited and 290 characters.

Can somebody please help? I am using function module FUNCTION 'SO_DOCUMENT_SEND_API1' to send
the mail to a Notes email address.

Thanks

Margariet
SAP Managed Tags:
ABAP Development

Reply

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 5/6
28/4/24, 16:34 Need help sending email attachment in CSV format u... - SAP Community
Former Member

In response to SFactor
‎07-25-2008 11:18 AM

0 Kudos

You must use FM as below

SO_NEW_DOCUMENT_ATT_SEND_API1.

Using se37 go into function module. Read its Documenation. You will find your solution.

regards

rajesh
SAP Managed Tags:
ABAP Development

Reply

Privacy Terms of Use Copyright Legal Disclosure Trademark Newsletter Support


Cookie

https://community.sap.com/t5/application-development-discussions/need-help-sending-email-attachment-in-csv-format-using-method/m-p/420951… 6/6

You might also like