Objective: To generate the formatted excel file which can be send or download as per below requirement.
1: User should able to download excel file when using GUI and execute in foreground mode.
2: When sending the email in foreground as well as if email is send in with background job.
3:When the ECC transaction is use as transaction launcher in SAP CRM the excel file should get generated same as it is working in SAP ECC, as in case of Transaction launcher it works as web page.
Advantage of using XML over OLE: As we can use the OLE method in ABAP to generate formatted excel but its work only in GUI foreground mode, where as we can use ‘xml’ concept in foreground as well as in background jobs for sending email etc.
Example: I have made the transaction in ECC which takes input as Year and display all the dates with weekday and in case of weekly off i.e Saturday and Sunday the background color of the cell will be green.
If user select the first option ‘Download Excel’ system will generate the excel file, presently I have kept the excel file in temp folder and same I have executed if file save successfully and in case of ‘Send email’ system will send the same file as email attachment.
Note : 1:We cannot save the file in any PC folder in background but we can save on app. Server using open data set method.
2: I have not added the code for email in my example we can check demo program BCS_EXAMPLE_7 to send file as email attachment.
3: I have made this program by refereeing the existing SDN doc.
http://wiki.scn.sap.com/wiki/display/Snippets/Formatted+Excel+as+Email+Attachment, I have use same for downloading the file in ECC frontend as well as when same is used in CRM WEB UI as transaction launcher.
4: For checking this you can upload the attach program in your system and can check the same.
Find here the attach file of program.