Showing posts with label Abap Reporting. Show all posts
Showing posts with label Abap Reporting. Show all posts

Wednesday, February 16, 2011

Abap send email with excel attachment

i just finished on of my SAP report requested by my user. The report need to run automatically once a month and send an email with EXCEL attachment to keep the result.

image credit to : wiki.sdn.sap.com

if you are using SAP ECC6, search for this example BCS_EXAMPLE_7 : Send Emeail with Excel attachment. from this example its will send email to the email receiver with excel attachment.  however the problems is, you cannot modify excel properties (such as column width, border, column color etc).

Don’t worry there always the solution, i just google around i found this solution: using excel XML to control the excel properties. What i have done was, using current code in BCS_EXAMPLE_7 and and bind the internal table contain into the excel’s XML format!!
from original BCS_EXAMPLE_7 search for form send, you will find this code :




Form create_content.

concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.

try.

cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = ’4103′ ”suitable for MS Excel, leave empty
iv_add_bom = ’X' ”for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.


and append the internal table into lv_string using the Excel’s XML  hierarchy.
your new LV_STRING could be coded as:

concatenate lv_string
‘<?xml version=”1.0″?>’
‘<?mso-application progid=”Excel.Sheet”?>’
<Workbook …. ‘  “XML header, please refer or link example as attached
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ” this line should be write with XML full header format
‘<Style ss:ID=”s3″>’ ” Make your Style ID
‘<Borders>’
‘<Border ss:Position=”Bottom” ss:LineStyle=”Continuous” ss:Weight=”1″/>’
‘<Border ss:Position=”Left” ss:LineStyle=”Continuous” ss:Weight=”1″/>’
‘<Border ss:Position=”Right” ss:LineStyle=”Continuous” ss:Weight=”1″/>’
‘<Border ss:Position=”Top” ss:LineStyle=”Continuous” ss:Weight=”1″/>’
</Borders>’
‘ </Style>
‘<Worksheet ss:Name=”Sheet1″>’
‘<Table ss:ExpandedColumnCount=”4″ ss:ExpandedRowCount=”9″ x:FullColumns=”1″
x:FullRows=”1″>’
‘<Column ss:AutoFitWidth=”0″ ss:Width=”135″/>’
‘<Column ss:Index=”3″ ss:StyleID=”" ss:AutoFitWidth=”0″ ss:Width=”66.75″/> ‘
‘<Row>’
‘<Cell ss:StyleID=”s3″><Data ss:Type=”String”>Row 4</Data></Cell>’
‘<Cell ss:StyleID=”s3″><Data ss:Type=”Number”>4000</Data></Cell>’
‘<Cell ss:StyleID=”s6″/>’
‘<Cell ss:StyleID=”s3″/>’
‘</Row>’
‘</Table>  <DataValidation xmlns=”urn:schemas-microsoft-com:office:excel”>’
‘<Range>R2C2:R1000C2</Range>’
‘<Type>List</Type>’
‘<CellRangeList/>’
‘<Value>”Red, Black, Green”</Value>’
‘</DataValidation>’
‘</Worksheet></Workbook> 

you also can refer to this example for your reference.

Monday, February 7, 2011

Abap Fields Symbols and Get Reference for multiple ALV report

Most of the customized report i created usually have different pattern in a single report such as the report have capability to show multiple type of result in the same sap report.  The user interface usually are always represented with radio button as below.

 

Each choosen radio button will represent a diffrent type of result (different number of column). If you are design your code using Object Oriented ALV, tradisionally you need to have multiple internal table for each result, such as IT01,IT02, IT03,… and you nedd to call ALV method multiple times, depending on number of your internal table and definately in my own opinion it is not good for programming implementation if we always repeating same method for the same purpose !