2008 Jun 27 2:35 PM
Hi,
I created an excel sheet with more than one worksheets by using 'OLE' object . Created excel sheet must be saved on the server but this doesn't work when running in background.
Is there a way to do this?
Is there a way to export data to excel with multiple worksheets other then with OLE object?
How can I read a content of the OLE object?
Regards,
Amel
Hi,
I created an excel sheet with more than one worksheets by using 'OLE' object . Created excel sheet must be saved on the server but this doesn't work when running in background.
Is there a way to do this?
Is there a way to export data to excel with multiple worksheets other then with OLE object?
How can I read a content of the OLE object?
Regards,
Amel
2008 Jul 01 10:44 AM
OLE objects are always run in the foreground beacuse they are run from the client (not from the SAP server), there is no way to do it in the background
still you can build an Excel file in binary format, but this means a lot of work...
2008 Jul 01 10:55 AM
Hi,
welcome.
Creating Excel sheets in background :
PERFORM get_result_data.
PERFORM get_actors.
IF NOT gt_recipients IS INITIAL.
PERFORM build_email_content.
PERFORM build_file_content.
PERFORM build_document_data.
PERFORM build_packing_list.
PERFORM send_email.
ELSE. "Do not continue
MESSAGE i010(ad) WITH text-004.
ENDIF.
get_result_data
PERFORM get_actors.
FORM get_actors .
DATA:
lt_container TYPE TABLE OF swcont,
ls_container TYPE swcont,
lt_actor TYPE TABLE OF swhactor,
ls_actor LIKE swhactor.
MOVE 'REPORTNAMERECIPIENTS' TO ls_container-element.
MOVE 'ZMC_NEW_CLIENTS' TO ls_container-value.
MOVE '040' TO ls_container-elemlength.
MOVE 'C' TO ls_container-type.
APPEND ls_container TO lt_container.
CALL FUNCTION 'RH_GET_ACTORS'
EXPORTING
act_object = 'AC90000144'
TABLES
actor_container = lt_container
actor_tab = lt_actor
EXCEPTIONS
no_active_plvar = 1
no_actor_found = 2
exception_of_role_raised = 3
no_valid_agent_determined = 4
OTHERS = 5.
Filter out any not added to the role as users e.g. US
LOOP AT lt_actor INTO ls_actor WHERE otype EQ 'US'.
CONCATENATE ls_actor-objid '@linklaters.com' INTO
gs_recipients-receiver.
gs_recipients-rec_type = 'U'.
gs_recipients-com_type = 'INT'.
gs_recipients-notif_ndel = 'X'.
APPEND gs_recipients TO gt_recipients.
ENDLOOP.
ENDFORM. " get_actors
Then I build the text in the e-mail:
&----
*& Form build_email_content
&----
FORM build_email_content .
MOVE 'Please find attached a recent New Client Report' TO
gs_email_body-line.
APPEND gs_email_body TO gt_email_body.
MOVE 'This is a system generated mail, please do not reply.' TO
gs_email_body-line.
APPEND gs_email_body TO gt_email_body.
ENDFORM. " build_email_content
&----
*& Form build_file_content
&----
FORM build_file_content .
DATA: lv_mrp_name(81) TYPE c,
lv_mtp_name(81) TYPE c,
lv_mrp_locn(81) TYPE c,
lv_mtp_locn(81) TYPE c.
CONCATENATE gv_tmp_result_string
'Client Number'
'Client Name'
'Client Location'
'CUP Name'
'GUP Name'
'DUP Name'
'IP Name'
'Cup Number'
'GUP Number'
'DUP Number'
'IP Number'
'DUNS Number'
'SIC Code'
'SIC Description'
'MRP Name'
'MRP Location'
'1st Approving Partner Name'
'1st Approving Partner Location'
con_cret
INTO gv_tmp_result_string SEPARATED BY con_tab.
LOOP AT gt_result INTO gs_result.
CLEAR: lv_mrp_name, lv_mtp_name, lv_mrp_locn, lv_mtp_locn.
CONCATENATE gs_result-mrp_last gs_result-mrp_first INTO lv_mrp_name
SEPARATED BY ','.
CONCATENATE gs_result-mtp_last gs_result-mtp_first INTO lv_mtp_name
SEPARATED BY ','.
CONCATENATE gs_result-mrp_office1 gs_result-mrp_office2 INTO
lv_mrp_locn SEPARATED BY ','.
CONCATENATE gs_result-mtp_office1 gs_result-mtp_office2 INTO
lv_mtp_locn SEPARATED BY ','.
CONCATENATE gv_tmp_result_string
gs_result-partner
gs_result-name
gs_result-city1
gs_result-z_cup_name
gs_result-z_gup_name
gs_result-dup_name
gs_result-ip_name
gs_result-z_cup_number
gs_result-z_gup_number
gs_result-dup_number
gs_result-ip_number
gs_result-duns_number
gs_result-ind_sector
gs_result-text
lv_mrp_name
lv_mrp_locn
lv_mtp_name
lv_mtp_locn
con_cret
INTO gv_tmp_result_string SEPARATED BY con_tab.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
EXPORTING
text = gv_tmp_result_string
TABLES
ftext_tab = gt_file_contents.
ENDFORM. " build_file_content
Then I calculate the size and set the e-mail sensitivity:
&----
*& Form build_document_data
&----
FORM build_document_data .
DATA: lv_lines TYPE i.
gs_document_data-obj_name = 'SAPREPORT'.
gs_document_data-obj_descr = 'New Client Report'.
gs_document_data-obj_langu = sy-langu.
gs_document_data-sensitivty = 'P'. "Confidential
DESCRIBE TABLE gt_file_contents LINES lv_lines.
gs_document_data-doc_size = 255 * lv_lines.
ENDFORM. " build_document_data
Then the packing list:
&----
*& Form build_packing_list
&----
FORM build_packing_list .
Describe the body of the message
CLEAR gt_packing_list.
REFRESH gt_packing_list.
gs_packing_list-transf_bin = space.
gs_packing_list-head_start = 1.
gs_packing_list-head_num = 0.
gs_packing_list-body_start = 1.
DESCRIBE TABLE gt_file_contents LINES gs_packing_list-body_num.
gs_packing_list-doc_type = 'RAW'.
APPEND gs_packing_list TO gt_packing_list.
Describe the attachment
CONCATENATE 'NewClientReport' p_dateto INTO gv_filename.
gs_packing_list-transf_bin = 'X'.
gs_packing_list-head_start = 1.
gs_packing_list-head_num = 1.
gs_packing_list-body_start = 1.
gs_packing_list-obj_descr = gv_filename.
gs_packing_list-doc_type = 'XLS'.
DESCRIBE TABLE gt_file_contents LINES gs_packing_list-body_num.
gs_packing_list-obj_name = gv_filename.
gs_packing_list-doc_size = gs_packing_list-body_num * 255.
APPEND gs_packing_list TO gt_packing_list.
ENDFORM. " build_packing_list
And finally send the e-mail
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gs_document_data
commit_work = 'X'
TABLES
packing_list = gt_packing_list
contents_bin = gt_file_contents
contents_txt = gt_email_body
receivers = gt_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.
thanks
abdul
reward me if usefull.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |