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: 

sending the data of internal table as .txt attachment file through e- mail

Former Member
0 Kudos

hi experts,

can u help me how to pass the internal table data into .txt file and send it as attachment through email in good format.

7 REPLIES 7

former_member342104
Participant
0 Kudos

DATA: LT_TEXT LIKE ZSVFILE OCCURS 0 WITH HEADER LINE.

DATA: BINARY_CONTENT TYPE SOLIX_TAB.

DATA: XL_CONTENT TYPE XSTRING.

DATA: OUTPUT TYPE STRING.

DATA : V_RECIPIENT LIKE ADR6-SMTP_ADDR.

DATA : WTABIX LIKE SY-TABIX.

WTABIX = SY-TABIX.

FREE: SEND_REQUEST,

DOCUMENT ,

SENDER ,

RECIPIENT ,

BCS_EXCEPTION.

CONCATENATE' '

SY-DATUM+6(2) '.'

SY-DATUM+4(2) '.'

SY-DATUM+0(4) INTO HEADERTXT.

WSUBJECT = HEADERTXT.

TRY.

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

SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

APPEND 'Dear Sir/Madam,' TO WTEXT1.

APPEND ' ' TO WTEXT1.

CONCATENATE ''

' INTO WTEXT SEPARATED BY SPACE.

APPEND WTEXT TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' '

TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND '.' TO WTEXT1.

APPEND ' ' TO WTEXT1.

DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

I_TYPE = 'RAW'

I_TEXT = WTEXT1

  • I_LENGTH = '12'

I_SUBJECT = HEADERTXT ).

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

TABLES

I_TAB_SAP_DATA = inernaltbale

I_TAB_CONVERTED_DATA = LT_TEXT

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

endif.

REFRESH WTEXT1.

LOOP AT LT_TEXT .

WTEXT_3 = LT_TEXT.

APPEND WTEXT_3 TO WTEXT3.

CLEAR WTEXT_3.

ENDLOOP.

LOOP AT GT_FIELDCAT INTO LS_FIELDCAT.

IF SY-TABIX = 1.

WTEXT_3 = LS_FIELDCAT-SELTEXT_L.

ELSE.

CONCATENATE WTEXT_3

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

LS_FIELDCAT-SELTEXT_L

INTO WTEXT_3.

ENDIF.

ENDLOOP.

INSERT WTEXT_3 INTO WTEXT3 INDEX 1.

CLEAR: XL_CONTENT.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

IMPORTING

BUFFER = XL_CONTENT

TABLES

TEXT_TAB = WTEXT3

EXCEPTIONS

FAILED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

ENDIF.

REFRESH BINARY_CONTENT .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = XL_CONTENT

TABLES

BINARY_TAB = BINARY_CONTENT.

CALL METHOD DOCUMENT->ADD_ATTACHMENT

EXPORTING

I_ATTACHMENT_TYPE = 'TXT'

I_ATTACHMENT_SUBJECT = WSUBJECT

I_ATT_CONTENT_HEX = BINARY_CONTENT.

CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).

SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ).

CALL METHOD SEND_REQUEST->SET_SENDER

EXPORTING

I_SENDER = SENDER.

PERFORM DETERMINE_MAIL_RECEPIENTS.

CALL METHOD SEND_REQUEST->SEND(

EXPORTING

I_WITH_ERROR_SCREEN = 'X'

RECEIVING

RESULT = SENT_TO_ALL ).

COMMIT WORK.

CATCH CX_BCS INTO BCS_EXCEPTION.

WRITE: 'Error in Sending Mail'.

WRITE: 'Error Type:'(002), BCS_EXCEPTION->ERROR_TYPE.

EXIT.

ENDTRY.

Edited by: kk on Oct 23, 2008 1:34 PM

former_member671224
Participant
0 Kudos

Use the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send attachment as mail.

Regards,

Amal

former_member342104
Participant
0 Kudos

also add this code

DATA : V_RECIPIENT LIKE ADR6-SMTP_ADDR.

DATA : WTABIX LIKE SY-TABIX.

WTABIX = SY-TABIX.

LOOP AT email_input.

WTABIX = SY-TABIX.

V_RECIPIENT = email_input.

RECIPIENT =

CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( V_RECIPIENT ).

CALL METHOD SEND_REQUEST->ADD_RECIPIENT

EXPORTING

I_RECIPIENT = RECIPIENT

I_EXPRESS = 'X'.

ENDLOOP.

0 Kudos

thanxs kk for ur reply,

but could understand u ,give me a clear code, i could not get what is the data type of wtext3 and some of other variable. Please give a clear code please.

0 Kudos

HI EXPERTs,

i am using SO_DOCUMENT_SEND_API1 to send the mail, please tell me how should i proceed to send mail with text file data attachment

Former Member
0 Kudos

thank u experts