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: 

RE: Mail sent to SAP inbox-Urgent.

Former Member
0 Kudos

Hi,

I sent mail with attachment( internal table contents) to SAP inbox using the below codw.

DATA: l_text TYPE char255. " Text

*DATA: l_text(280) TYPE c. " Text

DATA: l_lines TYPE i,

l_size TYPE sood-objlen. " Size of Attachment

  • Mail related

DATA: i_content TYPE soli_tab, " Mail content

i_attach TYPE soli_tab. " Attachment

DATA: l_send_request TYPE REF TO cl_bcs, " E-Mail Send Request

l_document TYPE REF TO cl_document_bcs, " E-Mail Attachment

l_recipient TYPE REF TO if_recipient_bcs, " Distribution List

l_sender TYPE REF TO if_sender_bcs, " Address of Sender

l_uname TYPE salrtdrcpt, " Sender Name(SY-UNAME)

l_bcs_exception TYPE REF TO cx_document_bcs, " BCS Exception

l_addr_exception TYPE REF TO cx_address_bcs, " Address Exception

l_send_exception TYPE REF TO cx_send_req_bcs. " E-Mail sending Exception

DATA: l_recipient_soos TYPE soos1.

****************************************************************************

*data : p_uname TYPE ad_smtpadr .

FORM send_to_sap_mail .

  • Preparing body of the Mail

MOVE 'Pending Delivery Documents List' TO l_text.

APPEND l_text TO i_content.

  • Preparing contents of attachment with Change Log

PERFORM prepare_attachment.

  • Creates persistent send request

TRY.

l_send_request = cl_bcs=>create_persistent( ).

  • Creating Document

l_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = i_content[]

i_subject = 'Pending Delivery Documents' ).

  • DESCRIBE TABLE i_mara LINES l_lines.

DESCRIBE TABLE it_output LINES l_lines.

  • Size to multiplied by 2 for UNICODE enabled systems

l_size = l_lines * 2 * 255.

  • Adding Attachment

CALL METHOD l_document->add_attachment

EXPORTING

i_attachment_type = c_ext

i_attachment_size = l_size

i_attachment_subject = 'Pending Delivery Documents'

i_att_content_text = i_attach[].

  • Add document to send request

CALL METHOD l_send_request->set_document( l_document ).

  • Get Sender Object

l_uname = sy-uname.

l_sender = cl_sapuser_bcs=>create( l_uname ).

CALL METHOD l_send_request->set_sender

EXPORTING

i_sender = l_sender.

  • E-Mail

TRANSLATE p_uname TO UPPER CASE.

l_recipient_soos-recesc = 'B'.

l_recipient_soos-recnam = p_uname.

  • Preparing recepient from SAP Logon Name

CALL METHOD cl_send_request_bcs=>create_recipient_from_soos1

EXPORTING

i_soos1 = l_recipient_soos

RECEIVING

result = l_recipient.

  • Add Recipient

CALL METHOD l_send_request->add_recipient

EXPORTING

i_recipient = l_recipient

i_express = 'U'

i_copy = ' '

i_blind_copy = ' '

i_no_forward = ' '.

*Trigger E-Mail immediately

l_send_request->set_send_immediately( 'X' ).

CALL METHOD l_send_request->send( ).

COMMIT WORK.

CATCH cx_document_bcs INTO l_bcs_exception.

CATCH cx_send_req_bcs INTO l_send_exception.

CATCH cx_address_bcs INTO l_addr_exception.

ENDTRY.

Refresh it_output.

clear l_text.

clear I_content.

refresh I_attach.

ENDFORM. " Send_to_sap_mail

&----


*& Form prepare_attachment

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM prepare_attachment .

FIELD-SYMBOLS: <lfs_table>, " Internal table structure

<lfs_con>. " Field Content

  • DATA: l_text TYPE char1024. " Text content for mail attachment

DATA: l_text(1280) TYPE c. " Text content for mail attachment

DATA: l_con(50) TYPE c. " Field Content in character format

  • Columns to be tab delimeted

LOOP AT it_output ASSIGNING <lfs_table>.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>

TO <lfs_con>.

IF sy-subrc NE 0.

CONCATENATE c_cr l_text INTO l_text.

APPEND l_text TO i_attach.

EXIT.

ELSE.

CLEAR: l_con.

MOVE <lfs_con> TO l_con.

CONDENSE l_con.

IF sy-index = 1.

CLEAR: l_text.

MOVE l_con TO l_text.

ELSE.

CONCATENATE l_text l_con INTO l_text

SEPARATED BY c_tab.

ENDIF.

ENDIF.

ENDDO.

ENDLOOP.

ENDFORM. " prepare_attachment

Here my problem is in my internal table i have 30 columns and the row output length is more than 255 char,

and the SOLI structure fields defined as CHAR255, thats why when i am opening the sap mail attachment in Excel sheet, last three fields data is not displaying can any one please let me know the answer.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

loop at output_table.

concatenate g_string

filed1

filed2

. ...

. ...

. ...

CL_ABAP_CHAR_UTILITIES=>CR_LF

into g_string separted by

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

endloop.

now pass the filled string to

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

text = g_string

  • IMPORTING

  • LENGTH = LENGTH

TABLES

ftext_tab = obj_bin.

pass this objbin to SO_NEW_DOCUMENT_ATT_SEND_API1

now you will get the desired excel sheet.

NOte: dont put urgent in your subject.it is arule that people should not ans question which have urgent.

Edited by: S.r.v.r.Kumar on Jun 18, 2008 10:25 PM

2 REPLIES 2

Former Member
0 Kudos

loop at output_table.

concatenate g_string

filed1

filed2

. ...

. ...

. ...

CL_ABAP_CHAR_UTILITIES=>CR_LF

into g_string separted by

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

endloop.

now pass the filled string to

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

text = g_string

  • IMPORTING

  • LENGTH = LENGTH

TABLES

ftext_tab = obj_bin.

pass this objbin to SO_NEW_DOCUMENT_ATT_SEND_API1

now you will get the desired excel sheet.

NOte: dont put urgent in your subject.it is arule that people should not ans question which have urgent.

Edited by: S.r.v.r.Kumar on Jun 18, 2008 10:25 PM

Former Member
0 Kudos

Thank you.