*&---------------------------------------------------------------------*
*& Form download_to_application
*& download to application server, attach to mail and send to user
*&---------------------------------------------------------------------*
FORM download_to_application.
data: l_title type SO_OBJ_DES.
l_title = sy-repid.
CALL FUNCTION 'ZSEND_REPORT_MAIL'
EXPORTING
i_title = l_title
tables
it_text_data = it_download
EXCEPTIONS
INVALID_USER = 1
MAIL_SEND_ERROR = 2
OPEN_FILE = 3
FILE_GET_NAME = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE e368(00) with 'ZSEND_REPORT_MAIL fail -'
sy-subrc.
ENDIF.
ENDFORM. " download_to_application
===============================================================================
FUNCTION Zsend_report_mail.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_UNAME) TYPE SYUNAME DEFAULT SY-UNAME
*" REFERENCE(I_TITLE) TYPE SO_OBJ_DES
*" TABLES
*" IT_TEXT_DATA
*" EXCEPTIONS
*" INVALID_USER
*" MAIL_SEND_ERROR
*" OPEN_FILE
*" FILE_GET_NAME
*"----------------------------------------------------------------------
* This function is used to store a file (report result) on the file
* system of the application server and to send an "active" SAP mail
* to the user.
* The "active" SAP mail calls function ZMAIL_DOWNLOAD to
* download the file to the presentation server.
DATA: ls_document_data LIKE sodocchgi1.
DATA: lt_object_para LIKE soparai1 OCCURS 5 WITH HEADER LINE.
DATA: lt_object_parb LIKE soparbi1 OCCURS 0 WITH HEADER LINE.
DATA: lt_object_cont LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: lt_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: l_filename(200) TYPE c.
CHECK NOT it_text_data[] IS INITIAL.
* terminate if name not suitable.
IF i_uname IS INITIAL OR
i_uname = 'WF-BATCH' OR
i_uname = 'DDIC' OR
i_uname = 'SAP*'.
RAISE invalid_user.
ENDIF.
* get physical file from logical filename( optional)
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'MAILFILE'
parameter_1 = sy-uname
parameter_2 = sy-datum
parameter_3 = sy-uzeit
* USE_PRESENTATION_SERVER = ' '
* WITH_FILE_EXTENSION = ' '
* USE_BUFFER = ' '
* ELEMINATE_BLANKS = 'X'
IMPORTING
* EMERGENCY_FLAG =
* FILE_FORMAT =
file_name = l_filename
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
RAISE file_get_name.
ENDIF.
* save file
OPEN DATASET l_filename FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0.
RAISE open_file.
ENDIF.
LOOP AT it_text_data. " into l_text_data.
TRANSFER it_text_data TO l_filename.
ENDLOOP.
CLOSE DATASET l_filename.
* SAP mail header (execute function)
CLEAR: ls_document_data.
ls_document_data-obj_descr = i_title.
ls_document_data-proc_type = 'F'. " function call
ls_document_data-proc_name = 'ZMAIL_DOWNLOAD'.
ls_document_data-no_change = 'X'.
* SAP mail receiver
REFRESH lt_reclist.
CLEAR lt_reclist.
lt_reclist-receiver = i_uname.
lt_reclist-rec_type = 'B'.
* gt_reclist-express = 'X'.
APPEND lt_reclist.
* message text
REFRESH lt_object_cont.
CLEAR lt_object_cont.
lt_object_cont-line =
'The result of the following report has been saved.'.
APPEND lt_object_cont.
* report name
lt_object_cont-line = 'Report:'.
lt_object_cont-line+15 = sy-cprog.
CONDENSE lt_object_cont-line.
APPEND lt_object_cont.
* date & time
lt_object_cont-line = 'Date/Time:'.
WRITE sy-datum TO lt_object_cont-line+15.
WRITE sy-uzeit TO lt_object_cont-line+27.
CONDENSE lt_object_cont-line.
APPEND lt_object_cont.
*
lt_object_cont-line =
'Please execute (Ctrl-F6) this mail to download the result.'.
APPEND lt_object_cont.
* mail parameters
REFRESH lt_object_parb.
CLEAR lt_object_parb.
lt_object_parb-name = 'FUNCTION'. " mail identifier
lt_object_parb-value = 'FILE_DOWNLOAD'. " mail identifier
APPEND lt_object_parb.
lt_object_parb-name = 'FILENAME'.
lt_object_parb-value = l_filename.
APPEND lt_object_parb.
*call SAPOffice API
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = ls_document_data
TABLES
object_content = lt_object_cont
object_para = lt_object_para
object_parb = lt_object_parb
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.
IF sy-subrc NE 0.
RAISE mail_send_error.
ENDIF.
ENDFUNCTION.
===========================================================================
FUNCTION zmail_download.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" MSGDIAL STRUCTURE SOPARBI1
*"----------------------------------------------------------------------
* This function is called in a SAP mail to download a file from the
* application server file system.
* Function ZSEND_REPORT_MAIL is used to save report result
* on application server file system and to send SAP mail to user.
* Based on UK COM solution by Damian Norton.
DATA: ls_msgdial TYPE soparbi1.
DATA: l_filename TYPE filep.
* DATA: l_filename_local TYPE filep.
DATA: l_operation(30) TYPE c.
DATA: BEGIN OF lt_text_data OCCURS 10,
line(2000),
END OF lt_text_data.
* read parameters
LOOP AT msgdial INTO ls_msgdial.
CASE ls_msgdial-name.
WHEN 'FUNCTION'.
l_operation = ls_msgdial-value.
WHEN 'FILENAME'.
l_filename = ls_msgdial-value.
WHEN OTHERS.
MESSAGE e368(00) WITH 'Invalid parameter' ls_msgdial-name.
ENDCASE. " ls_msgdial-name
ENDLOOP. " msgdial
IF l_operation = 'FILE_DOWNLOAD'.
* check, whether file exists on presentation server
REFRESH lt_text_data.
OPEN DATASET l_filename FOR INPUT IN TEXT MODE.
IF sy-subrc = 0.
DO.
READ DATASET l_filename INTO lt_text_data-line.
IF sy-subrc = 0.
APPEND lt_text_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
* request filename on presentation server - or GUI_DOWNLOAD??
CALL FUNCTION 'DOWNLOAD'
TABLES
data_tab = lt_text_data
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
customer_error = 7
OTHERS = 8.
IF sy-subrc NE 0.
MESSAGE e688(00) WITH 'File download error' sy-subrc.
ENDIF.
ELSE.
MESSAGE e398(00) WITH 'File open error' l_filename.
ENDIF. " sy-subrc = 0 (OPEN DATASET)
ENDIF. " l_operation = 'FILE_DOWNLOAD'
ENDFUNCTION.
Tuesday, May 6, 2008
Sample ABAP Program for Output file to application server then send mail with Download details
Labels:
Sample ABAP Code Programs
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2008
(300)
-
▼
May
(80)
- Object oriented programming (OOP) All Steps
- Object oriented programming (OOP) Step2
- Object oriented programming (OOP) Step-by-step
- Object oriented programming (OOP) explained with a...
- Interview Question on BAPI, RFC, ABAP Objects, Tables
- The Other 50 ABAP Interview Faq's
- More than 100 ABAP Interview Faq's
- Events in Report
- Example: The IDoc Type ORDERS01
- Program for Outbound IDOC
- Basic Configuration in IDOC
- Sample ABAP Program to Upload table using new func...
- Sample ABAP Program for Submitting report with sel...
- Sample ABAP Program for Submitting report with sel...
- Sample ABAP Program for Sending SAP Mail
- Sample ABAP Program for Search Layout sets for giv...
- Sample ABAP Program for Sapscript PerForm Module
- Sample ABAP Program for Create IDOC
- Sample ABAP Program for Output file to application...
- Sample ABAP Program for Module Pool Skeleton
- Sample ABAP Program for Module Pool containing scr...
- Sample ABAP Program for MB1B Call Transaction
- Sample ABAP Program of Function Module to Convert ...
- Sample ABAP Program of FTP Function Module
- Sample ABAP Program to EXPORT LIST TO MEMORY
- Sample ABAP Program to Execute Unix command from w...
- Sample ABAP Program to Get Output in EXCEL
- Sample ABAP Program to Implement EDI
- Sample Program to dynamically change upload/downlo...
- Sample ABAP Program to download table using new fu...
- Sample ABAP Program to Download file to Presentati...
- Sample ABAP Program to display pop message to avoi...
- Sample ABAP Program of ALV Grid
- Sample ABAP Program of Dialogue Module Pool
- Sample ABAP Program to DIALOGUE FLOW LOGIC
- Sample ABAP Program to Delete a file from the appl...
- Sample ABAP Program to Compare to Unix or PC files...
- Sample ABAP Program to Colour cells in ALV
- Sample ABAP Program to Calculate difference betwee...
- Sample ABAP Program of BW User Exit
- Sample SAP ABAP Program to Browse a file on the ap...
- Sample SAP ABAP Program of ALV Grid control using ...
- SE30 - Runtime Analysis Tool
- List of System fields
- Write a report that displays the text 'Hello world...
- HR (Human Resource) Tutorials Free downloads
- FI (Financial) Tutorials Free downloads
- PM (Plant Maintenance) Tutorials Free downloads
- WM (Warehouse Management) Tutorials Free downloads
- QM (Quality Management) Tutorials Free downloads
- PP (Production Planning) Tutorials Free downloads
- SD (Sales and Distribution) Tutorials Free downloads
- MM (Material Management) Tutorials Free downloads
- IDOC INTRODUCTION & STRUCTURE
- Step-by-Step Guide for using LSMW to Update Custom...
- LIST of TABLES
- Transporting Objects and Standard Text from one cl...
- SAP R/3 INTERVIEW ARCHITECTURE QUESTIONS
- SAP TRANSACTIONS INTERVIEW QUESTIONS
- SAP MODULARIZATION INTERVIEW QUESTIONS
- SAP LOGICAL DATABASE INTERVIEW QUESTIONS
- SAP R/3 DATA DICTIONARY INTERVIEW QUESTIONS
- SAP BDC INTERVIEW QUESTIONS & ANSWERS
- SAP ABAP MENU PAINTER & SCREEN PAINTER Tutorials
- SAP ABAP WORKFLOW Tutorials PDF Free downloads
- SAP ABAP ITS Tutorials PDF Free downloads
- SAP ABAP EDI Tutorials PDF Free downloads
- SAP ABAP BAPI Tutorials PDF Free downloads
- SAP ABAP Change&Transport System Tutorials PDF Fre...
- SAP ABAP OBJECTS Tutorials PDF Free downloads
- SAP ABAP USER EXITS Tutorials PDF Free downloads
- SAP ABAP ALE Tutorials PDF Free downloads
- SAP ABAP IDOC Tutorials PDF Free downloads
- SAP ABAP LSMW Tutorials PDF Free downloads
- SAP ABAP BDC (Batch Data Communication) Tutorials ...
- SAP ABAP SAPSCRIPTS Tutorials Free downloads
- ALV Grid free download
- SAP ABAP INTERACTIVE REPORTING FAQs
- SAP ABAP REPORTING GENERAL
- SAP REPORTS FAQ
-
▼
May
(80)
No comments:
Post a Comment