on 02-21-2012 7:25 AM
I have a purchase order and want to send it via email. The purchase order has attachments at line item level (e.g. a specification in pdf format). Attachments were able to see through T-code CV03N,
When transferring the PO to vendor ,smartform is attached to email and sended to vendor .now we need additioanl attachments also to be sended in same email which is present at line item level (CV03N),Whether it is possible to copy the attachments into the email, so they are sent out, too?
Please explain the methods
Print program used for smartform is custom Z name space.
Thanks in advance
Regards,
arun
part 2.
*&---------------------------------------------------------------------*
*& Selection screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME TITLE text-001.
PARAMETERS: pa_ebeln TYPE ebeln.
PARAMETERS: pa_incl TYPE os_boolean AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK blk01.
SELECTION-SCREEN BEGIN OF BLOCK blk02 WITH FRAME TITLE text-002.
PARAMETERS: pa_incl2 TYPE os_boolean AS CHECKBOX DEFAULT 'X'.
PARAMETERS pa_dir TYPE c LENGTH 100.
PARAMETERS pa_file TYPE c LENGTH 40.
SELECTION-SCREEN END OF BLOCK blk02.
SELECTION-SCREEN BEGIN OF BLOCK blk03 WITH FRAME TITLE text-003.
PARAMETERS pa_email TYPE ad_smtpadr.
PARAMETERS pa_subj TYPE so_obj_des.
SELECTION-SCREEN END OF BLOCK blk03.
*&---------------------------------------------------------------------*
*& Fill variables with parameters
*&---------------------------------------------------------------------*
lv_ebeln = pa_ebeln.
lv_dir = pa_dir.
lv_file = pa_file.
lv_email = pa_email.
l_main_title = pa_subj.
*&---------------------------------------------------------------------*
*& Create email document
*&---------------------------------------------------------------------*
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_subject = l_main_title ).
send_request = cl_bcs=>create_persistent( ).
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
send_request->set_sender( lo_sender ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
send_request->add_recipient( lo_recipient ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
part 3
*&---------------------------------------------------------------------*
*& Cet GOS attachments
*&---------------------------------------------------------------------*
IF pa_incl = 'X'.
CALL FUNCTION 'BDS_GOS_CONNECTIONS_GET'
EXPORTING
classname = 'BUS2010'
objkey = lv_ebeln
TABLES
gos_connections = lt_gos_connections
EXCEPTIONS
no_objects_found = 1
internal_error = 2
internal_gos_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i001(zmm) WITH 'BDS_GOS_CONNECTIONS_GET' sy-subrc DISPLAY LIKE 'E'.
ENDIF.
LOOP AT lt_gos_connections INTO ls_gos_connections.
CLEAR lv_docid.
lv_docid = ls_gos_connections-loio_id.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_docid
IMPORTING
document_data = ls_document_data
TABLES
object_content = lt_object_content
contents_hex = lt_contents_hex
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i001(zmm) WITH 'SO_DOCUMENT_READ_API1' sy-subrc DISPLAY LIKE 'E'.
ENDIF.
* Create attachment name as file name
CONCATENATE ls_document_data-obj_descr '.' ls_document_data-obj_type INTO at_subj.
*add attachment
IF ls_document_data-obj_type = 'TXT'. "If text document, attachment type should be 'RAW'
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'RAW'
i_attachment_subject = at_subj
i_att_content_text = lt_object_content.
ELSE.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'BIN'
i_attachment_subject = at_subj
i_att_content_hex = lt_contents_hex.
ENDIF.
ENDLOOP.
ENDIF.
part 4 (final)
*&---------------------------------------------------------------------*
*& Cet documents from SAP application server directory
*&---------------------------------------------------------------------*
IF pa_incl2 = 'X'.
"------------------------ get direcotry listing
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = lv_dir
TABLES
dir_list = dir_list
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE i001(zmm) WITH 'EPS_GET_DIRECTORY_LISTING' sy-subrc DISPLAY LIKE 'E'.
ENDIF.
LOOP AT dir_list.
IF lv_file IS NOT INITIAL.
CHECK dir_list-name CS lv_file. "consider only files with this name
ENDIF.
CONCATENATE lv_dir dir_list-name INTO file_name.
OPEN DATASET file_name FOR INPUT IN BINARY MODE.
READ DATASET file_name INTO data_string.
CLOSE DATASET file_name.
CALL METHOD document->xstring_to_solix
EXPORTING
ip_xstring = data_string
RECEIVING
rt_solix = it_attachments.
at_subj = dir_list-name.
**add attachment
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'BIN'
i_attachment_subject = at_subj
i_att_content_hex = it_attachments.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEAR data_table.
ENDLOOP.
ENDIF.
send_request->set_document( document ).
DATA sent_to_all TYPE os_boolean.
sent_to_all = send_request->send( ).
IF sent_to_all = 'X'.
MESSAGE text-004 TYPE 'I'.
ENDIF.
COMMIT WORK.
part 1.
*&---------------------------------------------------------------------*
*& Report ZTEST_SSP
*&
*&---------------------------------------------------------------------*
*& This program is used to send purchase orders by email, it should be
*& implemented in the print program for printing the smartform.
*& Since this is a test program, this can be used as an example.
*&---------------------------------------------------------------------*
REPORT ztest_ssp.
*&---------------------------------------------------------------------*
*& Data declaration
*&---------------------------------------------------------------------*
DATA lv_ebeln TYPE swotobjid-objkey.
DATA ls_gos_connections TYPE bdn_con.
DATA lt_gos_connections TYPE TABLE OF bdn_con.
DATA lv_email TYPE ad_smtpadr.
DATA lt_contents_hex TYPE TABLE OF solix.
DATA ls_document_data TYPE sofolenti1.
DATA at_subj TYPE so_obj_des.
DATA send_request TYPE REF TO cl_bcs.
DATA lt_object_content TYPE TABLE OF solisti1.
DATA lv_docid TYPE sofolenti1-doc_id.
DATA document TYPE REF TO cl_document_bcs.
DATA l_main_title TYPE so_obj_des.
DATA lo_sender TYPE REF TO if_sender_bcs.
DATA lo_recipient TYPE REF TO if_recipient_bcs.
*directory list
DATA: BEGIN OF dir_list OCCURS 0.
INCLUDE STRUCTURE epsfili.
DATA END OF dir_list.
DATA file_name TYPE string.
DATA lv_dir TYPE epsf-epsdirnam.
DATA lv_file TYPE epsf-epsfilnam.
DATA data_table TYPE TABLE OF solix.
DATA data_string TYPE xstring.
DATA it_attachments TYPE solix_tab.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Below is a test program which allows you to get the attachments of a PO document and send it with email.
In addition, this program allows you to get files from a folder on the sap application server, and attach the files in this folder as well.
Best wishes,
Steven Spronk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Arun,
You can use function call BDS_GOS_CONNECTIONS_GET to get the list of attached documents. Then use function call 'SO_DOCUMENT_READ_API1' to get the actual content of these attached documents in the list.
You can then use class cl_document_bcs method add_attachment to add the document to your email.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.