2009 Sep 14 9:51 AM
Hi,
I have a requirement to update a ztable.
If the update statement fails then I need to populate all the messages into an internal table and use that internal table in the function module that is used to send the email with the error messages populated in the internal table.
How can I send the internal table populated with messages into the function module?
Hi,
I have a requirement to update a ztable.
If the update statement fails then I need to populate all the messages into an internal table and use that internal table in the function module that is used to send the email with the error messages populated in the internal table.
How can I send the internal table populated with messages into the function module?
2009 Sep 14 10:05 AM
Hi
Use the Function Module:
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
Regards,
Sreeram
2009 Sep 14 10:09 AM
Hi,
I have used the same function module.But when I pass the internal table containing the message data for the parameter CONTENTS_TXT it is giving a dump error.
2009 Sep 14 10:16 AM
Hi,
Check this blog
[FM|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417400)ID1252149750DB00943061504503853248End?blog=/pub/wlg/15570]
[BCS Interface|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417400)ID1252149750DB00943061504503853248End?blog=/pub/wlg/789]
Regards,
Amit
Edited by: Amit Iyer on Sep 14, 2009 2:46 PM
Edited by: Amit Iyer on Sep 14, 2009 3:05 PM
2009 Sep 14 10:12 AM
Hello,
You can use the method CREATE_DOCUMENT of the class CL_DOCUMENT_BCS to create the mail body and subject.
Use the method SET_DOCUMENT of class CL_BCS to add the document to send request.
Get the sender object by using the method CREATE of class CL_SAPUSER_BCS.
Add sender by using the SET_SENDER of class CL_BCS.
Create recipient by using the method CREATE INTERNET ADDRESS of class CL_CAM_ADDRESS_BCS
You can add recipient through method ADD_RECIPIENT of class CL_BCS.
Then send the documentl using method SEND of class CL_BCS.
Regards
Nilanjan
2009 Sep 14 10:12 AM
Hello,
You can use the method CREATE_DOCUMENT of the class CL_DOCUMENT_BCS to create the mail body and subject.
Use the method SET_DOCUMENT of class CL_BCS to add the document to send request.
Get the sender object by using the method CREATE of class CL_SAPUSER_BCS.
Add sender by using the SET_SENDER of class CL_BCS.
Create recipient by using the method CREATE INTERNET ADDRESS of class CL_CAM_ADDRESS_BCS
You can add recipient through method ADD_RECIPIENT of class CL_BCS.
Then send the document using method SEND of class CL_BCS.
Regards
Nilanjan
2009 Sep 14 10:15 AM
Hi
Use the below alternative then.
call function 'EFG_GEN_SEND_EMAIL'
exporting
i_title = 'KPI Report - Status'(046)
i_sender = g_sender
i_recipient = g_email
i_flg_commit = k_x
i_flg_send_immediately = k_x
tables
i_tab_lines = it_tab_soli
exceptions
not_qualified = 1
failed = 2
others = 3.
if sy-subrc <> 0.
write:/ sy-subrc.
endif.
Regards,
Sreeram
2009 Sep 14 10:32 AM
hi,
refer this example, hope it will solve your issue.
DATA:
W_SUBJECT LIKE SODOCCHGI1, u201CFOR SUBJECT
I_PACK_LIST LIKE SOPCKLSTI1 OCCURS 1 WITH HEADER LINE, u201CFOR PACKING LIST
I_OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE, u201CFOR OBJECT HEADER
I_CONTENTS_TEXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE, u201CFOR MAIL CONTENTS
I_CONTENTS_BIN TYPE STANDARD TABLE OF SOLISTI1 WITH HEADER LINE,
u201CFOR ATTACHMENT
I_CONTENTS_HEX TYPE STANDARD TABLE OF SOLIX WITH HEADER LINE,
u201CFOR ATTACHMENT
I_RECEIVER LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE, u201CFOR RECIPIENTS
CONTENT_OUT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
In my example I have created a subroutine SEND_MAIL in which the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1' is called for transferring the data in my internal table ITAB_INPUT as an excel file attachment, to an external email address.
FORM SEND_MAIL.
u201CSubroutine used for sending mail through the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
DATA: TAB_LINES TYPE I, u201CFor Number of lines
SENT_TO_ALL LIKE SONV-FLAG,
OBJ_DESC LIKE W_SUBJECT-OBJ_DESCR, u201CObject description
LV_HEX1(1) TYPE C, "Carriage return
LV_LINES TYPE I. u201CNumber of record lines in the internal table
DATA: BEGIN OF LI_CONTENTS_BIN OCCURS 10, u201CLocal Structure to pass attachment contents
LINE TYPE STRING, u201Cin STRING form
END OF LI_CONTENTS_BIN.
DATA: BEGIN OF LI_CONTENTS OCCURS 10, u201CLocal Structure to pass attachment contents
LINE TYPE XSTRING, u201Cin XSTRING form
END OF LI_CONTENTS.
DATA: LI_CONTENTS_HEX TYPE STANDARD TABLE OF SOLIX WITH HEADER LINE.
u201CFor attachment
LV_HEX1 = CL_ABAP_CHAR_UTILITIES=>CR_LF. u201CLine carriage return
CLEAR: W_SUBJECT,
SENT_TO_ALL,
I_PACK_LIST[],
I_OBJHEAD[],
I_CONTENTS_HEX[],
I_CONTENTS_TEXT[],
I_RECEIVER[].
DESCRIBE TABLE ITAB_INPUT LINES LV_LINES. u201CCount number of lines in the internal table
*ADD ONE LINE FOR THE COLUMN HEADER
LV_LINES = LV_LINES + 1.
*Subject of the mail.
OBJ_DESC = 'TESTING TO SEND MAIL THROUGH ABAP'.
W_SUBJECT-OBJ_NAME = 'TEST MAIL '.
W_SUBJECT-OBJ_DESCR = OBJ_DESC.
*Creating the Body of the mail message
I_CONTENTS_TEXT = SPACE.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
MOVE 'DEAR SIR/MADAM,' TO I_CONTENTS_TEXT.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
*Adding a line feed in the mail contents
I_CONTENTS_TEXT = SPACE.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
CONCATENATE
u2018THIS IS A TEST MAIL TO CHECK IF DATA FROM AN INTERNAL MAIL IS SENT TO AN EXTERNAL ADDRESS AS AN EXCELu2019 'FILE.' INTO I_CONTENTS_TEXT.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
I_CONTENTS_TEXT = SPACE.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
I_CONTENTS_TEXT = 'WARM REGARDS'.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
I_CONTENTS_TEXT = SPACE.
APPEND I_CONTENTS_TEXT.
CLEAR I_CONTENTS_TEXT.
*Creating the body of the attachment file of the mail
*Creating the column headers for the Status report
*the separation of # is used to divide the data into diff columns.
CONCATENATE 'USER NAME'
'TIME'
'SHORT TEXT'
'LONG TEXT'
u2018DATE'
'MESSAGE'
INTO LI_CONTENTS_BIN-LINE SEPARATED BY LC_TAB.
u201CLC_TAB is used to insert a # (HASH) delimiter
u201CBetween the columns
CONCATENATE LI_CONTENTS_BIN-LINE LV_HEX1 INTO LI_CONTENTS_BIN-LINE.
APPEND LI_CONTENTS_BIN.
CLEAR LI_CONTENTS_BIN.
*loop into internal table ITAB_INPUT and fill the table for attachment
LOOP AT ITAB_INPUT.
CONCATENATE
ITAB_INPUT-UNAME
ITAB_INPUT-TIME
ITAB_INPUT-SHORT_TEXT
ITAB_INPUT-LONG_TEXT
ITAB_INPUT-DAT
ITAB_INPUT-MESSAGE
INTO LI_CONTENTS_BIN-LINE SEPARATED BY LC_TAB.
*ADD THE CARRIAGE RETURN TO THE LAST RECORD.
IF LV_LINES GT SY-TABIX.
CONCATENATE LI_CONTENTS_BIN-LINE LV_HEX1 INTO LI_CONTENTS_BIN-LINE.
ENDIF.
APPEND LI_CONTENTS_BIN.
CLEAR LI_CONTENTS_BIN.
ENDLOOP.
TO COMPRESS THE CONTENTS u2013 THE CONVERSION APPLIED IS STRING TO XSTRING AND THEN XSTRING TO BINARY.BINARY DATA WAS PASSED INTO I_CONTENTS_HEX----
THIS CONVERSION WAS REQUIRED BECAUSE IN MY EXAMPLE I M USING THE CONTENTS_HEX PARAMETER TO PASS THE ATTACHMENT>
*Converting the table contents for attachment from STRING to XSTRING and then XSTRING to BINARY
*For this purpose the following function modules 'SCMS_STRING_TO_XSTRING' and 'SCMS_XSTRING_TO_BINARY' are used.
LOOP AT LI_CONTENTS_BIN.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LI_CONTENTS_BIN-LINE
MIMETYPE = ' u2018
ENCODING =
IMPORTING
BUFFER = LI_CONTENTS-LINE
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LI_CONTENTS-LINE
APPEND_TO_TABLE = 'I_CONTENTS_HEX'
IMPORTING
OUTPUT_LENGTH =
TABLES
BINARY_TAB = LI_CONTENTS_HEX
.
LOOP AT LI_CONTENTS_HEX.
APPEND LI_CONTENTS_HEX TO I_CONTENTS_HEX .
ENDLOOP.
ENDLOOP.
*Write Packing List (Body)
*Describe the body of the message -
the various fields of the Packing List have already been explained above
CLEAR I_PACK_LIST.
I_PACK_LIST-TRANSF_BIN = SPACE.
I_PACK_LIST-HEAD_START = 1.
I_PACK_LIST-HEAD_NUM = 0.
I_PACK_LIST-BODY_START = 1.
DESCRIBE TABLE I_CONTENTS_TEXT LINES I_PACK_LIST-BODY_NUM.
I_PACK_LIST-OBJ_DESCR = 'STATUS REPORT'.
I_PACK_LIST-DOC_TYPE = 'RAW'.
APPEND I_PACK_LIST.
CLEAR I_PACK_LIST.
*Describe the attributes of the attachment of the mail
DESCRIBE TABLE I_CONTENTS_HEX LINES TAB_LINES.
READ TABLE I_CONTENTS_HEX INDEX TAB_LINES.
W_SUBJECT-DOC_SIZE = TAB_LINES * 255 + STRLEN( I_CONTENTS_BIN ) .
I_PACK_LIST-TRANSF_BIN = 'X'.
I_PACK_LIST-HEAD_START = 1.
I_PACK_LIST-HEAD_NUM = 1.
I_PACK_LIST-BODY_START = 1.
I_PACK_LIST-BODY_NUM = TAB_LINES.
I_PACK_LIST-DOC_TYPE = 'XLS'.
I_PACK_LIST-OBJ_DESCR = 'STATUS REPORT'.
APPEND I_PACK_LIST.
CLEAR I_PACK_LIST.
*Create receiver list from selection parameter
*In my example, I have created a selection parameter for obtaining the recipientsu2019 address from the user. *The selection screen values for S_RCPNT is then passed onto to the parameter for the recipient.
LOOP AT S_RCPNT.
I_RECEIVER-RECEIVER = S_RCPNT-LOW.
I_RECEIVER-REC_TYPE = 'U'.
APPEND I_RECEIVER.
CLEAR I_RECEIVER.
ENDLOOP.
Function Module called for sending the mail to the intended recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_subject
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
NEW_OBJECT_ID =
TABLES
packing_list = i_pack_list
object_header = i_objhead
contents_hex = i_contents_hex
contents_txt = i_contents_text
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
receivers = i_receiver
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.
Thanks and Regards,
Ahamed.
2009 Sep 14 11:04 AM
2009 Sep 14 10:39 AM
HI,
see the fallowing link,
http://www.sapdb.info/abap-program-to-send-mail-with-attachment/
it will help you,
Regards,
Vijay
2009 Sep 14 11:02 AM
Hello,
You can use this sample code for your reference:
DATA: L_V_MAILID TYPE AD_SMTPADR, "Recepients
L_WA_OBJCONT TYPE SOLI, "to process mail contents
L_IT_OBJCONT TYPE STANDARD TABLE OF SOLI,
L_IT_RECLIST TYPE STANDARD TABLE OF SOOS1, "mail recepients
L_WA_RECLIST TYPE SOOS1,
L_WRK_OBJHEAD TYPE SOOD1,
L_V_COUNT1 TYPE SYDBCNT,
L_V_MESSAGE TYPE CHAR128.
CONSTANTS:
L_C_O TYPE SO_OBJ_SNS VALUE 'O', "Sensitivity
L_C_MAILSTATUS TYPE SO_MLSTAT VALUE 'E', "Mail status
L_C_RECESC TYPE SO_ESCAPE VALUE 'E', "Recepient type
L_C_SNDART TYPE TDDEVICE VALUE 'INT',"Output device
L_C_SNDPRI TYPE SO_SND_PRI VALUE '1', "Priority
L_C_1 TYPE INT1 VALUE 1, "for calculation
L_C_OBJTYP TYPE SO_OBJ_TP VALUE 'RAW'."Code for document
DATA: V_MSG TYPE SO_TEXT255.
MESSAGE E179(00) INTO V_MSG.
DO 10 TIMES.
L_WA_OBJCONT = V_MSG.
APPEND L_WA_OBJCONT TO L_IT_OBJCONT.
ENDDO.
* Set Message Header
L_WRK_OBJHEAD-OBJLA = SY-LANGU. "Language
L_WRK_OBJHEAD-OBJNAM = 'Error Log'."Name of document
* Set subject line of the mail
CONCATENATE 'Error Log' 'for Email' INTO L_WRK_OBJHEAD-OBJDES
SEPARATED BY SPACE.
* Recepient's mail id
L_V_MAILID = <required email id>.
L_WRK_OBJHEAD-OBJLEN =
( L_V_COUNT1 - L_C_1 ) * 255 + STRLEN( L_WA_OBJCONT ). "volume of msg
L_WRK_OBJHEAD-OBJSNS = L_C_O."sensitivity
BR,
Suhas
2009 Sep 14 11:03 AM
Contd ...
*Receivers detail
L_WA_RECLIST-RCDAT = SY-DATUM. "Date document was received
L_WA_RECLIST-RCTIM = SY-UZEIT . "Time object was received
L_WA_RECLIST-RECESC = L_C_RECESC. "Specification of recipient type
L_WA_RECLIST-RECEXTNAM = L_V_MAILID. "Direct external as recipient
L_WA_RECLIST-SNDART = L_C_SNDART. "Output device
L_WA_RECLIST-SNDPRI = L_C_SNDPRI. "Send: Priority
L_WA_RECLIST-MAILSTATUS = L_C_MAILSTATUS. "Status of mail was
L_WA_RECLIST-NOTE_NUM = L_V_COUNT1. "note lines for this
*recipient
APPEND L_WA_RECLIST TO L_IT_RECLIST.
*Send mail to the responsible persons
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
OBJECT_HD_CHANGE = L_WRK_OBJHEAD
OBJECT_TYPE = L_C_OBJTYP
OWNER = SY-UNAME
TABLES
OBJCONT = L_IT_OBJCONT
RECEIVERS = L_IT_RECLIST
EXCEPTIONS
ACTIVE_USER_NOT_EXIST = 1
COMMUNICATION_FAILURE = 2
COMPONENT_NOT_AVAILABLE = 3
FOLDER_NOT_EXIST = 4
FOLDER_NO_AUTHORIZATION = 5
FORWARDER_NOT_EXIST = 6
NOTE_NOT_EXIST = 7
OBJECT_NOT_EXIST = 8
OBJECT_NOT_SENT = 9
OBJECT_NO_AUTHORIZATION = 10
OBJECT_TYPE_NOT_EXIST = 11
OPERATION_NO_AUTHORIZATION = 12
OWNER_NOT_EXIST = 13
PARAMETER_ERROR = 14
SUBSTITUTE_NOT_ACTIVE = 15
SUBSTITUTE_NOT_DEFINED = 16
SYSTEM_FAILURE = 17
TOO_MUCH_RECEIVERS = 18
USER_NOT_EXIST = 19
X_ERROR = 20
OTHERS = 21.
IF SY-SUBRC <> 0.
WRITE:/ TEXT-019.
ELSE.
COMMIT WORK.
ENDIF.
BR,
Suhas
2009 Sep 14 3:24 PM
Hi,
You can use the follwoing code to populate the data into mail. It wil send emial as table with all data.
IF NOT gi_hrp1000 IS INITIAL.
CONCATENATE 'The following are the datilas of inactive PU/DUs'(003)
'.<BR><BR>'
INTO wa_message SEPARATED BY space.
APPEND wa_message TO gi_messages.
Create table to populate the output
wa_message = '<table border=2>'.
APPEND wa_message TO gi_messages.
wa_message = '<tr>'.
APPEND wa_message TO gi_messages.
*Header of columns in table
wa_message = lc_table_header.
APPEND wa_message TO gi_messages.
wa_message = '</tr>'.
APPEND wa_message TO gi_messages.
*Populate Internal Table values into an html table in output.
LOOP AT gi_hrp1000 INTO wa_hrp1000.
wa_message = '<tr>'.
APPEND wa_message TO gi_messages.
wa_message = '<td>'.
APPEND wa_message TO gi_messages.
wa_message = wa_hrp1000-objid.
APPEND wa_message TO gi_messages.
wa_message = '</td>'.
APPEND wa_message TO gi_messages.
wa_message = '<td>'.
APPEND wa_message TO gi_messages.
wa_message = wa_hrp1000-stext.
APPEND wa_message TO gi_messages.
wa_message = '</td>'.
APPEND wa_message TO gi_messages.
wa_message = '<td>'.
APPEND wa_message TO gi_messages.
wa_message = wa_hrp1000-short.
APPEND wa_message TO gi_messages.
wa_message = '</td>'.
APPEND wa_message TO gi_messages.
APPEND wa_message TO gi_messages.
wa_message = '</tr>'.
APPEND wa_message TO gi_messages.
ENDLOOP.
where:
lc_table_header TYPE string VALUE '<td><b>Object ID</b></td><td><b>Code</b></td><td><b>Description</b></td>'. "#EC NOTEXT
Regards,
Rajesh Kumar
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |