ABAP Sending Email in Bcc
Friends,
I'm using below code to send an email , But problem is , After using the Bcc field , People whose name used in Bcc filed are still appering in 'To' field when they receive the email,
Actually the people who added in Bcc field must be disablled,
Can anone let me know inputs on this
========================================================================
To Sent the email as in To:
wa_receivers-receiver = so_malid-low.
wa_receivers-rec_id = so_malid-low.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
To send email as CC:
wa_receivers-receiver = so_malid-low.
wa_receivers-rec_id = so_malid-low.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X
wa_receivers-copy = 'X''.
To send as BCC:
wa_receivers-receiver = so_malid-low.
wa_receivers-rec_id = so_malid-low.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X
wa_receivers-copy_copy = 'X'.
Where wa_receivers is of type somlreci1
=========================================================
Thank you
Regards
Sandy
Hi Raj,
How to use the below line whichever u have told and where to use..in the below code
Use BLIND_COPY of wa_receivers
lt_mailrecipients-rec_type = 'U'.
lt_mailrecipients-com_type = 'INT'.
lt_mailrecipients-RECEIVER = email.
lt_mailrecipients-BLIND_COPY = 'X'.
APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .
lt_mailrecipients-rec_type = 'U'.
lt_mailrecipients-com_type = 'INT'.
lt_mailrecipients-RECEIVER = email.
lt_mailrecipients-BLIND_COPY = 'X'. APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .
Edited by: mrSandy1981 on Mar 11, 2010 8:12 AM
Similar Messages
-
Cannot send email to bcc: list without an address in to:
I've been trying to figure out how to send an email from my iPhone (3G) that only has recipients in the bcc: field, not in the to: field, but the send button stays grayed out until I enter an address in the to: field. I tried just entering "null" for the to: but the email wouldn't send because one of the addresses was invalid.
Any way to change this so I can send only to a bcc list?
Thanks!Thanks for your response.
Yeah, that's what I've been doing (sending to myself), but bcc: works without a to: recipient in Apple Mail, so I thought there should be a way to do it on the iPhone as well. It seems rather strange that the iPhone would be RFC 2822 compliant but Apple Mail wouldn't.
Message was edited by: Pete Edwards -
I used to send out christmas greetings from my biz to groups of 20 customers, in BCC format. all addresses are good, but the emails don't get sent now because of the supposed ASCII problem.
Restart the operating system in '''[http://en.wikipedia.org/wiki/Safe_mode safe mode with Networking]'''. This loads only the very basics needed to start your computer while enabling an Internet connection. Click on your operating system for instructions on how to start in safe mode: [http://windows.microsoft.com/en-us/windows-8/windows-startup-settings-including-safe-mode Windows 8], [http://windows.microsoft.com/en-us/windows/start-computer-safe-mode#start-computer-safe-mode=windows-7 Windows 7], [http://windows.microsoft.com/en-us/windows/start-computer-safe-mode#start-computer-safe-mode=windows-vista Windows Vista], [http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/boot_failsafe.mspx?mfr=true" Windows XP], [http://support.apple.com/kb/ht1564 OSX]
; If safe mode for the operating system fixes the issue, there's other software in your computer that's causing problems. Possibilities include but not limited to: AV scanning, virus/malware, background downloads such as program updates. -
Regarding sending Email as attachment
Hi guys.
One unique issue.
I meed to send a file as an attachment to one perticular address. Got to knowt that some function module like So_attmail would work. But that sends the content as body of the mail. But i want the file to be sent as attachment. Could someone help me this plz.
If possible also let me know what are the parameters that i need to pass in short.
Thanks in advance.
Abhi.Hi Abhi,
Have a look at this example:
http://www.sap-img.com/abap/sending-email-with-attachment.htm
http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm
http://www.sap-img.com/fu016.htm
1. We can send files with attachment.
However, There is some trick involved
in the binary files.
2. I have made a program (and it works fantastic)
ONLY 6 LINES FOR EMAILING
BELIEVE ME
ITS A FANTASTIC PROGRAM.
IT WILL WORK LIKE OUTLOOK EXPRESS !
3. The user is provided with
a) file name
b) email address to send mail
and it sends ANY FILE (.xls,.pdf .xyz..)
Instantaneously !
4. Make two things first :
1. Include with the name : ZAMI_INCLFOR_MAIL
2. Report with the name : ZAM_TEMP147 (any name will do)
3. Activate both and execute (2)
4. After providing filename, email adress
5. Code for Include :
10.08.2005 Amit M - Created
Include For Mail (First Req F16)
Modification Log
Data
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
FORM
FORM ml_customize USING objname objdesc.
Clear Variables
CLEAR docdata.
REFRESH objpack.
CLEAR objpack.
REFRESH objhead.
REFRESH objtxt.
CLEAR objtxt.
REFRESH objbin.
CLEAR objbin.
REFRESH objhex.
CLEAR objhex.
REFRESH reclist.
CLEAR reclist.
REFRESH listobject.
CLEAR listobject.
CLEAR tab_lines.
CLEAR doc_size.
CLEAR att_type.
Set Variables
docdata-obj_name = objname.
docdata-obj_descr = objdesc.
ENDFORM. "ml_customize
FORM
FORM ml_addrecp USING preceiver prec_type.
CLEAR reclist.
reclist-receiver = preceiver.
reclist-rec_type = prec_type.
APPEND reclist.
ENDFORM. "ml_customize
FORM
FORM ml_addtxt USING ptxt.
CLEAR objtxt.
objtxt = ptxt.
APPEND objtxt.
ENDFORM. "ml_customize
FORM
FORM ml_prepare USING bypassmemory whatatt_type whatname.
IF bypassmemory = ''.
Fetch List From Memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
in = listobject
out = objbin
EXCEPTIONS
OTHERS = 1
IF sy-subrc <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
ENDIF.
Header Data
Already Done Thru FM
Main Text
Already Done Thru FM
Packing Info For Text Data
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
APPEND objpack.
Packing Info Attachment
att_type = whatatt_type..
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = att_type.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = whatname.
APPEND objpack.
Receiver List
Already done thru fm
ENDFORM. "ml_prepare
FORM
FORM ml_dosend.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
CONTENTS_HEX = objhex
OBJECT_PARA =
object_parb =
receivers = reclist
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 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
ENDFORM. "ml_customize
FORM
FORM ml_spooltopdf USING whatspoolid.
DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
Call Function
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = whatspoolid
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
OTHERS = 12.
Convert
PERFORM doconv TABLES pdf objbin.
ENDFORM. "ml_spooltopdf
FORM
FORM doconv TABLES
mypdf STRUCTURE tline
outbin STRUCTURE solisti1.
Data
DATA : pos TYPE i.
DATA : len TYPE i.
Loop And Put Data
LOOP AT mypdf.
pos = 255 - len.
IF pos > 134. "length of pdf_table
pos = 134.
ENDIF.
outbin+len = mypdf(pos).
len = len + pos.
IF len = 255. "length of out (contents_bin)
APPEND outbin.
CLEAR: outbin, len.
IF pos < 134.
outbin = mypdf+pos.
len = 134 - pos.
ENDIF.
ENDIF.
ENDLOOP.
IF len > 0.
APPEND outbin.
ENDIF.
ENDFORM. "doconv
CODE FOR PROGRAM
5.
REPORT zam_temp147 .
INCLUDE zami_inclfor_mail.
DATA
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
data : path like PCFILE-PATH.
data : extension(5) type c.
data : name(100) type c.
SELECTION SCREEN
PARAMETERS : receiver TYPE somlreci1-receiver lower case.
PARAMETERS : p_file LIKE rlgrap-filename
OBLIGATORY.
AT SELECTION SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CLEAR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM ml_customize USING 'Tst' 'Testing'.
PERFORM ml_addrecp USING receiver 'U'.
PERFORM upl.
PERFORM doconv TABLES itab objbin.
PERFORM ml_prepare USING 'X' extension name.
PERFORM ml_dosend.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
FORM
FORM upl.
file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_name
filetype = 'BIN'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
path = file_name.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
EXTENSION = extension
NAME = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
INVALID_DRIVE = 1
INVALID_EXTENSION = 2
INVALID_NAME = 3
INVALID_PATH = 4
OTHERS = 5
ENDFORM. "upl
<b>PS : Reward points if helpful</b>
Thanks,
Ramya. -
Error in sending email to users(outside sap)
Hello experts,
We just transported my program to QAS server and I just tested it now if my program to send messages to emails outside works. Unfortunately, it doesn't. I am using FM SO_NEW_DOCUMENT_SEND_API1 and the sy-subrc = 2 whcih means document not sent. Also, there is window that popped up that says
Database error for <ADDR_PERS_COMP_COMM_GET> <0>
Again, thank you guys for all your help and take care!Hi,
Check this
Sending mail To Standard SAP MAIL Box
http://www.sap-img.com/abap/sending-email-with-attachment.htm
SCOT settings
http://www.sap-img.com/basis/basis-faq.htm
Sending External email through SAP
http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm\
http://www.sap-img.com/abap/sending-email-with-attachment.htm
Sample Code
Sending External email through SAP
What is the FM for sending the external email through SAP by attaching layout set to it?
These are the FM for sending external email :-
SO_DOCUMENT_SEND_API1
SAPoffice: Send new document with attachments via RFC
SO_NEW_DOCUMENT_ATT_SEND_API1
(In 4.6C only, You can go to SE37 and click the documentation on how to use it. A sample program is provided there.)
SAPoffice: Send new document with attachments via RFC
Note : If you are using FM SO_NEW_DOCUMENT_ATT_SEND_API1 then Export Parameter DOCUMENT_DATA-OBJ_DESCR contains the Subject.
SO_NEW_DOCUMENT_SEND_API1
SAPoffice: Send new document
How to send a report to an external mail-id?
<b>
Try this sample code :-</b>
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = '[email protected]'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
<b>
2nd Program</b>
REPORT ZSENDEXTERNAL.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
Mail Contents
OBJTXT = 'Minimum bid : $250000'.
APPEND OBJTXT.
OBJTXT = 'A representation of the pictures up for auction'.
APPEND OBJTXT.
OBJTXT = 'was included as attachment.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
*OBJBIN = ' \O/ '. APPEND OBJBIN.
*OBJBIN = ' | '. APPEND OBJBIN.
*OBJBIN = ' / \ '. APPEND OBJBIN.
*DESCRIBE TABLE OBJBIN LINES TAB_LINES.
*OBJHEAD = 'PICTURE.BMP'.
*APPEND OBJHEAD.
Creation of the entry for the compressed attachment
*OBJPACK-TRANSF_BIN = 'X'.
*OBJPACK-HEAD_START = 1.
*OBJPACK-HEAD_NUM = 1.
*OBJPACK-BODY_START = 1.
*OBJPACK-BODY_NUM = TAB_LINES.
*OBJPACK-DOC_TYPE = 'BMP'.
*OBJPACK-OBJ_NAME = 'PICTURE'.
*OBJPACK-OBJ_DESCR = 'Representation of object 138'.
*OBJPACK-DOC_SIZE = TAB_LINES * 255.
*APPEND OBJPACK.
Completing the recipient list
RECLIST-RECEIVER = '[email protected]'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
*RECLIST-RECEIVER = 'SAPUSERNAME'.
*RECLIST-REC_TYPE = 'P'.
*APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = '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.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT RECLIST.
WRITE: / RECLIST-RECEIVER(48), ':'.
IF RECLIST-RETRN_CODE = 0.
WRITE 'The document was sent'.
ELSE.
WRITE 'The document could not be sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
Message was edited by: Manoj Gupta -
SENDING AN EMAIL USING BCC AND RECIPIENT NAME APPEAR IN TO FIELD
I'm sending and email to several people using the BCC field. However, when the recipients receives the email, I want the recipient's name to appear in the TO field and the recipient not know the email was sent using the BCC. Right now, the
recipient knows it was sent BCC because their name is not appearing in the address fieldsHi Vinay,
You can use action defintions to send emails to your employee responsible.
for that pls check action profile 'Order_Messages' and within this, action definition
'ORDER_CONFIRMATION'.
Check in there. Partner funtion is assigned to it, in second level customizing and smart form to be mailed in third level customizing.
Prerequisite: emails should be maintained in BP master.
For your requirement you can do following settings:
In second level customizing(i.e. selecting the action definition and double click on the same)
Enter the partner funtion of Emp. responsible. in 'Partner Determination for the Action' Details. and check 'Partner Dependent'.
Secondly, in details for 'Action Determination and Action Merging' in 'Action Merging' details select 'Max. 1 Unprocessed Action for Each Action Definition.
Save the settings.
Schedule the actions using action scheduling.
Best Regards,
Pratik Patel
<b>Reward with Points!</b> -
To avoid the attachment for the body content while sending email from ABAP
SAP Version : 4.7
When i tried to send an external email from the abap report program, the body content of the mail is coming as an attachment for the same. I need to avoid this. Please give the suggestion. Am attaching the code.
DECLARATION PART *
TYPE-POOLS : SLIS.
TABLES : VBAK.
DECLARATION FOR ALV.
DATA : F_FIELD TYPE SLIS_T_FIELDCAT_ALV,
W_FIELD TYPE SLIS_FIELDCAT_ALV,
L_HEADER TYPE SLIS_T_LISTHEADER,
W_HEADER TYPE SLIS_LISTHEADER,
W_LAYOUT TYPE SLIS_LAYOUT_ALV,
t_sort type slis_t_sortinfo_alv,
w_sort type slis_sortinfo_alv.
TYPES : BEGIN OF T_VBAK,
VBELN LIKE VBAK-VBELN,
VKGRP LIKE VBAK-VKGRP,
KUNNR LIKE VBAK-KUNNR,
ERDAT LIKE VBAK-ERDAT,
VTWEG LIKE VBAK-VTWEG,
LIFSK LIKE VBAK-LIFSK,
VKBUR LIKE VBAK-VKBUR,
END OF T_VBAK.
TYPES : BEGIN OF T_VBAP,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
WERKS LIKE VBAP-WERKS,
ARKTX LIKE VBAP-ARKTX,
KWMENG LIKE VBAP-KWMENG,
CUOBJ LIKE VBAP-CUOBJ,
NETWR LIKE VBAP-NETWR,
ZSCHL_K LIKE VBAP-ZSCHL_K,
KONDM LIKE VBAP-KONDM,
ZZURWN LIKE VBAP-ZZURWN,
END OF T_VBAP.
TYPES : BEGIN OF T_LIPS,
VBELN LIKE LIPS-VBELN,
POSNR LIKE LIPS-POSNR,
VGBEL LIKE LIPS-VGBEL,
VGPOS LIKE LIPS-VGPOS,
END OF T_LIPS.
TYPES : BEGIN OF T_KNA1,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
ADRNR LIKE KNA1-ADRNR,
END OF T_KNA1.
TYPES : BEGIN OF T_VBKD,
VBELN LIKE VBKD-VBELN,
POSNR LIKE VBKD-POSNR,
BSTKD LIKE VBKD-BSTKD,
BSTDK LIKE VBKD-BSTDK,
KURSK LIKE VBKD-KURSK, " CURRENCY CHECK
BZIRK LIKE VBKD-BZIRK, " SALES DISTRICT
KDGRP LIKE VBKD-KDGRP,
IHREZ LIKE VBKD-IHREZ,
END OF T_VBKD.
TYPES : BEGIN OF T_LIKP,
VBELN LIKE LIKP-VBELN,
ERDAT LIKE LIKP-ERDAT,
END OF T_LIKP.
TYPES : BEGIN OF T_ADR6,
ADDRNUMBER LIKE ADR6-ADDRNUMBER,
SMTP_ADDR LIKE ADR6-SMTP_ADDR,
END OF T_ADR6.
DATA : BEGIN OF IT_CUST OCCURS 0,
KUNNR LIKE VBAK-KUNNR,
END OF IT_CUST.
TYPES : BEGIN OF T_VBUP,
VBELN LIKE VBUP-VBELN,
POSNR LIKE VBUP-POSNR,
KOSTA LIKE VBUP-KOSTA,
WBSTA LIKE VBUP-WBSTA,
END OF T_VBUP.
TYPES : BEGIN OF T_TVLST,
LIFSP LIKE TVLST-LIFSP,
VTEXT LIKE TVLST-VTEXT,
END OF T_TVLST.
TYPES : BEGIN OF T_CONFIG.
INCLUDE STRUCTURE CONF_OUT.
TYPES : END OF T_CONFIG.
DATA : TMP LIKE VBAK-KUNNR.
DATA : NAME_TEXT LIKE THEAD-TDNAME.
DATA : TLINE1 LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA : TMP_BRAKET LIKE CONF_OUT-ATWRT,
TMP_BRAKET1 LIKE CONF_OUT-ATWRT.
DATA : BEGIN OF IT_FINAL OCCURS 0,
WERKS LIKE VBAP-WERKS,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
KUNNR LIKE VBAK-KUNNR,
NAME1 LIKE KNA1-NAME1,
VBELN1 LIKE LIKP-VBELN,
ERDAT LIKE LIKP-ERDAT,
LIFSK LIKE VBAK-LIFSK,
ZZURWN LIKE VBAP-ZZURWN,
IHREZ LIKE VBKD-IHREZ,
ERDAT1 LIKE VBAK-ERDAT,
NETWR(25) type C,
BSTKD LIKE VBKD-BSTKD,
BSTDK LIKE VBKD-BSTDK,
SALORD(17) TYPE C,
PUMP_TYPE LIKE CONF_OUT-ATWRT,
PUMP_SIZE LIKE CONF_OUT-ATWRT,
VTEXT LIKE TVLST-VTEXT,
KWMENG(25) TYPE C,
FOOTER(330) TYPE C,
ITMTXT(330) TYPE C,
END OF IT_FINAL.
DATA : IT_VBAK TYPE STANDARD TABLE OF T_VBAK,
IT_VBAP TYPE STANDARD TABLE OF T_VBAP,
IT_VBKD TYPE STANDARD TABLE OF T_VBKD,
IT_LIKP TYPE STANDARD TABLE OF T_LIKP,
IT_LIPS TYPE STANDARD TABLE OF T_LIPS,
IT_VBUP TYPE STANDARD TABLE OF T_VBUP,
IT_KNA1 TYPE STANDARD TABLE OF T_KNA1,
IT_ADR6 TYPE STANDARD TABLE OF T_ADR6,
IT_FINAL1 LIKE IT_FINAL OCCURS 0 with header line,
IT_TVLST TYPE STANDARD TABLE OF T_TVLST,
IT_CONFIG TYPE STANDARD TABLE OF T_CONFIG,
W_VBAK TYPE T_VBAK,
W_VBAP TYPE T_VBAP,
W_VBKD TYPE T_VBKD,
W_LIKP TYPE T_LIKP,
W_ADR6 TYPE T_ADR6,
W_LIPS TYPE T_LIPS,
W_VBUP TYPE T_VBUP,
W_KNA1 TYPE T_KNA1,
W_TVLST TYPE T_TVLST,
W_CONFIG TYPE T_CONFIG.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
SELECTION-CRITERIA *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : R2 RADIOBUTTON GROUP G1 USER-COMMAND radio DEFAULT 'X',
R1 RADIOBUTTON GROUP G1 .
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT '[email protected]'.
PARAMETERS : P_VTWEG LIKE W_VBAK-VTWEG ,
P_WERKS LIKE W_VBAP-WERKS.
select-options : s_vkgrp for w_vbak-vkgrp,
s_ERDAT for w_LIKP-ERDAT.
selection-screen end of block b2.
Initialization
INITIALIZATION.
s_vkgrp-sign = 'I'.
s_vkgrp-option = 'BT'.
s_vkgrp-low = '313'.
s_vkgrp-high = '324'.
APPEND s_vkgrp.
s_erdat-sign = 'I'.
s_erdat-option = 'BT'.
s_erdat-low = '20080108'.
s_erdat-high = '20080108'.
s_erdat-low = '20070101'.
s_erdat-high = sy-datum.
APPEND s_erdat.
selection-screen validations
AT SELECTION-SCREEN.
Validation for Plant.
IF p_werks NE '7210'.
MESSAGE : 'Plant entered should be 7210' TYPE 'E'.
ENDIF.
START OF SELECTION *
start-of-selection.
GETTING THE DATA FROM THE DATABASE TABLE
PERFORM DATA_FETCH.
FILLING THE FINAL INTERNAL TABLE
PERFORM FILL_FINAL.
GETTING THE LIST FOR SENDING MAIL OR DISPLAY.
IF R1 = 'X'.
Populate table with details to be entered into .xls file
LOOP AT IT_CUST.
PERFORM build_xls_data_table using it_cust-kunnr.
ENDLOOP.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
ELSEIF R2 = 'X'.
PERFORM LIST_DISPLAY.
ENDIF.
END OF SELECTION *
end-of-selection.
*& Form DATA_FETCH
text
--> p1 text
<-- p2 text
FORM DATA_FETCH .
SELECT VBELN
VKGRP
KUNNR
ERDAT
VTWEG
LIFSK
VKBUR
INTO TABLE IT_VBAK
FROM VBAK
WHERE VTWEG = P_VTWEG
AND VKGRP IN S_VKGRP
AND LIFSK NE ''.
IF IT_VBAK[] IS NOT INITIAL.
SELECT LIFSP
VTEXT
INTO TABLE IT_TVLST
FROM TVLST
FOR ALL ENTRIES IN IT_VBAK
WHERE LIFSP = IT_VBAK-LIFSK
AND SPRAS = 'EN'.
SELECT VBELN
POSNR
MATNR
WERKS
ARKTX
KWMENG
CUOBJ
NETWR
ZSCHL_K
KONDM
ZZURWN
INTO TABLE IT_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN
AND WERKS = P_WERKS.
SELECT KUNNR
NAME1
ADRNR
INTO TABLE IT_KNA1
FROM KNA1
FOR ALL ENTRIES IN IT_VBAK
WHERE KUNNR = IT_VBAK-KUNNR.
SELECT VBELN
POSNR
BSTKD
BSTDK
KURSK
BZIRK
KDGRP
INTO TABLE IT_VBKD
FROM VBKD
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
IF IT_VBAP[] IS NOT INITIAL.
SELECT VBELN
POSNR
VGBEL
VGPOS
INTO TABLE IT_LIPS
FROM LIPS
FOR ALL ENTRIES IN IT_VBAP
WHERE VGBEL = IT_VBAP-VBELN
AND VGPOS = IT_VBAP-POSNR.
ENDIF.
IF IT_LIPS[] IS NOT INITIAL.
SELECT VBELN
ERDAT
INTO TABLE IT_LIKP
FROM LIKP
FOR ALL ENTRIES IN IT_LIPS
WHERE VBELN = IT_LIPS-VBELN
AND ERDAT IN S_ERDAT.
SELECT VBELN
POSNR
KOSTA
WBSTA
INTO TABLE IT_VBUP
FROM VBUP
FOR ALL ENTRIES IN IT_LIPS
WHERE VBELN = IT_LIPS-VBELN
AND POSNR = IT_LIPS-POSNR
AND KOSTA EQ 'C'
AND WBSTA NE 'C'.
ENDIF.
IF IT_KNA1[] IS NOT INITIAL.
SELECT ADDRNUMBER
SMTP_ADDR
INTO TABLE IT_ADR6
FROM ADR6
FOR ALL ENTRIES IN IT_KNA1
WHERE ADDRNUMBER = IT_KNA1-ADRNR.
ENDIF.
ENDFORM. " DATA_FETCH
*& Form LIST_DISPLAY
text
--> p1 text
<-- p2 text
FORM LIST_DISPLAY .
REFRESH F_FIELD.
IF R2 = 'X'.
W_FIELD-col_pos = 1.
W_FIELD-fieldname = 'WERKS'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Plant'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 2.
W_FIELD-fieldname = 'VBELN'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Sales Order'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 3.
W_FIELD-fieldname = 'KUNNR'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Customer Code'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 4.
W_FIELD-fieldname = 'NAME1'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Customer Name'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 5.
W_FIELD-fieldname = 'VBELN1'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Delivery Number'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 6.
W_FIELD-fieldname = 'ERDAT'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Delivery Date'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 7.
W_FIELD-fieldname = 'LIFSK'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Delivery Block'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 8.
W_FIELD-fieldname = 'PUMP_TYPE'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Pump Type'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 9.
W_FIELD-fieldname = 'PUMP_SIZE'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_l = 'Pump Size'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 10.
W_FIELD-fieldname = 'ZZURWN'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Pump Srno'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 11.
W_FIELD-fieldname = 'IHREZ'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Indent No.'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 12.
W_FIELD-fieldname = 'ERDAT'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Order Booking Dt'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 13.
W_FIELD-fieldname = 'NETWR'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C710'.
W_FIELD-seltext_m = 'Net Value'.
w_field-do_sum = 'X'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 14.
W_FIELD-fieldname = 'KWMENG'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C710'.
W_FIELD-seltext_m = 'Qty'.
w_field-do_sum = 'X'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 15.
W_FIELD-fieldname = 'BSTKD'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Customer PONO'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 16.
W_FIELD-fieldname = 'BSTDK'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Customer PODT'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 17.
W_FIELD-fieldname = 'SALORD'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Sales Order/Item'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 18.
W_FIELD-fieldname = 'VTEXT'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Delivery Block Desc.'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 19.
W_FIELD-fieldname = 'FOOTER'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Footer Text'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
W_FIELD-col_pos = 20.
W_FIELD-fieldname = 'ITMTXT'.
W_FIELD-tabname = 'IT_FINAL'.
W_FIELD-emphasize = 'C410'.
W_FIELD-seltext_m = 'Item Text'.
APPEND W_FIELD TO F_FIELD.
CLEAR W_FIELD.
PERFORM SORT_FIELD.
PERFORM LAYOUT_DISPLAY.
PERFORM GRID_DISPLAY.
ENDIF.
ENDFORM. " LIST_DISPLAY
*& Form FILL_FINAL
text
--> p1 text
<-- p2 text
FORM FILL_FINAL .
REFRESH IT_FINAL.
LOOP AT IT_VBUP INTO W_VBUP.
READ TABLE IT_LIPS INTO W_LIPS WITH KEY VBELN = W_VBUP-VBELN POSNR = W_VBUP-POSNR.
READ TABLE IT_LIKP INTO W_LIKP WITH KEY VBELN = W_LIPS-VBELN.
IF SY-SUBRC EQ 0.
READ TABLE IT_VBAP INTO W_VBAP WITH KEY VBELN = W_LIPS-VGBEL POSNR = W_LIPS-VGPOS.
READ TABLE IT_VBAK INTO W_VBAK WITH KEY VBELN = W_VBAP-VBELN.
READ TABLE IT_VBKD INTO W_VBKD WITH KEY VBELN = W_VBAK-VBELN.
READ TABLE IT_KNA1 INTO W_KNA1 WITH KEY KUNNR = W_VBAK-KUNNR.
READ TABLE IT_TVLST INTO W_TVLST WITH KEY LIFSP = W_VBAK-LIFSK.
IT_FINAL-WERKS = W_VBAP-WERKS.
IT_FINAL-VBELN = W_VBAP-VBELN.
IT_FINAL-KUNNR = W_VBAK-KUNNR.
IT_FINAL-NAME1 = W_KNA1-NAME1.
IT_FINAL-VBELN1 = W_LIKP-VBELN.
IT_FINAL-ERDAT = W_LIKP-ERDAT.
IT_FINAL-LIFSK = W_VBAK-LIFSK.
IT_FINAL-ZZURWN = W_VBAP-ZZURWN.
IT_FINAL-IHREZ = W_VBKD-IHREZ.
IT_FINAL-ERDAT1 = W_VBAK-ERDAT.
IT_FINAL-NETWR = W_VBAP-NETWR.
IT_FINAL-BSTKD = W_VBKD-BSTKD.
IT_FINAL-BSTDK = W_VBKD-BSTDK.
IT_FINAL-POSNR = W_VBAP-POSNR.
IT_FINAL-VTEXT = W_TVLST-VTEXT.
IT_FINAL-KWMENG = W_VBAP-KWMENG.
CONCATENATE W_VBAP-VBELN W_VBAP-POSNR INTO IT_FINAL-SALORD SEPARATED BY '/'.
IF W_VBAP-CUOBJ NE '000000000000000000'.
REFRESH IT_CONFIG.
CALL FUNCTION 'VC_I_GET_CONFIGURATION'
EXPORTING
INSTANCE = W_VBAP-CUOBJ
LANGUAGE = SY-LANGU
TABLES
CONFIGURATION = IT_CONFIG
EXCEPTIONS
INSTANCE_NOT_FOUND = 1
INTERNAL_ERROR = 2
NO_CLASS_ALLOCATION = 3
INSTANCE_NOT_VALID = 4
OTHERS = 5.
IF SY-SUBRC = 0.
READ TABLE IT_CONFIG INTO W_CONFIG WITH KEY ATNAM = 'IN_PUMP_TYPE'.
IT_FINAL-PUMP_TYPE = W_CONFIG-ATWRT.
CLEAR W_CONFIG.
READ TABLE IT_CONFIG INTO W_CONFIG WITH KEY ATNAM = 'IN_PUMP_SIZE' .
IT_FINAL-PUMP_SIZE = W_CONFIG-ATWRT.
CLEAR W_CONFIG.
ENDIF.
ENDIF.
move w_vbap-vbeln to name_text.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'ZKT1'
language = 'E'
name = name_text
object = 'VBBK'
TABLES
lines = tline1
EXCEPTIONS
OTHERS = 8.
LOOP AT TLINE1.
CONCATENATE IT_FINAL-FOOTER TLINE1-TDLINE+0(65) INTO IT_FINAL-FOOTER.
CLEAR : TLINE1.
ENDLOOP.
clear : name_text,tline1[].
concatenate w_vbap-vbeln w_vbap-posnr into name_text.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'ZKT3'
language = 'E'
name = name_text
object = 'VBBP'
TABLES
lines = tline1
EXCEPTIONS
OTHERS = 8.
LOOP AT TLINE1.
CONCATENATE IT_FINAL-ITMTXT TLINE1-TDLINE+0(65) INTO IT_FINAL-ITMTXT.
CLEAR : TLINE1.
ENDLOOP.
APPEND IT_FINAL.
ENDIF.
CLEAR : IT_FINAL,W_VBAP,W_VBKD,W_VBUP,W_LIPS,W_LIKP,W_KNA1,W_VBAK,W_TVLST,name_text,tline1[].
ENDLOOP.
IT_FINAL1[] = IT_FINAL[].
SORT IT_FINAL1 BY KUNNR.
LOOP AT IT_FINAL1.
IF TMP NE IT_FINAL1-KUNNR.
IT_CUST-KUNNR = IT_FINAL1-KUNNR.
APPEND IT_CUST.
clear : tmp,it_cust.
TMP = IT_FINAL1-KUNNR.
ENDIF.
CLEAR : IT_FINAL1.
ENDLOOP.
ENDFORM. " FILL_FINAL
*& Form LAYOUT_DISPLAY
text
--> p1 text
<-- p2 text
FORM LAYOUT_DISPLAY .
W_LAYOUT-colwidth_optimize = 'X'.
ENDFORM. " LAYOUT_DISPLAY
*& Form GRID_DISPLAY
text
--> p1 text
<-- p2 text
FORM GRID_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT = W_LAYOUT
IT_FIELDCAT = F_FIELD
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT = T_SORT
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 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.
ENDFORM. " GRID_DISPLAY
*& Form SORT_FIELD
text
--> p1 text
<-- p2 text
FORM SORT_FIELD .
w_sort-spos = 1.
w_sort-fieldname = 'KUNNR'.
w_sort-up = 'X'.
append w_sort to t_sort.
clear w_sort.
w_sort-spos = 2.
w_sort-fieldname = 'VBELN'.
w_sort-up = 'X'.
append w_sort to t_sort.
clear w_sort.
ENDFORM. " SORT_FIELD
*& Form TOP_OF_PAGE
text
FORM top_of_page.
IF R2 = 'X'.
REFRESH l_header.
w_header-typ = 'S'.
w_header-key = 'Delivery Block : '.
w_header-info = 'Outbound delivery created but not despatched'.
APPEND w_header TO l_header.
CLEAR w_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = l_header.
ENDIF.
ENDFORM. "TOP_OF_PAGE
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table using custcode.
CONSTANTS: con_cret TYPE X VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
data : it_custcode like vbak-kunnr.
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
clear : it_attach,it_attach[].
CONCATENATE 'Customer PONO' 'Customer PODT' 'Sales Order No' 'Item No'
'Pump Type' 'Pump Size' 'Order Value Rs' 'Delivery No.' 'Delivery Dt.'
'Quantity' 'Reasons for not getting Despatch'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
it_custcode = custcode.
CLEAR : W_KNA1,W_ADR6. "Code need to be added once testing is over.
READ TABLE IT_KNA1 INTO W_KNA1 WITH KEY KUNNR = IT_CUSTCODE.
READ TABLE IT_ADR6 INTO W_ADR6 WITH KEY ADDRNUMBER = W_KNA1-ADRNR.
P_EMAIL = W_ADR6-SMTP_ADDR.
LOOP AT it_final where kunnr = it_custcode.
CONCATENATE
IT_FINAL-BSTKD
IT_FINAL-BSTDK
IT_FINAL-VBELN
IT_FINAL-POSNR
IT_FINAL-PUMP_TYPE
IT_FINAL-PUMP_SIZE
IT_FINAL-NETWR
IT_FINAL-VBELN1
IT_FINAL-ERDAT
IT_FINAL-KWMENG
IT_FINAL-VTEXT
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
clear it_final.
ENDLOOP.
if R1 = 'X'.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'AWAITING DESPATCH CLEARANCE'
'XLS'
'Delivery_Block'
'Delivery_Blk'
'[email protected]'
'INT'
changing gd_error
gd_reciever.
endif.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR : w_doc_data,w_cnt.
DESCRIBE TABLE it_attach LINES w_cnt.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
object_header = objhead
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'We have manufactured the pump/s against your purchase order and regret to inform'.
APPEND it_message.
it_message = 'you that same cannot be despatched for the reason/s indicated below.'.
APPEND it_message.
it_message = ' '.
APPEND it_message.
it_message = 'Please find the below attachment "Delivery_Blk.xls" for the details.'.
APPEND it_message.
it_message = ' '.
APPEND it_message.
it_message = 'We now request you to send the required detail/s by return mail/post to enable us '.
APPEND it_message.
it_message = 'to despatch the pump/s at the earliest.'.
APPEND it_message.
it_message = ' '.
APPEND it_message.
it_message = ' '.
APPEND it_message.
it_message = 'Best Regards'.
APPEND it_message.
it_message = 'O.E. ENGINEER'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODYHi,
Refer to the following piece of code. This is the simple code to send email with content and attachment.
Declaration
DATA: lwa_hd_change TYPE sood1,
lt_objcont TYPE STANDARD TABLE OF soli,
lwa_objcont TYPE soli,
lt_receivers TYPE STANDARD TABLE OF soos1,
lwa_receivers TYPE soos1 ,
lt_att_cont TYPE STANDARD TABLE OF soli,
lwa_att_cont TYPE soli,
lt_packing TYPE STANDARD TABLE OF soxpl,
lwa_packing TYPE soxpl,
lf_sent TYPE sonv-flag,
lf_size TYPE i.
CONSTANTS: lc_obj(11) TYPE c VALUE 'BOMSouthco',
lc_desc(20) TYPE c VALUE 'BOM Download',
lc_lang(1) TYPE c VALUE 'E',
lc_raw(3) TYPE c VALUE 'RAW',
lc_net(1) TYPE c VALUE 'U',
lc_mail(4) TYPE c VALUE 'MAIL',
lc_xls(3) TYPE c VALUE 'XLS',
lc_ext(3) TYPE c VALUE 'EXT'.
Passing values to the strutures used in SO_OBJECT_SEND function module
lwa_hd_change-objla = lc_lang.
lwa_hd_change-objnam = lc_obj.
lwa_hd_change-objdes = lc_desc.
lwa_hd_change-objlen = 255.
lwa_objcont-line = text-t29.
APPEND lwa_objcont TO lt_objcont.
CLEAR lwa_objcont.
lwa_receivers-recextnam = text-t31.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
lwa_receivers-recextnam = text-t30.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
Passing values for the attachment file
LOOP AT gt_output INTO gwa_output.
CONCATENATE gf_lf gwa_output-matnr gf_etb gwa_output-idnrk gf_etb
gwa_output-type gf_etb gwa_output-menge gf_etb
gwa_output-meins gf_etb gwa_output-comp gf_etb
INTO lwa_att_cont-line.
APPEND lwa_att_cont TO lt_att_cont.
CLEAR lwa_att_cont.
ENDLOOP.
CHECK lt_att_cont IS NOT INITIAL.
DESCRIBE TABLE lt_att_cont LINES lf_size.
lwa_packing-transf_bin = ' '.
lwa_packing-head_start = 1.
lwa_packing-head_num = 0.
lwa_packing-body_start = 1.
lwa_packing-body_num = lf_size.
lwa_packing-file_ext = lc_xls.
lwa_packing-objlen = lf_size * 255.
lwa_packing-objtp = lc_ext.
lwa_packing-objdes = lc_desc.
lwa_packing-objnam = lc_obj.
APPEND lwa_packing TO lt_packing.
CLEAR lwa_packing.
CHECK gf_error IS NOT INITIAL. "Check if unix file is written
FM to send email to the intended recipients
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = lwa_hd_change
object_type = lc_raw
IMPORTING
sent_to_all = lf_sent
TABLES
objcont = lt_objcont
receivers = lt_receivers
packing_list = lt_packing
att_cont = lt_att_cont
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
originator_not_exist = 20
x_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE s004 WITH text-t34.
ENDIF.
COMMIT WORK.
Reward if helpful.
Regards,
Ramya -
When I send an email with bcc recipients, the bcc does not show in my sent mail so I can't reference back later who I sent the email to. Worked in Snow Leopard but not in Yosemite. Please advise if their is fix for that.
Did you select View->Bcc Address Field from the menu bar?
-
Trouble with SAPconnect / sending email in ABAP-code
Hi,
with the code below I try to send an email from ABAP outside
to an mail-account in the internet.
I'll get no error/exceptions but the mail will be not send
to the internet-mail-account.
In Transaktion SCOT I checked the SAPconnect-Node "INT"-"SMTP".
There is a mailserver with the right IP und the right Port. So I don't understand
what could be the problem!?
Can anybody help me and say me why the code below doesn't works?
Best wishes!
* For API
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.
mailtxt-line = 'This is a test'.
append mailtxt.
mailrec-receiver = '[email protected]'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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.
* Start the send process using the following statement
submit rsconn01 with mode = 'int' and return.
Message was edited by:
sebastian eckesSAP is a robust system, which gives many facilities in the form of Function Modules (FMs) for connecting to external systems or for use within the system. With a clever use of these FMs we can achieve a lot of things through ABAP code.
This article focuses on ways to send E-mails and SAP Mails using ABAP code.
Firstly SAP Mail
A SAP mail is a mail internal to the SAP system. It is a very good forum to exchange information with other users. Using a SAP mail in ABAP code facilitates exchange of automatic messages at various stages of the business process. It is easy to use and saves many hassles involved in using workflows for exchanging messages.
The ABAP code to send a sap mail is built around the FM SO_OBJECT_SEND which has the following pattern.
call function 'SO_OBJECT_SEND'
exporting
EXTERN_ADDRESS = ' '
FOLDER_ID = ' '
FORWARDER = ' '
OBJECT_FL_CHANGE = ' '
OBJECT_HD_CHANGE = ' '
OBJECT_ID = ' '
OBJECT_TYPE = ' '
OUTBOX_FLAG = ' '
OWNER = ' '
STORE_FLAG = ' '
DELETE_FLAG = ' '
SENDER = ' '
CHECK_ALREADY_SENT = ' '
importing
object_id_new =
sent_to_all =
tables
OBJCONT =
OBJHEAD =
OBJPARA =
OBJPARB =
receivers =
PACKING_LIST =
ATT_CONT =
ATT_HEAD =
NOTE_TEXT =
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.
In the next article we will understand the main parameters and table interfaces of the FM.
Import Parameters Name and Description Field name Field function
Object_hd_change (structure) Contains the process to be done when SAP mail is marked for execution.When the Execute Icon in the SAP mail is clicked the corresponding object is executed vmtyp D for dialog module F for function moduleR for reportT for transactionU for transaction with export
Acnam Name of the object which is to be executed, like name of transaction/report
Skips X to execute first screen in background
Objsns Indicates sensitivity of the object. P for private objectF for functional objectO for confidential objectC for company confidential objectSensitivity level is restricted to O for documents in shared folders
Objla Language of the document E for Englishsy-langu for system language
Objnam Name of the document
Objdes Short description (Title) of the document
Objsrt Name of the sort field. This is used to group documents based on certain criteria
Object_type Type of document to be sent with mail RAW for raw text (default) DOC for word file XLS for excel fileAll classes can be used except for folders (FOL) and distribution lists (DLI)
Outbox_flag X to indicate that mail should also be stored in outbox of the user after sending (default )
Owner Sap login of the user responsible for transmission
Table Parameters Name and Description Field Name Field function
Objcont Table to hold the body of the mail Line Text lines up to 255 characters
Objhead Table to hold number of lines in the body of the mail, i.e size of the table in lines Line Text lines up to 255 characters
Objpara Table to hold the set/get parameters to be transferred to the processing element Name Name of the parameter. Only first three characters are used
Option Not used
Low Value of the parameter in name
High Not used
Objparb Table to hold information for mails to which a certain processing type is assigned. For a report or transaction with transfer of values to global memory, the table has to contain the parameters with relevant values. The memory id is taken from the first row. For a FM or dialog module, data in table will be transferred as table parameter msgdial Name For report or transaction with transfer of values to global memory, the field for first row should hold the name of the memory id used for export and the other rows should hold the parameter names. For FM or dialog module this field should hold the values as per the usage of the module
Value For report or transaction with transfer of values to global memory, the field for first row should remain empty and the other rows should hold values of the parameters. For FM or dialog module this field should hold the values as per the usage of the module
Receivers Table to hold recipient details Recnam SAP login of the recipient. Append all the recipients to this table
Sndcp X for sending mail as a copy
Sndex X for sending as express document. This will prompt a logged on recipient saying that he or she has received an express mail
Recesc B for SAP user E for external email addressU for unix address
Export Parameters Name and Description Field name Field function
Object_id_new Contains object id of document created during send process
Sent_to_all X indicates that document was sent to all recipients. Flag is not activated if sending fails in one or more cases
Main Exceptions Name and Description Description
Too_much_receivers Number of recipients is greater than number for which sender is authorised to send
Object_not_sent Document was not delivered to any of the recipients
Object_not_exist Document class specified does not exist or cannot be sent
Object_no_authorisation Document could not be sent as one of the required authorisations does not exist
Parameter_error Invalid combination of parameter values transferred to FM
X_error Internal error occurred
Once all the parameters and table interfaces are properly filled, call the function module to send the SAP mail to the recipient inbox.
Care should be taken to report the status of execution of the function module to the user using one of the exceptions defined (refer function module pattern above)
Though SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly. The next article covers sending E-mails using ABAP.
Sending Email to a non-SAP system:
Though SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly.
Sending an email to the Microsoft Inbox is a way of interacting with a non SAP system through ABAP code and hence is very interesting. A fair knowledge of UNIX shell scripting is assumed here.
The ABAP code to send an email to Microsoft inbox revolves around following UNIX script
Echo "From:" "<"$1">" > <unix file path name>
Echo "To:" "<"$2">" >> <unix file path name>
Echo "Subject:" "<"$3">" >> <unix file path name>
Cat $4 >> <unix file path name>
Uuencode $5 $6 >> <unix file path name>
Cat <unix file path name> | /usr/sbin/sendmail f $fraddr $toaddr
(Note : the commands in the above script can be case sensitive. Check the actual case on the unix installation in question)
Let us understand the various parts of the above script.
$1 = Sender email address
$2 = Recipient email address
$3 = Subject of the email
$4 = Path of unix server file having email body
Form email body as an internal table in ABAP program, download it to a unix server file
$5 = Path of unix server file to be sent as email attachment
$6 = Name to be given to the attachment (like test1.doc, test1.xls). The corresponding Microsoft icon
will be shown in the email for the type of file attached ( Word document, excel document etc)
The script builds a temporary file and pipes the file to the sendmail command to achieve the mission.
This script can be invoked from SAP to send the mail to the intended recipient. Store this small script on the unix server. (Assume script name is sndmail )
To do this we should define a link in the SAP system between a customized command and this unix script.
The FM to define a customized command in SAP system has the following pattern.
call function 'SXPG_CALL_SYSTEM'
exporting
commandname =
PARAMETERS = ' '
importing
status =
tables
exec_protocol =
exceptions
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
others = 12.
In the next article we will understand the main parameters and table interfaces of the FM.
Import Parameters Name and Description Field name Field function
Commandname Name of unix shell script or command to be executed by SAP Name of unix shell script to be invoked
Parameters The parameters to be sent to unix shell script ($1, $2 etc). Send parameters as a concatenated string separated by space and length not exceeding 128 characters For eg in UNIX environment the above shell script would be executed as Sndmail [email protected] [email protected] Trial /home/test.doc testmail.We will be simulating this command using the FM from SAP system
Table Parameters Name and Description Field Name Field function
Exec_protocol (structure) Table to get messages from unix server after shell script is executed Length Length of the message from external program i.e unix
Message Log message from external program i.e unix
Export Parameters Name and Description Field name Field function
Status Contains the status of execution of external program Scheduling status of external program i.e unix
Once the above FM is invoked with the necessary parameters the unix program sendmail will send a mail to the inbox of the recipient in Microsoft.
The restriction on the parameter string length of 128 characters can be removed to make way for very long email addresses and subjects. Build the parameters into an internal table and download it as a file on the unix server. Instead of passing each parameter individually, pass the unix server path of this file as the parameter to the unix shell script (sndmail mentioned above). Modify the shell script to read every line of this parameter file as variables to be used in the shell script.
In the next article we will see an example of the ABAP code you can use to send SAP Mails.
REPORT ZTSAPMAIL.
DATA: X_OBJECT_TYPE LIKE SOOD-OBJTP.
DATA: BEGIN OF X_OBJECT_HD_CHANGE.
INCLUDE STRUCTURE SOOD1.
DATA: END OF X_OBJECT_HD_CHANGE.
DATA: BEGIN OF X_OBJCONT OCCURS 10.
INCLUDE STRUCTURE SOLI.
DATA: END OF X_OBJCONT.
DATA: BEGIN OF X_OBJHEAD OCCURS 0.
INCLUDE STRUCTURE SOLI.
DATA: END OF X_OBJHEAD.
DATA: BEGIN OF RAW_HEAD.
INCLUDE STRUCTURE SORH.
DATA: END OF RAW_HEAD.
DATA: BEGIN OF X_RECEIVERS OCCURS 0.
INCLUDE STRUCTURE SOOS1.
DATA: END OF X_RECEIVERS.
PARAMETERS: RECEIVER LIKE X_RECEIVERS-RECNAM. " Name
*BUILD MESSAGE HEADER
MOVE 'Sort field goes here' TO X_OBJECT_HD_CHANGE-OBJSRT. " Sort field
MOVE 'Name of the object goes here' TO X_OBJECT_HD_CHANGE-OBJNAM. " Name
MOVE 'Document title goes here' TO X_OBJECT_HD_CHANGE-OBJDES. " Title
MOVE 'F' TO X_OBJECT_HD_CHANGE-OBJSNS. " Functional OBJECT
MOVE 'E' TO X_OBJECT_HD_CHANGE-OBJLA. " Language
Object type of the new document
MOVE 'RAW' TO X_OBJECT_TYPE.
CLEAR X_OBJCONT.
MOVE 'Contents of mail' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
CLEAR X_OBJCONT-LINE. APPEND X_OBJCONT.
MOVE 'More contents' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
MOVE 'Still more contents'
to x_objcont-line.
APPEND X_OBJCONT.
MOVE ' ' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
Specific header (Dependent on the object type, here RAW)
REFRESH X_OBJHEAD.
DESCRIBE TABLE X_OBJCONT LINES RAW_HEAD-RAWSIZ.
MOVE RAW_HEAD TO X_OBJHEAD.
APPEND X_OBJHEAD.
*RECEIVERS table
CLEAR X_RECEIVERS.
REFRESH X_RECEIVERS.
MOVE RECEIVER TO X_RECEIVERS-RECNAM. " Name
MOVE 'B' TO X_RECEIVERS-RECESC. " Receiver type
MOVE 'X' TO X_RECEIVERS-SNDCP. " Send as a copy
MOVE 'X' TO X_RECEIVERS-SNDEX. " EXPRESS DOCUMENT
APPEND X_RECEIVERS.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
folder_id = 'OUTBOX'
forwarder = x_forwarder
object_fl_change = x_object_fl_change
OBJECT_HD_CHANGE = X_OBJECT_HD_CHANGE
object_id = x_object_id
OBJECT_TYPE = X_OBJECT_TYPE
OUTBOX_FLAG = 'X'
OWNER = SY-UNAME
store_flag = x_store_flag
importing
object_id_new = x_object_id_new
sent_to_all = x_sent_to_all "May need to use
TABLES
OBJCONT = X_OBJCONT
OBJHEAD = X_OBJHEAD
objpara = x_objpara
objparb = x_objparb
RECEIVERS = X_RECEIVERS.
REPORT ZTUNIXMAIL.
DATA : TO_ADDRESS LIKE SY_LISEL,
FROM_ADDRESS LIKE SY-LISEL,
SUBJECT LIKE SY-LISEL,
ATTACHMENT_NAME LIKE SY_LISEL,
DATA_FILE_PATH LIKE SXPGCOLIST-PARAMETERS,
BODY_FILE_PATH LIKE SXPGCOLIST-PARAMETERS.
DATA : BEGIN OF INT_EMAIL_ATTACH OCCURS 0,
TXTLINE CHAR(255),
END OF INT_EMAIL_ATTACH.
DATA : BEGIN OF INT_EMAIL_BODY OCCURS 0,
TXTLINE CHAR(255),
END OF INT_EMAIL_BODY.
CLEAR : INT_EXEC_PROTOCOL,INT_EMAIL_ATTACH,INT_EMAIL_BODY.
REFRESH : INT_EXEC_PROTOCOL,INT_EMAIL_ATTACH,INT_EMAIL_BODY.
INT_EMAIL_ATTACH-TXTLINE = 'Put all attachment text in this table'.
APPEND INT_EMAIL_ATTACH. CLEAR INT_EMAIL_ATTACH.
INT_EMAIL_BODY-TXTLINE = 'Put all attachment text in this table'.
APPEND INT_EMAIL_BODY. CLEAR INT_EMAIL_BODY.
CONCATENATE TO_ADDRESS
FROM_ADDRESS
SUBJECT
BODY_FILE_PATH
DATA_FILE_PATH
ATTACHMENT_NAME
INTO V_PARAMETERS.
IF NOT INT_EMAIL_ATTACH[] IS INITIAL.
OPEN DATASET DATA_FILE_PATH FOR OUTPUT IN TEXT MODE.
LOOP AT INT_EMAIL_ATTACH.
TRANSFER INT_EMAIL_ATTACH-TXTLINE TO DATA_FILE_PATH.
ENDLOOP.
CLOSE DATASET DATA_FILE_PATH.
ENDIF.
IF NOT INT_EMAIL_BODY[] IS INITIAL.
OPEN DATASET BODY_FILE_PATH FOR OUTPUT IN TEXT MODE.
LOOP AT INT_EMAIL_BODY.
TRANSFER INT_EMAIL_BODY-TXTLINE TO BODY_FILE_PATH.
ENDLOOP.
CLOSE DATASET BODY_FILE_PATH.
ENDIF.
CALL FUNCTION 'SXPG_CALL_SYSTEM'
EXPORTING
COMMANDNAME = 'Z_EMAIL' - Command calling unix script
PARAMETERS = V_PARAMETERS
importing
status = ''
TABLES
EXEC_PROTOCOL = INT_EXEC_PROTOCOL
EXCEPTIONS
NO_PERMISSION = 1
COMMAND_NOT_FOUND = 2
PARAMETERS_TOO_LONG = 3
SECURITY_RISK = 4
WRONG_CHECK_CALL_INTERFACE = 5
PROGRAM_START_ERROR = 6
PROGRAM_TERMINATION_ERROR = 7
X_ERROR = 8
PARAMETER_EXPECTED = 9
TOO_MANY_PARAMETERS = 10
ILLEGAL_COMMAND = 11
OTHERS = 12.
regards,
srinivas
<b>*Reward points for useful answers*</b> -
ABAP program for sending emails
Hello SAP developers,
I need ABAP program for sending emails to my internet adress in background - just some simple header with no body and no attachement. Recipient should be specified due the parameter etc... Does program like this exist or i have to create it? I am not familiar with ABAP. I am basis admin so I am little bit lost in this. I have tried program code from this page ->
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
But anyway it does not work - there is an exception "no message send". SCOT is configured, mails are working fine from transaction SBWP.
Thanks in advace
JMI have already solved my issue through CCMS agents and RZ20 central autoreaction (sms) in Solution Manager.
Regards
JM -
How to send Email with Cc and Bcc using MailPackage
Hi ,
we are using Mail Package to send the Email using Mail Adapter.We have a requirement where we need to send Email with Cc and Bcc using Mail Package .
Can we send Cc and Bcc using Mail Package ?
Thanks
Rajesh .HI Rajesh,
There is a standard structure for Receiver Mail adopter which we can get from SAP market Place but it is not provided with CC if u want to use CC then you have to go with Dynamic Configuration.
DynamicConfiguration configuration = (DynamicConfiguration) container.getTransformationParameters().getStreamTransformationConstants.DYNAMIC_CONFIGURATION);
/*any other required fields*/
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Mail", "THeaderCC");
configuration.put(key, "ccemail @ test.com");
Regards
Praveen Reddy
Edited by: Maareddy Praveen Reddy on Aug 10, 2011 12:17 PM -
hi
just want to ask if you have any sample code how to send email using microsoft outlook in ABAP.
thanks.
donnaHi ,
The following is the code to send an email.
This program extract does two things
1. Sends file contents as body of the mail
2. Sends a file as attachment.
Before going through the code, just check
the unix command for sending email, given below.
<b>(cat </b> 'filename containing the body of email' <b>; uuencode</b> 'name of file to be attached' 'Name of attached file to be displayed in the email') <b>| /bin/mailx -s "</b>
Subject of the mail <b>"</b> 'To email address'
Cat sends the file contents as body of email and uuencode sends the file as attachment
<b>(cat </b> content <b>; uuencode</b> filename fname<b>)</b> <b>| /bin/mailx -s "</b>
'Subject of the mail' <b>"</b> 'To email address'
FORM mail_message USING username filename.
DATA: BEGIN OF file OCCURS 0,
line(250),
END OF file.
Attached file will be displayed in the mail as fname
filename is the file that will be send as attachment in the email.
DATA : filename(100) TYPE c VALUE '/data/logs/lfile.txt'
DATA : fname(25) VALUE 'Logfile.txt'.
DATA: parcom(300) TYPE c,
pbody1(50) VALUE
'Please find the log details as an attachment
(This is the body of email) '
Content contains the file which contains the body of the mail.
Username contains the email address to which the mail has to be sent.
DATA : content(50) VALUE '/usr/sap/tmp/body'.
DATA : username(50) VALUE '[email protected]'.
CLEAR parcom.
TRANSLATE username TO LOWER CASE.
TRANSLATE filename TO LOWER CASE.
Writing the body of the mail to the file
OPEN DATASET content FOR OUTPUT IN TEXT MODE.
TRANSFER pbody1 TO content.
CLOSE DATASET content.
CONCATENATE '(cat ' content '; uuencode ' filename fname ') |' '/bin/mailx -s "'
'Subject of the mail' '"' username
INTO parcom SEPARATED BY space.
REFRESH file.
CLEAR file.
Send The Message.
CALL 'SYSTEM' ID 'COMMAND' FIELD parcom
ID 'TAB' FIELD file-sys.
if sy-subrc = '0'.
write: / 'Mail message successfully sent'.
else.
write: / 'Mail message failed'.
endif.
ENDFORM.
Reward points for helpful answers -
Sending emails from ABAP program
Hi,
I need to send error emails from ABAP program.
I have to pass error internal table as text (not as attachment) in the email.
Can anybody supply any sample code?
Thanks in advance.
Regards,
Arun MohanHI,
See if this code helps:
***Sending mail to the receipients
if not it_final[] is initial.
Populate table with detaisl to be entered into .xls file
PERFORM BUILD_XLS_DATA_TABLE.
PERFORM POPULATE_EMAIL_MESSAGE_BODY.
Send file by email as .xls speadsheet
PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
TABLES IT_MESSAGE
IT_ATTACH
USING P_EMAIL
'Sales Register Report - Set Top Box / Accessories'
'XLS'
'SSTB'
CHANGING GD_ERROR
GD_RECIEVER.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
endif.
*& Form BUILD_XLS_DATA_TABLE
text
--> p1 text
<-- p2 text
FORM BUILD_XLS_DATA_TABLE .
data: wa_itab like it_final.
CONSTANTS:
CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
CONCATENATE 'Business Place' 'Region Code' 'Region' 'Branch Code'
'Branch' 'Material Desc' 'Area off Code'
'Area Name' 'Zone code' 'Zone Name' 'Cust No' 'Cust Name'
'Bill Doc No' 'Bill Date' 'Base Val' 'Total Val' 'Quantity'
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
LOOP AT IT_FINAL INTO WA_ITAB.
CONCATENATE WA_ITAB-BUSINESS_PLACE
WA_ITAB-KVGR1
WA_ITAB-REGION
WA_ITAB-VKBUR
WA_ITAB-SALES_OFF
WA_ITAB-ARKTX
WA_ITAB-vkgrp
WA_ITAB-sales_grp
WA_ITAB-bzirk
WA_ITAB-zone
WA_ITAB-kunnr
WA_ITAB-name
WA_ITAB-vbeln
WA_ITAB-fkdat
WA_ITAB-base_value
WA_ITAB-total_value
WA_ITAB-fkimg
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form POPULATE_EMAIL_MESSAGE_BODY
text
--> p1 text
<-- p2 text
FORM POPULATE_EMAIL_MESSAGE_BODY .
REFRESH IT_MESSAGE.
CONCATENATE SY-DATUM6(2) '/' SY-DATUM4(2) '/' SY-DATUM+0(4) INTO G_DATE.
IT_MESSAGE = 'Please find attached excel sheet.'.
APPEND IT_MESSAGE.
IT_MESSAGE = 'Sales Register Report - Set Top Box / Accessories'.
APPEND IT_MESSAGE.
Concatenate 'Report generated date' ':' G_Date '.' into IT_MESSAGE.
APPEND IT_MESSAGE.
clear it_message.
append it_message.
IT_MESSAGE = 'This is an autogenerated mail, please do not reply'.
APPEND IT_MESSAGE.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE
PIT_ATTACH
USING P_EMAIL
P_MTITLE
P_FORMAT
P_FILENAME
P_ATTDESCRIPTION
P_SENDER_ADDRESS
P_SENDER_ADDRES_TYPE
CHANGING P_ERROR
P_RECIEVER.
DATA: LD_ERROR TYPE SY-SUBRC,
LD_RECIEVER TYPE SY-SUBRC,
LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,
LD_EMAIL LIKE SOMLRECI1-RECEIVER,
LD_FORMAT TYPE SO_OBJ_TP ,
LD_ATTDESCRIPTION TYPE SO_OBJ_NAM ,
LD_ATTFILENAME TYPE SO_OBJ_DES ,
LD_SENDER_ADDRESS LIKE SOEXTRECI1-RECEIVER,
LD_SENDER_ADDRESS_TYPE LIKE SOEXTRECI1-ADR_TYP,
LD_RECEIVER LIKE SY-SUBRC.
LD_EMAIL = P_EMAIL.
LD_MTITLE = P_MTITLE.
LD_FORMAT = P_FORMAT.
LD_ATTDESCRIPTION = P_ATTDESCRIPTION.
LD_ATTFILENAME = P_FILENAME.
LD_SENDER_ADDRESS = P_SENDER_ADDRESS.
LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.
Fill the document data.
W_DOC_DATA-DOC_SIZE = 1.
Populate the subject/generic message attributes
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'SAPRPT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE .
W_DOC_DATA-SENSITIVTY = 'F'.
Fill the document data and get size of attachment
CLEAR W_DOC_DATA.
READ TABLE IT_ATTACH INDEX W_CNT.
W_DOC_DATA-DOC_SIZE =
( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'SAPRPT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE.
W_DOC_DATA-SENSITIVTY = 'F'.
CLEAR T_ATTACHMENT.
REFRESH T_ATTACHMENT.
T_ATTACHMENT[] = PIT_ATTACH[].
Describe the body of the message
CLEAR T_PACKING_LIST.
REFRESH T_PACKING_LIST.
T_PACKING_LIST-TRANSF_BIN = SPACE.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 0.
T_PACKING_LIST-BODY_START = 1.
T_PACKING_LIST-OBJ_NAME = 'stb'.
DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND T_PACKING_LIST.
Create attachment notification
T_PACKING_LIST-TRANSF_BIN = 'X'.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 1.
T_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = LD_FORMAT.
T_PACKING_LIST-DOC_TYPE = 'XLS'.
T_PACKING_LIST-OBJ_DESCR = LD_ATTDESCRIPTION.
T_PACKING_LIST-OBJ_DESCR = 'Sales_STB'.
T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.
T_PACKING_LIST-OBJ_NAME = 'stb'.
T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.
APPEND T_PACKING_LIST.
Add the recipients email address
CLEAR T_RECEIVERS.
REFRESH T_RECEIVERS.
LOOP AT IT_RECV.
T_RECEIVERS-RECEIVER = IT_RECV-EMAIL.
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COM_TYPE = 'INT'.
T_RECEIVERS-COPY = 'X'.
T_RECEIVERS-NOTIF_DEL = 'X'.
T_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND T_RECEIVERS.
ENDLOOP.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOC_DATA
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = LD_SENDER_ADDRESS
SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = W_SENT_ALL
TABLES
PACKING_LIST = T_PACKING_LIST
CONTENTS_BIN = T_ATTACHMENT
CONTENTS_TXT = IT_MESSAGE
RECEIVERS = T_RECEIVERS
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.
Populate zerror return code
LD_ERROR = SY-SUBRC.
Populate zreceiver return code
LOOP AT T_RECEIVERS.
LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
ENDLOOP.
ENDFORM. "SEND_FILE_AS_EMAIL_ATTACHMENT
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
text
--> p1 text
<-- p2 text
FORM INITIATE_MAIL_EXECUTE_PROGRAM .
WAIT UP TO 2 SECONDS.
SUBMIT RSCONN01 WITH MODE = 'INT'
WITH OUTPUT = ''
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
Regards
Subramanian -
Sending EMAIL from ABAP Program Configuration+Code(Step by step)
Dear All,
Please anybody can provide me Step by Step document for sending Email from ABAP Program.
Thanks,
RPNot an appropriate forum. Try ABAP forum.
Regards,
Jai Shankar -
Sending email to internet from ABAP
I am trying to send email to external email address thru the standard approach using the function module SO_NEW_DOCUMENT_SEND_API1.
The function module and the abap programs run successfully without errors but still I am not receiving any email on my outlook. I guess there might be some issue with the SAP settings, can anyone help what are all those settings I need to make sure so that an email is sent out from SAP?Hi Sunil,
Has your BASIS configured the mail server (transaction SCOT)?
Please check this links for SCOT setup.
http://www.sap-img.com/basis/basis-faq.htm
http://www.sapgenie.com/interfaces/sapconnect.htm
Also could you please cut and paste your codes perhaps they are something missing.
Regards,
Ferry Lianto
Maybe you are looking for
-
Best Method for setting up a time-defined logout function.
Greetings, I'm attempting to setup an application that is only valid between certain hours of the day. I'm able to setup a test to verify that I'm within that time frame, but I'm not sure exactly where to put this pl/sql procedure to check to see if
-
I have created a database as 'system' and try to give access for other users. I created a new user with 'create user identified by passwd' and made 'grant connect to user' and 'grant select, insert, update to table'. But after that the new user can't
-
DropDown in Table using WD ABAP
Hi Gurus, I am trying to populate dynamic values in a dropdown. This dropdown is in a table on the form. My context design is: DataSource ( cardinality 1..1) --> TableNode ( cardinality 0..n) --> Drop_Down ( cardinality 1..n)
-
Downloading photos from Nano--help
I recently lost a laptop and camera that had family photos. The only device where I had these particular photos downloaded was my ipod Nano. Is there anyway to move these photos from the nano to my macbook? Is there a syncing issue?
-
Apple TV adds content on it's own
I just hooked up Apple TV for the first time, and I'm syncing content. After I synced for the first time, I noticed that there were several files that had been synced that I didn't select. Any idea why my Apple TV took it upon itself to add its own c