2013 Jun 17 5:31 AM
Dear Gurus,
I have a requirement that to send an document in email, which is in system like D drive contains lot of pdf documents. I know the path and file name which I want to send. I also know a module function 'GUI_UPLOAD' to get file into internal table but How to get convert this into type of SOLISTI1 so I could send it using the module function of 'SO_NEW_DOCUMENT_ATT_SEND_APTI'.
If you have any other scenario then kindly update me ...
Many Thanks / Himanshu Gupta
2013 Jun 17 6:25 AM
Hi Himanshu Gupta,
Try this code your problem will sloved.
data : wa_doc_data like SODOCCHGI1,
v_lin like Sy-tabix,
v_obj_id like SOFOLENTI1-OBJECT_ID.
data : wa_reciever like SOMLRECI1,
t_reciever like standard table of wa_reciever.
data : wa_pk_list like SOPCKLSTI1,
t_pk_list like standard table of wa_pk_list.
data : wa_con_txt like SOLISTI1,
t_TEMP like standard table of wa_con_txt,
t_con_txt like standard table of wa_con_txt.
wa_con_txt = 'Hello Mail Body'.
append wa_con_txt to t_con_txt.
describe table t_con_txt lines v_lin.
read table t_con_txt index v_lin into wa_con_txt.
wa_doc_data-doc_size = ( v_lin - 1 ) * 255 + strlen( wa_con_txt ).
wa_doc_data-OBJ_NAME = 'ATC'.
wa_doc_data-OBJ_DESCR = 'Send PDF as Attachment'.
wa_doc_data-OBJ_LANGU = 'E'.
wa_reciever-RECEIVER = '[email protected]'.
wa_reciever-REC_TYPE = 'U'.
wa_reciever-com_type = 'INT'.
append wa_reciever to t_reciever.
clear wa_pk_list-transf_bin.
wa_pk_list-head_start = 1.
wa_pk_list-head_num = 0.
wa_pk_list-BODY_START = 1.
wa_pk_list-body_num = v_lin.
wa_pk_list-doc_type = 'RAW'.
append wa_pk_list to t_pk_list.
*to upload a pdf file*
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'E:\file.pdf'
FILETYPE = 'BIN'
TABLES
DATA_TAB = T_TEMP
.
DESCRIBE TABLE T_TEMP LINES V_LIN.
WA_PK_LIST-TRANSF_BIN = 'X'.
WA_PK_LIST-HEAD_NUM = 0.
WA_PK_LIST-BODY_START = 1.
WA_PK_LIST-BODY_NUM = V_LIN.
WA_PK_LIST-DOC_TYPE = 'PDF'.
WA_PK_LIST-OBJ_NAME = 'ATTACHMENT'.
WA_PK_LIST-OBJ_DESCR = 'Reproduction object 138'.
WA_PK_LIST-DOC_SIZE = V_LIN * 255.
APPEND WA_PK_LIST TO T_PK_LIST..
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = wa_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
PACKING_LIST = t_pk_list
CONTENTS_BIN = T_TEMP
CONTENTS_TXT = t_con_txt
RECEIVERS = t_reciever
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.
else.
message 'Mail Sended Successfully'(008) type 'I'.
endif.
Regards,
Ramesh.T
Dear Gurus,
I have a requirement that to send an document in email, which is in system like D drive contains lot of pdf documents. I know the path and file name which I want to send. I also know a module function 'GUI_UPLOAD' to get file into internal table but How to get convert this into type of SOLISTI1 so I could send it using the module function of 'SO_NEW_DOCUMENT_ATT_SEND_APTI'.
If you have any other scenario then kindly update me ...
Many Thanks / Himanshu Gupta
2013 Jun 17 5:46 AM
Hi Himanshu,
Have not worked on it but found a couple of seemingly useful links for you -
http://www.sapdev.co.uk/reporting/email/attach_xls.htm
BR.
2013 Jun 17 5:46 AM
Hi,
Why don't you try CL_DOCUMENT_BCS method ADD_ATTACHMENT. Its easy.
Cheers,
Arindam
2013 Jun 17 6:01 AM
Hii Arindam,
I didn't try this class now I try it then let you update.
Many Thanks / Himanshu Gupta
2013 Jun 17 6:07 AM
Hi,
Just to get you started. Check the link below:
http://wiki.sdn.sap.com/wiki/display/Snippets/Sending++attachment+using+cl_bcs+classes
Cheers,
Arindam
2013 Jun 17 6:18 AM
HI Gupta,
For mail attaching you can use function module "SO_NEW_DOCUMENT_ATT_SEND_APTI".
please look into bellow code, it's suitable for your requirement.
Types: t_receivers TYPE somlreci1,
t_pdf TYPE tline.
DATA :
g_sent_to_all TYPE sonv-flag,
DATA :
w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
DATA :
i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf
content_out = i_attachment
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'B'. "Internet address
w_receivers-receiver = sy-uname.
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
.
"Function module to send mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_body_msg
receivers = i_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 .
* MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
ENDIF.
* ENDIF.
2013 Jun 17 6:06 AM
Refer below programs,
BCS_EXAMPLE_5,
Hope its useful,
Manjunath M
2013 Jun 17 6:10 AM
Hey here is standard program which meets your requirement,
BCS_EXAMPLE_6
Regards,
Manjunath M
2013 Jun 17 6:25 AM
Hi Himanshu Gupta,
Try this code your problem will sloved.
data : wa_doc_data like SODOCCHGI1,
v_lin like Sy-tabix,
v_obj_id like SOFOLENTI1-OBJECT_ID.
data : wa_reciever like SOMLRECI1,
t_reciever like standard table of wa_reciever.
data : wa_pk_list like SOPCKLSTI1,
t_pk_list like standard table of wa_pk_list.
data : wa_con_txt like SOLISTI1,
t_TEMP like standard table of wa_con_txt,
t_con_txt like standard table of wa_con_txt.
wa_con_txt = 'Hello Mail Body'.
append wa_con_txt to t_con_txt.
describe table t_con_txt lines v_lin.
read table t_con_txt index v_lin into wa_con_txt.
wa_doc_data-doc_size = ( v_lin - 1 ) * 255 + strlen( wa_con_txt ).
wa_doc_data-OBJ_NAME = 'ATC'.
wa_doc_data-OBJ_DESCR = 'Send PDF as Attachment'.
wa_doc_data-OBJ_LANGU = 'E'.
wa_reciever-RECEIVER = '[email protected]'.
wa_reciever-REC_TYPE = 'U'.
wa_reciever-com_type = 'INT'.
append wa_reciever to t_reciever.
clear wa_pk_list-transf_bin.
wa_pk_list-head_start = 1.
wa_pk_list-head_num = 0.
wa_pk_list-BODY_START = 1.
wa_pk_list-body_num = v_lin.
wa_pk_list-doc_type = 'RAW'.
append wa_pk_list to t_pk_list.
*to upload a pdf file*
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'E:\file.pdf'
FILETYPE = 'BIN'
TABLES
DATA_TAB = T_TEMP
.
DESCRIBE TABLE T_TEMP LINES V_LIN.
WA_PK_LIST-TRANSF_BIN = 'X'.
WA_PK_LIST-HEAD_NUM = 0.
WA_PK_LIST-BODY_START = 1.
WA_PK_LIST-BODY_NUM = V_LIN.
WA_PK_LIST-DOC_TYPE = 'PDF'.
WA_PK_LIST-OBJ_NAME = 'ATTACHMENT'.
WA_PK_LIST-OBJ_DESCR = 'Reproduction object 138'.
WA_PK_LIST-DOC_SIZE = V_LIN * 255.
APPEND WA_PK_LIST TO T_PK_LIST..
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = wa_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
PACKING_LIST = t_pk_list
CONTENTS_BIN = T_TEMP
CONTENTS_TXT = t_con_txt
RECEIVERS = t_reciever
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.
else.
message 'Mail Sended Successfully'(008) type 'I'.
endif.
Regards,
Ramesh.T
2013 Jun 17 7:26 AM
HI,
Have you got answer, if yes please close this thread by marking as correct answer.
Regards,
Ramesh.T
2013 Jun 17 7:45 AM
Dear Ramesh,
Thanks for your reply and my issue has solved. Actually, I was doing correct but one thing I did incorrect is I was using file type as RAW in function module of 'GUI_UPLOAD' instead of 'BIN'.
Many Thanks / Himanshu Gupta
2013 Jun 17 8:02 AM
Dear Ramesh,
Thanks for your reply and my issue has solved. Actually, I was doing correct but one thing I did incorrect is I was using file type as RAW in function module of 'GUI_UPLOAD' instead of 'BIN'.
Many Thanks / Himanshu Gupta
2013 Jun 17 8:08 AM
Hi Ramesh
Thank for the information.
This email attachment GUI_UPLOAD - Will it work in background?
Suppose, I have a background program that picksup file from the shared location and send mail...
Regards,
Venkat
2013 Jun 17 8:18 AM
Hi Venkateswaran,
I paste the code please follow it to pickup file from shared location or any location..
TABLES: rlgrap.
DATA:BEGIN OF it_excel OCCURS 0.
INCLUDE TYPE alsmex_tabline.
DATA:END OF it_excel.
* DATA:
DATA: BEGIN OF itab OCCURS 0,
panno(10) TYPE c,
END OF itab.
DATA : wtab LIKE LINE OF itab .
DATA : txt TYPE string.
DATA : it_tab1 TYPE filetable .
DATA : wtab1 TYPE file_table .
DATA: result TYPE char1,
v_count TYPE i,
gd_subrc TYPE i,
v_string TYPE string.
****************using function modules*************************
DATA : ltb_objtxt TYPE solisti1 OCCURS 10 WITH HEADER LINE,
lwa_doc_chng TYPE sodocchgi1,
lw_tab_lines TYPE sy-tabix,
lwa_recipients TYPE somlreci1,
v_lines_bin TYPE i,
ltb_recipients TYPE TABLE OF somlreci1,
wa_pk_list like SOPCKLSTI1,
ltb_objpack TYPE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA : BEGIN OF ltb_objbin OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA : END OF ltb_objbin.
data : wmail like solisti1,
tmail like standard table of wmail,
t_con_txt like standard table of wmail.
*DATA : BEGIN OF tmail OCCURS 0.
* INCLUDE STRUCTURE solix.
*DATA : END OF tmail.
*DATA : tmail type solix_tab.
*data : tmail type solix occurs 0 .
*********end of using function module**************************
DATA : BEGIN OF it_main OCCURS 0,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
adrnr TYPE lfa1-adrnr,
smtp_addr TYPE adr6-smtp_addr,
END OF it_main.
DATA : ob_frnt TYPE REF TO cl_gui_frontend_services.
*
PARAMETERS: pfile1 TYPE rlgrap-filename OBLIGATORY.
PARAMETERS : pfile2 TYPE rlgrap-filename ,
brow TYPE i DEFAULT '1' OBLIGATORY,
erow TYPE i DEFAULT '1' OBLIGATORY,
p1 TYPE sy-datum,
p2 TYPE sy-datum.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfile2.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = pfile2
.
START-OF-SELECTION.
v_string = pfile1.
* Clear result variable
CLEAR result.
* Check if the folder name exists under the specified directory
* which you want to create
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = v_string
RECEIVING
result = result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF result NE 'X'.
MESSAGE 'TDS Folder does not exist' TYPE 'E'.
LEAVE SCREEN.
ENDIF.
CALL METHOD cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = v_string
filter = '*.pdf'
* files_only =
* directories_only =
CHANGING
file_table = it_tab1
count = v_count
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF pfile2 IS NOT INITIAL.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = pfile2
i_begin_col = '1'
i_begin_row = brow
i_end_col = '1'
i_end_row = erow
TABLES
intern = it_excel
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF it_excel[] IS INITIAL.
MESSAGE i398(00) WITH 'No data exists in the excel file' space space space.
LEAVE PROGRAM.
ELSE.
LOOP AT it_excel .
CASE it_excel-col.
WHEN '001'.
itab-panno = it_excel-value.
ENDCASE.
AT END OF row.
APPEND itab.
CLEAR itab.
ENDAT.
ENDLOOP.
ENDIF.
ENDIF.
IF itab[] IS NOT INITIAL.
LOOP AT itab.
REFRESH : it_main, it_main[].
CONDENSE itab-panno.
READ TABLE it_tab1 INTO wtab1 WITH KEY filename+0(10) = itab-panno.
IF sy-subrc EQ 0.
SELECT a~lifnr a~name1 b~addrnumber b~smtp_addr
INTO (it_main-lifnr, it_main-name1, it_main-adrnr, it_main-smtp_addr)
FROM lfa1 AS a INNER JOIN adr6 AS b
ON a~adrnr = b~addrnumber
WHERE a~stcd1 = itab-panno.
APPEND it_main.
CLEAR it_main.
ENDSELECT.
PERFORM automail USING wtab1.
ENDIF.
CLEAR itab.
ENDLOOP.
ENDIF.
FORM automail USING wtab1 TYPE file_table .
"Insert correct name for <...>.
* IF eml[] IS NOT INITIAL .
CLEAR: ltb_objbin, ltb_objtxt, ltb_objpack,
lwa_doc_chng.
REFRESH: ltb_objbin,ltb_objtxt, ltb_objpack.
* control data
lwa_doc_chng-obj_name = 'URGENT'.
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'P'.
lwa_doc_chng-obj_prio = '1'.
lwa_doc_chng-priority = '1'.
CONCATENATE 'TDS Form for the period from ' p1 'to' p2 INTO lwa_doc_chng-obj_descr SEPARATED BY space.
*** refresh it_message.
ltb_objtxt = 'Dear Sir/Madam,'.
APPEND ltb_objtxt.
ltb_objtxt = ' '.
APPEND ltb_objtxt.
READ TABLE it_main INDEX 1.
CONCATENATE 'Kindly please find your TDS certificate for the pan card number of' it_main-smtp_addr
INTO ltb_objtxt SEPARATED BY space.
APPEND ltb_objtxt.
ltb_objtxt = ' '.
APPEND ltb_objtxt.
ltb_objtxt = 'Thanks & Regards'.
APPEND ltb_objtxt.
ltb_objtxt = ' '.
APPEND ltb_objtxt.
ltb_objtxt = 'Accounts Department'.
APPEND ltb_objtxt.
****email packing
CLEAR ltb_objtxt.
DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE ltb_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( ltb_objtxt ).
CLEAR ltb_objpack-transf_bin.
ltb_objpack-body_start = 1.
ltb_objpack-head_start = 1.
ltb_objpack-head_num = 0.
ltb_objpack-body_num = lw_tab_lines.
ltb_objpack-doc_type = 'RAW'.
ltb_objpack-transf_bin = space.
APPEND ltb_objpack.
ENDIF.
SORT it_main BY smtp_addr ASCENDING.
DELETE ADJACENT DUPLICATES FROM it_main COMPARING smtp_addr.
LOOP AT it_main.
CONDENSE it_main-smtp_addr.
CLEAR lwa_recipients.
lwa_recipients-rec_type = 'U'.
* lwa_recipients-copy = 'X'.
lwa_recipients-receiver = it_main-smtp_addr.
APPEND lwa_recipients TO ltb_recipients.
CLEAR it_main.
ENDLOOP.
CLEAR : ltb_objbin,ltb_objbin[]. ",it_message,it_message[].
REFRESH : ltb_objbin,ltb_objbin[]. ",it_message,it_message[].
data : file type string.
concatenate pfile1 '\' wtab1-filename into file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file
FILETYPE = 'BIN'
tables
data_tab = ltb_objbin
.
DESCRIBE TABLE ltb_objbin LINES v_lines_bin.
WA_PK_LIST-TRANSF_BIN = 'X'.
WA_PK_LIST-HEAD_NUM = 0.
WA_PK_LIST-BODY_START = 1.
WA_PK_LIST-BODY_NUM = v_lines_bin.
WA_PK_LIST-DOC_TYPE = 'PDF'.
WA_PK_LIST-OBJ_NAME = 'ATTACHMENT'.
WA_PK_LIST-OBJ_DESCR = 'Reproduction object 138'.
WA_PK_LIST-DOC_SIZE = v_lines_bin * 255.
APPEND WA_PK_LIST TO ltb_objpack.
*call the function to send the pdf file by email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = ltb_objpack
contents_bin = ltb_objbin
contents_txt = ltb_objtxt
receivers = ltb_recipients
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 EQ '0'.
COMMIT WORK.
MESSAGE 'Your Email has been sent to corresponding authority' TYPE 'I'.
ENDIF.
ENDFORM. " AUTOMAIL
Here, pfile1 is the location from where you want to search particular document and pfile2 is use to get excel sheet to pickup the pan number in corresponding of it find the particular file in pfile1 location. Here, pan number which get from pfile2 is defined as the name of the pdf file in pfile1 location.
Many Thanks / Himanshu Gupta
2013 Jun 17 8:19 AM
Dear Venkateswaran,
It will works in background also.
Regards,
Ramesh.T
2013 Jun 28 8:19 PM
I wonder how GUI_UPLOAD works in background ... .. if there is a front end file to be uploaded, then how can background job do that??
Thanks,
Sam Peter
2013 Jun 29 4:38 AM
Hi Sam,
Your understanding is correct, GUI_UPLOAD cannot be used to upload a file in background.
BR.
2013 Jun 29 5:10 AM
Dear Sam,
Yes it is correct that GUI_UPLOAD does not works in background but if I give internally the path of file it takes the file and can do in background.
Many Thanks / Himanshu Gupta
2013 Jul 01 1:07 PM
Hi Team,
Please look into CL_GUI_FRONTEND_SERVICES methods by using those we can do background.
Regards,
Venkat.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |