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: 

Reg OTR text display in Email as HTML

Former Member
0 Kudos

Is there any function module is there to display the Text in email.

1 REPLY 1

nabheetscn
Active Contributor
0 Kudos

You can use the concept of class and all to display text.. or use fm SO_SEND*AP11

For class refer the below code.

DATA: send_request TYPE REF TO cl_bcs.

DATA: text TYPE bcsy_text.

DATA: binary_content TYPE solix_tab.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: bcs_exception TYPE REF TO cx_bcs.

DATA: sent_to_all TYPE os_boolean.

DATA:lv_fax TYPE ad_fxnmbr,

lv_filename_cl TYPE sood-objdes.

  • Convert the OTF file format ino the PDF format.

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = lwa_bin_filesize

TABLES

otf = lt_otf

doctab_archive = lt_doctab_archive

lines = lt_pdf_lines

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

  • get the pdf data into the attachment table .

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_dst = 255

TABLES

content_in = lt_pdf_lines

content_out = lt_objbin

EXCEPTIONS

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

OTHERS = 4.

  • Refresh the local tables and workareas.

REFRESH: lt_reclist,

lt_objtxt,

lt_objpack.

TRY.

  • -------- create persistent send request ------------------------

send_request = cl_bcs=>create_persistent( ).

  • -------- create and set document with attachment ---------------

  • create document from internal table with text

APPEND 'test1' TO text.

APPEND 'test2.' TO text.

APPEND 'test3' TO text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = text

i_length = '12'

i_subject = 'Electronic Payment Notification' ).

FIELD-SYMBOLS <fs_x> TYPE x.

DATA lv_content TYPE xstring.

LOOP AT lt_objbin INTO lwa_objbin.

ASSIGN lwa_objbin TO <fs_x> CASTING.

CONCATENATE lv_content <fs_x> INTO lv_content IN BYTE MODE.

ENDLOOP.

pdf_content = cl_document_bcs=>xstring_to_solix(

ip_xstring = lv_content ).

  • add attachment to document

  • BCS expects document content here e.g. from document upload

  • binary_content = ...

CONCATENATE 'test_' sy-datum sy-uzeit '.pdf' INTO lv_filename_cl.

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = lv_filename_cl

i_att_content_hex = pdf_content.

  • add document to send request

CALL METHOD send_request->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.

CALL METHOD send_request->set_status_attributes(

EXPORTING

i_requested_status = 'N'

i_status_mail = 'N' ).

  • Fill the receiver for the email with PDF attachemnt.

CLEAR : lwa_reclist,

lwa_lfa1,

lwa_adr6.

READ TABLE lt_lfa1

INTO lwa_lfa1

WITH KEY lifnr = lwa_reguh-lifnr.

IF sy-subrc EQ 0.

READ TABLE lt_adr6

INTO lwa_adr6

WITH KEY addrnumber = lwa_lfa1-adrnr.

IF ( sy-subrc EQ 0 )

AND ( lwa_adr6-smtp_addr IS NOT INITIAL ).

  • --------- add recipient (e-mail address) -----------------------

  • create recipient - please replace e-mail address !!!

recipient = cl_cam_address_bcs=>create_internet_address(

lwa_adr6-smtp_addr ).

ELSE.

lv_fax = lwa_lfa1-telfx.

recipient = cl_cam_address_bcs=>create_fax_address(

i_country = lwa_lfa1-land1

i_number = lv_fax ).

ENDIF.

ENDIF.

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

  • ---------- send document ---------------------------------------

CALL METHOD send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = sent_to_all ).

IF sent_to_all = 'X'.

WRITE text-003.

ENDIF.

COMMIT WORK.

CATCH cx_bcs INTO bcs_exception.

WRITE: 'Error Occured'.

WRITE: 'Error', bcs_exception->error_type.

EXIT.

ENDTRY.

endif.

Thanks

Nabheet