2008 Jun 19 5:50 AM
I am sending external e-mail using the function module
SO_NEW_document_send_api1 .
it is working fine.
but the require ment is i have to send an attachement along with e-mail content
How to send attachement in the e-mail ?
Please put you valuable suggestions .
Points wil l be awarded for the useful answers
Thanks
2008 Jun 19 5:56 AM
Hi,
Please do the minor changes and paste it in your program.
DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des .
* ld_receiver LIKE sy-subrc.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c, "#EC NEEDED
w_doc_data LIKE sodocchgi1.
REFRESH it_receivers . CLEAR it_receivers .
IF v_trip_send = 'X'.
it_receivers-receiver = it_trip_dload-approver_email .
ELSE .
it_receivers-receiver = it_adv_dload-approver_email .
ENDIF.
it_receivers-rec_type = c_u .
APPEND it_receivers. CLEAR it_receivers.
* it_receivers-receiver = " Pass your Email Id where you want to send the mail.
IF v_trip_send = 'X' .
it_receivers-receiver = it_trip_dload-requester_email .
ELSE .
it_receivers-receiver = it_adv_dload-requester_email .
ENDIF .
it_receivers-rec_type = c_u .
it_receivers-copy = 'X' .
APPEND it_receivers. CLEAR it_receivers.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
* 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 = c_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 = c_saprpt.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = c_f.
CLEAR it_attachment.
REFRESH it_attachment.
it_attachment[] = it_attach[].
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = c_raw.
APPEND it_packing_list.
* Create attachment notification
it_packing_list-transf_bin = c_x.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = ld_format.
it_packing_list-obj_descr = ld_attdescription.
it_packing_list-obj_name = ld_attfilename.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = c_x
commit_work = c_x
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers.
&********** Reward point if helpful**************&
2008 Jun 19 5:54 AM
hi,
Use the packing_list parameter to send the attachment:
Create Message Attachment
Write Packing List (Attachment)
DESCRIBE TABLE lt_objbin LINES l_tab_lines.
CLEAR lt_objbin.
READ TABLE lt_objbin INDEX l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'CSV'.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'Detail List'.
APPEND lt_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
commit_work = 'X'
put_in_outbox = ''
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_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.
Regards,
Subramanian
2008 Jun 19 5:55 AM
dear friend,
this code msut help u out form this
problem.
pls rewards are help full, and expected.
vivek
+++++++++++++++++++++++++++++++++++++++++
*--Data declearation
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
DATA: L_MSG(100) TYPE C.
Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'Z2318S1B01'.
DOC_CHNG-OBJ_DESCR = EMSUBJ .
- Begin of update By NDASARI 05/17/2007 -
*OBJTXT = 'your report from apple vacations is enclosed as
ATTACHMENT'.
OBJTXT = 'your report from apple vacations is enclosed as ATTACHMENT'.
- End of update By NDASARI 05/17/2007 -
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.
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
LOOP AT IT_ATTACHMENT.
OBJBIN = IT_ATTACHMENT-EMAIL.
APPEND OBJBIN.
CLEAR OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Airport Mainfest'.
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 = 'RAW'.
OBJPACK-OBJ_NAME = 'ANLAGE'.
OBJPACK-OBJ_DESCR = 'Representation of object 138'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
CLEAR EMAILID.
LOOP AT EMAILID.
TRANSLATE EMAILID-LOW TO LOWER CASE.
RECLIST-RECEIVER = EMAILID-LOW.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
CLEAR RECLIST.
ENDLOOP.
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
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
IF SY-SUBRC = 0.
LOOP AT RECLIST.
IF RECLIST-RETRN_CODE = 0.
CONCATENATE RECLIST-RECEIVER ':'
'The document was sent' INTO L_MSG.
MESSAGE S656 WITH L_MSG.
ELSE.
CONCATENATE RECLIST-RECEIVER ':'
'The document was sent' INTO L_MSG.
MESSAGE E656 WITH L_MSG.
ENDIF.
ENDLOOP.
ELSE.
CONCATENATE RECLIST-RECEIVER ':'
'error occurred in sending mail' INTO L_MSG.
MESSAGE S656 WITH L_MSG.
ENDIF.
2008 Jun 19 5:56 AM
Hi,
Please do the minor changes and paste it in your program.
DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des .
* ld_receiver LIKE sy-subrc.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c, "#EC NEEDED
w_doc_data LIKE sodocchgi1.
REFRESH it_receivers . CLEAR it_receivers .
IF v_trip_send = 'X'.
it_receivers-receiver = it_trip_dload-approver_email .
ELSE .
it_receivers-receiver = it_adv_dload-approver_email .
ENDIF.
it_receivers-rec_type = c_u .
APPEND it_receivers. CLEAR it_receivers.
* it_receivers-receiver = " Pass your Email Id where you want to send the mail.
IF v_trip_send = 'X' .
it_receivers-receiver = it_trip_dload-requester_email .
ELSE .
it_receivers-receiver = it_adv_dload-requester_email .
ENDIF .
it_receivers-rec_type = c_u .
it_receivers-copy = 'X' .
APPEND it_receivers. CLEAR it_receivers.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
* 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 = c_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 = c_saprpt.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = c_f.
CLEAR it_attachment.
REFRESH it_attachment.
it_attachment[] = it_attach[].
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = c_raw.
APPEND it_packing_list.
* Create attachment notification
it_packing_list-transf_bin = c_x.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = ld_format.
it_packing_list-obj_descr = ld_attdescription.
it_packing_list-obj_name = ld_attfilename.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = c_x
commit_work = c_x
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers.
&********** Reward point if helpful**************&
2008 Jun 19 5:56 AM
Hi
Hope it will help you,.
Reward if help.
&----
*& Report ZEMAIL_ATTACH *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT ZEMAIL_ATTACH .
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver.
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
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.
************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
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
'Example .xls documnet attachment'
'XLS'
'filename'
' '
' '
' '
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
&----
*& Form BUILD_XLS_DATA_TABLE
&----
Build data table for .xls document
----
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*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.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
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 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.
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
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 = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
2008 Jun 19 5:58 AM
dear friend
one more example is there.
is is with our the use of FM that u have explain.
this is running code.
pls go through it if
helpfull
pls rewards..
if any problem .....pls keep in touch.
vivek
&----
*& Report YMM_SEND_EMAIL *
&----
Program : YMM_SEND_EMAIL *
Creation Date : 29-MAR-2008 *
Program Title : Send Material to user Email *
Program Author : T.KrishnaChaitanya *
Program Type : Report *
Transaction : YMAMAIL *
----
Version : 1.0 *
Object development-Id : Sildev01 *
----
Modification ID : N/A *
Date : DD-MMM-YYYY *
Author : N/A *
Description : N/A *
----
Please maintain following details in ZCODEMAIL *
PGMTYPE as FIELD Maintain CODE with CENVAT DBKDEPB CHAPTERID etc *
Respective User and his Email *
----
REPORT ymm_send_email NO STANDARD PAGE HEADING MESSAGE-ID ymess.
TABLES : mara,j_1imtchid,j_1imoddet,t001w.
TYPE-POOLS : slis.
*-> Tables
*-> Material Master
TYPES : BEGIN OF t_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
lvorm TYPE mara-lvorm, " Deletion Flag
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
werks TYPE marc-werks,
maktx TYPE makt-maktx,
END OF t_mara,
*-> Chapter ID
BEGIN OF t_chid,
matnr TYPE j_1imtchid-matnr,
werks TYPE j_1imtchid-werks,
j_1ichid TYPE j_1imtchid-j_1ichid,
END OF t_chid,
*-> Material & Sales Organisation
BEGIN OF t_mvke,
matnr TYPE mvke-matnr,
vkorg TYPE mvke-vkorg,
vtweg TYPE mvke-vtweg,
lvorm TYPE mvke-lvorm,
END OF t_mvke.
*-> Internal Tables
DATA : i_chid TYPE TABLE OF t_chid,
i_mara TYPE TABLE OF t_mara,
i_mvke TYPE TABLE OF t_mvke,
i_zdbksr TYPE TABLE OF zdbksr,
i_zdepbsr TYPE TABLE OF zdepbsr,
i_code TYPE TABLE OF zcodemail WITH HEADER LINE,
i_moddet TYPE TABLE OF j_1imoddet,
*-> Email Id
p_mtitle TYPE string,
p_report TYPE string,
i_remail LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
*-> Work Area
w_moddet TYPE j_1imoddet,
w_chid TYPE t_chid,
w_mara TYPE t_mara,
w_zdbksr TYPE zdbksr,
w_zdepbsr TYPE zdepbsr,
w_mvke TYPE t_mvke,
*-> Variables
v_flag1,
v_flag2,
v_error,
v_maktx TYPE makt-maktx,
v_lines TYPE i.
*-> Constants
CONSTANTS : c_bb TYPE t001w-werks VALUE '1120',
c_pp TYPE t001w-werks VALUE '1130',
c_br1 TYPE t001w-werks VALUE '1110',
c_br2 TYPE t001w-werks VALUE '1111',
c_so1 TYPE t001w-werks VALUE '1100',
c_so2 TYPE t001w-werks VALUE '1101',
c_i VALUE 'I',
c_e VALUE 'E',
c_eq(2) VALUE 'EQ'.
*-> Final IT
DATA : BEGIN OF i_final OCCURS 0,
matnr LIKE mara-matnr,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
werks LIKE marc-werks,
maktx LIKE makt-maktx,
END OF i_final,
i_chfinal LIKE i_final OCCURS 0 WITH HEADER LINE,
i_cefinal LIKE i_final OCCURS 0 WITH HEADER LINE,
i_dbkdepb LIKE i_final OCCURS 0 WITH HEADER LINE,
*-> FOR ALV
v_repid TYPE sy-repid,
i_fcat TYPE TABLE OF slis_fieldcat_alv,
w_fcat LIKE LINE OF i_fcat.
*-> Selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-011.
PARAMETER date TYPE sy-datum.
PARAMETER datum TYPE sy-datum NO-DISPLAY.
SELECT-OPTIONS : werks FOR t001w-werks,
mtart FOR mara-mtart NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN OUTPUT.
MOVE sy-datum TO date.
MOVE '20080401' TO datum.
START-OF-SELECTION.
*-> In selection if werks is initial then Append all plant.
IF werks[] IS INITIAL.
PERFORM append_plant.
ENDIF.
PERFORM append_mtart.
*-> Select all material Master Details.
PERFORM select_data.
*-> Process
PERFORM process_data.
&----
*& Form select_data
&----
FORM select_data .
*-> Material Master
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read Material Master'.
SELECT mara~matnr
mara~ersda
mara~ernam
mara~lvorm
mara~mtart
mara~matkl
marc~werks
makt~maktx
INTO TABLE i_mara
FROM mara
JOIN marc
ON marcmatnr = maramatnr
JOIN makt
ON maktmatnr = maramatnr
WHERE mara~matnr NOT IN mtart
AND mara~ersda GE datum
AND mara~lvorm EQ space
AND marc~werks IN werks.
IF sy-subrc <> 0.
MESSAGE a000.
ELSE.
SORT i_mara BY werks mtart matnr.
DELETE i_mara WHERE mtart IN mtart.
*-> Chapter ID
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read Chapter ID Master'.
SELECT matnr
werks
j_1ichid
FROM j_1imtchid
INTO TABLE i_chid
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND werks = i_mara-werks.
*-> Cenvat Details
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read Cenvat Master'.
SELECT *
FROM j_1imoddet
INTO TABLE i_moddet
WHERE werks IN werks.
*-> Sales Organisation
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read Sales Organisation Details'.
SELECT matnr
vkorg
vtweg
lvorm
FROM mvke
INTO TABLE i_mvke
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND lvorm EQ space.
*-> DBK Master
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read DBK Master'.
SELECT *
FROM zdbksr
INTO TABLE i_zdbksr
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND validfr LE date.
*-> DEPB Master
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Read DEPB Master'.
SELECT *
FROM zdepbsr
INTO TABLE i_zdepbsr
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND validfr LE date.
ENDIF.
ENDFORM. " select_data
&----
*& Form process_data
&----
FORM process_data .
*-> field catalog
----
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'I_FINAL'
i_inclname = v_repid
CHANGING
ct_fieldcat = i_fcat[].
----
break sildev01.
*-> Get all the data into internal tables.
----
SORT i_mara BY werks mtart matnr.
LOOP AT werks.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Prepare List To Send Email'.
LOOP AT i_mara INTO w_mara WHERE werks = werks-low.
*-> for baramati plants.
IF werks-low = c_br1 OR werks-low = c_br2.
IF mtart EQ 'HALB'.
PERFORM chapterid.
PERFORM cenvat.
ENDIF.
READ TABLE i_mvke INTO w_mvke WITH KEY matnr = w_mara-matnr
BINARY SEARCH.
IF w_mvke-vkorg EQ 5000.
PERFORM dbkdepb.
ENDIF.
ENDIF.
*-> for solapur plants.
IF werks-low = c_so1 OR werks-low = c_so2.
IF mtart EQ 'HALB'.
PERFORM chapterid.
PERFORM cenvat.
ENDIF.
READ TABLE i_mvke INTO w_mvke WITH KEY matnr = w_mara-matnr
BINARY SEARCH.
IF w_mvke-vkorg EQ 5000.
PERFORM dbkdepb.
ENDIF.
ENDIF.
*-> For butibori & pithampur plants.
IF werks-low = c_pp OR werks-low = c_bb.
PERFORM chapterid. " check chapter id
PERFORM cenvat. " check cenvat.
READ TABLE i_mvke INTO w_mvke WITH KEY matnr = w_mara-matnr
BINARY SEARCH.
IF w_mvke-vkorg EQ 5000.
PERFORM dbkdepb. " check DBK depb only for export material.
ENDIF.
ENDIF.
ENDLOOP.
----
*-> Send email *
----
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Sending Email'.
SELECT *
FROM zcodemail
INTO TABLE i_code
WHERE pgmtype = 'FIELD'
AND werks = werks-low.
PERFORM chapterid_email.
WAIT UP TO 3 SECONDS.
PERFORM cenvat_email.
WAIT UP TO 3 SECONDS.
PERFORM dbkdepb_email.
----
REFRESH : i_code[].
CLEAR : i_code.
ENDLOOP.
ENDFORM. " process_data
&----
*& Form append_plant
&----
FORM append_plant .
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_bb.
APPEND werks.
CLEAR werks.
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_pp.
APPEND werks.
CLEAR werks.
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_br1.
APPEND werks.
CLEAR werks.
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_br2.
APPEND werks.
CLEAR werks.
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_so1.
APPEND werks.
CLEAR werks.
werks-sign = c_i.
werks-option = c_eq.
werks-low = c_so2.
APPEND werks.
CLEAR werks.
SORT werks.
ENDFORM. " append_plant
&----
*& Form append_mtart
&----
FORM append_mtart .
mtart-sign = c_i.
mtart-option = c_eq.
mtart-low = 'ZCAP'.
APPEND mtart.
CLEAR mtart.
mtart-sign = c_i.
mtart-option = c_eq.
mtart-low = 'ZCPI'.
APPEND mtart.
CLEAR mtart.
mtart-sign = c_i.
mtart-option = c_eq.
mtart-low = 'DIEN'.
APPEND mtart.
CLEAR mtart.
mtart-sign = c_i.
mtart-option = c_eq.
mtart-low = 'UNBW'.
APPEND mtart.
CLEAR mtart.
ENDFORM. " append_mtart
&----
*& Form chapterid
&----
FORM chapterid .
READ TABLE i_chid INTO w_chid WITH KEY matnr = w_mara-matnr
werks = w_mara-werks
BINARY SEARCH.
IF sy-subrc <> 0 OR w_chid-j_1ichid IS INITIAL.
MOVE-CORRESPONDING w_mara TO i_chfinal.
COLLECT i_chfinal.
CLEAR : i_chfinal,w_chid.
ENDIF.
ENDFORM. " chapterid
&----
*& Form cenvat
&----
FORM cenvat .
READ TABLE i_moddet INTO w_moddet WITH KEY werks = w_mara-werks
j_1imoim = w_mara-matnr
BINARY SEARCH.
IF sy-subrc <> 0.
v_flag1 = 1.
ENDIF.
READ TABLE i_moddet INTO w_moddet WITH KEY werks = w_mara-werks
j_1imoom = w_mara-matnr
BINARY SEARCH.
IF sy-subrc <> 0.
v_flag2 = 1.
ENDIF.
IF v_flag1 = 1 AND v_flag2 = 1.
MOVE-CORRESPONDING w_mara TO i_cefinal.
COLLECT i_cefinal.
CLEAR : i_cefinal,v_flag1,v_flag2,w_moddet.
ENDIF.
ENDFORM. " cenvat
&----
*& Form dbkdepb
&----
FORM dbkdepb .
IF w_mara-mtart = 'HALB' OR w_mara-mtart = 'ABF'.
*-> dbk details
READ TABLE i_zdbksr INTO w_zdbksr WITH KEY matnr = w_mara-matnr
BINARY SEARCH.
IF sy-subrc IS NOT INITIAL OR w_zdbksr-zdbrate IS INITIAL.
v_flag1 = 1.
ENDIF.
*-> DEPB Details
READ TABLE i_zdepbsr INTO w_zdepbsr WITH KEY matnr = w_mara-matnr
BINARY SEARCH.
IF sy-subrc IS NOT INITIAL.
v_flag2 = 1.
ENDIF.
IF v_flag1 = 1 AND v_flag2 = 1.
MOVE-CORRESPONDING w_mara TO i_dbkdepb.
COLLECT i_dbkdepb.
CLEAR : i_dbkdepb,v_flag1,v_flag2,w_mvke,w_zdbksr,w_zdepbsr.
ENDIF.
ENDIF.
ENDFORM. " dbkdepb
&----
*& Form chapterid_email
&----
FORM chapterid_email .
IF i_chfinal[] IS NOT INITIAL.
p_mtitle = 'List of materials with out Chapter ID'.
p_report = p_mtitle.
LOOP AT i_code WHERE code = 'CHAPTERID'.
i_remail-receiver = i_code-smtp_addr.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDLOOP.
IF i_remail[] IS INITIAL.
i_remail-receiver = 'emailaddress'.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDIF.
CALL FUNCTION 'ZALVMAIL'
EXPORTING
p_mtitle = p_mtitle
p_report = p_report
TABLES
i_remail = i_remail[]
i_final = i_chfinal[]
fcat = i_fcat[].
CLEAR : p_mtitle,p_report.
REFRESH : i_chfinal[],i_remail[].
ENDIF.
ENDFORM. " chapterid_email
&----
*& Form cenvat_email
&----
text
----
FORM cenvat_email .
IF i_cefinal[] IS NOT INITIAL.
p_mtitle = 'List of materials with out Cenvat'.
p_report = p_mtitle.
LOOP AT i_code WHERE code = 'CENVAT'.
i_remail-receiver = i_code-smtp_addr.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDLOOP.
IF i_remail[] IS INITIAL.
i_remail-receiver = emailaddress'.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDIF.
CALL FUNCTION 'ZALVMAIL'
EXPORTING
p_mtitle = p_mtitle
p_report = p_report
TABLES
i_remail = i_remail[]
i_final = i_cefinal[]
fcat = i_fcat[].
CLEAR : p_mtitle,p_report.
REFRESH : i_cefinal[],i_remail[].
ENDIF.
ENDFORM. " cenvat_email
&----
*& Form dbkdepb_email
&----
FORM dbkdepb_email .
IF i_dbkdepb[] IS NOT INITIAL.
p_mtitle = 'List of materials with out DBK DEPB'.
p_report = p_mtitle.
LOOP AT i_code WHERE code = 'DBKDEPB'.
i_remail-receiver = i_code-smtp_addr.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDLOOP.
IF i_remail[] IS INITIAL.
i_remail-receiver = 'emailaddress'.
i_remail-rec_type = 'U'.
i_remail-notif_del = 'X'.
i_remail-notif_ndel = 'X'.
APPEND i_remail.
CLEAR i_remail.
ENDIF.
CALL FUNCTION 'ZALVMAIL'
EXPORTING
p_mtitle = p_mtitle
p_report = p_report
TABLES
i_remail = i_remail[]
i_final = i_dbkdepb[]
fcat = i_fcat[].
CLEAR : p_mtitle,p_report.
REFRESH : i_dbkdepb[],i_remail[].
ENDIF.
ENDFORM. " dbkdepb_email
2008 Jun 19 6:01 AM
Hi,
check this example program.
if u have any doubt pls revert it back
DATA: formname TYPE tdsfname,
fm_name TYPE rs38l_fnam,
control_parameters TYPE ssfctrlop,
output_options TYPE ssfcompop,
job_output_info TYPE ssfcrescl,
otf_data TYPE tsfotf.
DATA: otf TYPE TABLE OF itcoo WITH HEADER LINE,
doctab_archive TYPE TABLE OF docs WITH HEADER LINE,
lines TYPE TABLE OF tline WITH HEADER LINE,
bin_filesize TYPE i.
*&---------------------------------------------------------------------*
*& Form mail_users
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LINES text
* -->P_2153 text
* -->P_V_HEADER text
*----------------------------------------------------------------------*
FORM mail_users TABLES p_lines STRUCTURE tline
USING p_dist_list
p_v_header.
CONSTANTS: c_raw TYPE so_obj_tp VALUE 'RAW',
c_pdf TYPE so_obj_tp VALUE 'PDF',
c_255 TYPE i VALUE 255,
c_134 TYPE i VALUE 134,
c_x TYPE c VALUE 'X'.
DATA: document_data LIKE sodocchgi1 ,
tab_lines TYPE i,
contents_txt TYPE TABLE OF solisti1 WITH HEADER LINE,
contents_bin TYPE TABLE OF solisti1 WITH HEADER LINE,
packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
object_header TYPE TABLE OF solisti1 WITH HEADER LINE,
receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
l_str(255) ,
v1 TYPE i,
v2 TYPE i,
v3 TYPE i.
document_data-obj_name = 'EMAIL'.
document_data-obj_descr = p_v_header. " SUBJECT LINE
*CONCATENATE 'Please find the attached SAP generated Daily Production Report for the day'
' : '
p_repdt+6(2)
'.'
p_repdt+4(2)
'.' p_repdt+0(4)
INTO contents_txt.
APPEND contents_txt.* " Content of the mail
CLEAR contents_txt.
APPEND contents_txt.
APPEND contents_txt.
DESCRIBE TABLE contents_txt LINES tab_lines.
READ TABLE contents_txt INDEX tab_lines.
document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( contents_txt ).
document_data-doc_size = tab_lines .
CLEAR packing_list-transf_bin.
packing_list-head_start = 1.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = tab_lines.
packing_list-doc_type = c_raw.
packing_list-doc_size = document_data-doc_size.
APPEND packing_list.
LOOP AT p_lines.
CLEAR l_str.
l_str+0(2) = p_lines-tdformat.
l_str+2(132) = p_lines-tdline.
v2 = v1 + c_134.
IF v2 LE c_255.
contents_bin-line+v1(c_134) = l_str. v1 = v2.
ELSE.
v3 = v2 - c_255.
v2 = c_255 - v1.
IF NOT v2 IS INITIAL.
contents_bin-line+v1(v2) = l_str+0(v2).
ENDIF.
APPEND contents_bin.
CLEAR contents_bin.
v1 = v3.
v3 = 134 - v1.
IF NOT v1 IS INITIAL.
contents_bin-line+0(v1) = l_str+v3(v1).
ENDIF.
ENDIF.
ENDLOOP.
APPEND contents_bin.
CLEAR contents_bin.
DESCRIBE TABLE contents_bin LINES tab_lines.
READ TABLE contents_bin INDEX tab_lines.
CONCATENATE 'Hy-I Report'
'-'
p_repdt+6(2)
'.'
p_repdt+4(2)
'.' p_repdt+0(4)
'.pdf'
INTO object_header.
APPEND object_header.
packing_list-transf_bin = c_x.
packing_list-head_start = 1.
packing_list-head_num = 1.
packing_list-body_start = 1.
packing_list-body_num = tab_lines.
packing_list-doc_type = c_pdf.
packing_list-obj_name = 'text1'.
packing_list-obj_descr = 'Production report'.
packing_list-doc_size = tab_lines * 255 + STRLEN( contents_bin ).
APPEND packing_list.
receivers-receiver = p_dist_list.
receivers-rec_type = 'C'.
APPEND receivers.
CLEAR receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
put_in_outbox = ' '
SENDER_ADDRESS = 'CZPPPLG'
SENDER_ADDRESS_TYPE = 'B'
commit_work = 'X'
TABLES
packing_list = packing_list
object_header = object_header
contents_bin = contents_bin
contents_txt = contents_txt
receivers = 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.
IF sy-subrc = 0.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 with mode = 'INT' AND RETURN.
ENDIF.
ENDFORM. " mail_users
Thanks
Murugan.B
2008 Jun 19 6:47 AM
Hi abapers,
All are explained thru SO_document_send_api1.
Cant we use so_new_document sendapi1 for this.
I already coded using this, only attachement has to be included in that. let me go thru the code and i ll try to implement it using the FM given.
thanks for your answers, ll reward you once i implemented it