on 06-16-2009 10:42 AM
Hi All,
I'm downloading o/p into excell file...
but for excell download i need to add header information how to add those....
my code as below..
METHOD onactiondownload .
DATA lo_nd_it_prod_req_list_item TYPE REF TO if_wd_context_node.
DATA lo_el_it_prod_req_list_item TYPE REF TO if_wd_context_element.
DATA itab TYPE wd_this->elements_n_prod_req_list_item.
DATA wa TYPE wd_this->element_n_prod_req_list_item.
DATA : text TYPE string.
DATA xtext TYPE xstring.
navigate from <CONTEXT> to <SFLIGHT> via lead selection
lo_nd_it_prod_req_list_item = wd_context->get_child_node( name = wd_this->wdctx_n_prod_req_list_item ).
get all declared attributes
lo_nd_it_prod_req_list_item->get_static_attributes_table(
IMPORTING
table = itab ).
TYPES : BEGIN OF ty_tab ,
reqno TYPE zmatreq-reqno,
zitem TYPE zmatreq-zitem,
zreqtype TYPE zmatreq-zreqtype,
maktx TYPE zmatreq-maktx,
meins TYPE zmatreq-meins,
matkl TYPE zmatreq-matkl,
zbrand TYPE zmatreq-zbrand,
zvers TYPE zmatreq-zvers,
a_material TYPE zmatreq-matnr,
a_price TYPE string,
waers TYPE zmatreq-waers,
zmenge TYPE string,
name1 TYPE string,
bill TYPE string,
zstatus TYPE zmatreq-zstatus,
lead_time TYPE zmatreq-lead_time,
END OF ty_tab.
itab1 like TABLE OF itab.
DATA : itab1 TYPE TABLE OF ty_tab.
DATA : wa_tab TYPE ty_tab.
LOOP AT itab INTO wa.
move wa-reqno to wa_tab-reqno.
wa_tab-reqno = wa-reqno.
wa_tab-zitem = wa-zitem.
wa_tab-zreqtype = wa-zreqtype.
wa_tab-maktx = wa-maktx.
wa_tab-meins = wa-meins.
wa_tab-matkl = wa-matkl.
wa_tab-zbrand = wa-zbrand.
wa_tab-zvers = wa-zvers.
wa_tab-a_material = wa-a_material.
wa_tab-a_price = wa-a_price.
wa_tab-waers = wa-waers.
wa_tab-zmenge = wa-zmenge.
wa_tab-name1 = wa-name1.
wa_tab-bill = wa-bill.
wa_tab-zstatus = wa-zstatus.
wa_tab-lead_time = wa-lead_time.
APPEND wa_tab TO itab1.
CLEAR wa_tab.
ENDLOOP.
LOOP AT itab1 INTO wa_tab.
CONCATENATE text
wa_tab-reqno
wa_tab-zitem
wa_tab-zreqtype
wa_tab-a_material
wa_tab-maktx
wa_tab-meins
wa_tab-zmenge
wa_tab-a_price
wa_tab-waers
wa_tab-matkl
wa_tab-zbrand
wa_tab-zvers
wa_tab-name1
wa_tab-bill
wa_tab-lead_time
wa_tab-zstatus
cl_abap_char_utilities=>newline INTO text SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
*append text.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = text
IMPORTING
buffer = xtext.
wdr_task=>client_window->client->attach_file_to_response(
**path to the word file
i_filename = 'Pre_Purchase_Query.XLS'
String Variable
i_content = xtext
File Type
i_mime_type = 'EXCEL' ).
ENDMETHOD.
regards
Suprith
hi suprith ,
for downloading to excel u cn proceed like this :
1 Create context node in the corresponding view and add a correponding attribute ( attrbute name 'A' suppose) with supply function . This attribute wud be , for example , the key to the second node which contains values to be imported to the excel .
( as per ur requiremnt)
2 Create the second node with corresponding attributes .
3 Inside layout , create the UI elemnt ;drop down by index' ( for example )
4 Create context binding with attribute 'A' and in hv a corresponding on action of the dropdown
5 Suppose , u want to transfer the table contents , thn insert UI table and bind with the second context node
6 Create UI 'button ' - export to excel and in its on action use the FM''SCMS_STRING_TO_XSTRING"
for transfering contents to excel .
7 thn using the utility " cl_abap_char_utilities" , concatenate the header into the excel file .
I hope the method wud help u
Edited by: amit saini on Jun 16, 2009 2:58 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suprith,
Here is a complete working sample code for downloading from WD table(context) to excel.
method ATTACH_FILES .
data: xml_out TYPE string.
data: string_out type string.
data: line type string.
data: line2 type string.
data: conv_out type ref to cl_abap_conv_out_ce.
data: content1 type xstring.
data: begin of break,
mandt type mandt,
linekey type char_02,
linebreak type ZLINEBREAK,
end of break.
DATA lo_nd_node_data TYPE REF TO if_wd_context_node.
DATA lo_el_node_data TYPE REF TO if_wd_context_element.
DATA ls_node_data TYPE wd_this->element_node_data.
DATA export_line type wd_this->element_node_data.
DATA export_tab like STANDARD TABLE OF export_line.
lo_nd_node_data = wd_context->get_child_node( name = wd_this->wdctx_node_data ).
select SINGLE * from ZCH_LINEBREAK into break
where linekey = '01'.
#### This is where you add the header####
CONCATENATE 'Submission ID'
'Function'
'FPO Type'
'FPO Value'
'Business Code'
'Due Date'
'Bridger'
'Submitter'
'Approver'
'Recharger'
'Actuals Manager'
'Local Analyst'
'Submitter'
into line SEPARATED BY ','.
CONCATENATE line break-linebreak into string_out.
* alternative access via index
do.
lo_el_node_data = lo_nd_node_data->get_element( index = sy-index ).
* @TODO handle non existant child
IF lo_el_node_data IS INITIAL.
exit.
ELSE.
* get all declared attributes
lo_el_node_data->get_static_attributes(
IMPORTING
static_attributes = ls_node_data ).
export_line = ls_node_data .
* append export_line to export_tab.
replace: ALL OCCURRENCES OF ',' in export_line-submission_id with space,
ALL OCCURRENCES OF ',' in export_line-fnc_desc with space,
ALL OCCURRENCES OF ',' in export_line-fpo_type with space,
ALL OCCURRENCES OF ',' in export_line-fpo_value with space,
ALL OCCURRENCES OF ',' in export_line-bu_code with space,
ALL OCCURRENCES OF ',' in export_line-zdue_date with space,
ALL OCCURRENCES OF ',' in export_line-bridger_text with space,
ALL OCCURRENCES OF ',' in export_line-submitter_text with space,
ALL OCCURRENCES OF ',' in export_line-approver_text with space,
ALL OCCURRENCES OF ',' in export_line-recharger_text with space,
* " Added - Multipule Template assigment D.Wong 03/12/08
* ALL OCCURRENCES OF ',' in export_line-ztext with space,
* " End - Multipule Template assigment D.Wong 03/12/08
ALL OCCURRENCES OF ',' in export_line-actuals_manager_text with space,
* ALL OCCURRENCES OF ',' in export_line-zassigned_to_text with space,
ALL OCCURRENCES OF ',' in export_line-local_analyst_text with space.
CONCATENATE
export_line-submission_id
export_line-fnc_desc
export_line-fpo_type
export_line-fpo_value
export_line-bu_code
export_line-zdue_date
export_line-bridger_text
export_line-submitter_text
export_line-approver_text
export_line-recharger_text
export_line-local_analyst_text into line SEPARATED BY ','.
CONCATENATE string_out line break-linebreak into string_out.
ENDIF.
enddo.
* call transformation ('ID') source tab = export_tab result xml xml_out.
conv_out = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = string_out
* MIMETYPE = ' '
* ENCODING =
IMPORTING
BUFFER = content1
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
* attach the first file
conv_out->convert( exporting data = content1 ).
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'file1.csv'
i_content = content1
i_mime_type = 'application/msexcel'
i_in_new_window = i_in_new_window
i_inplace = i_inplace ).
endmethod.
Please appreciate if helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just concatenate an extra line at the beginning of the output string with the headers:
CONCATENATE
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
'Header'
cl_abap_char_utilities=>newline INTO text SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
Of course adjust the text to whatever you want your headers to be. If you want to lookup the headers from the Data Dictionary based upon a data reference, try this example resuable method:
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ES_ABAP_UTILITIES=>READ_FIELD_DESC
* +-------------------------------------------------------------------------------------------------+
* | [--->] FIELD TYPE ANY
* | [<-()] DESC TYPE SCRTEXT_M
* +--------------------------------------------------------------------------------------</SIGNATURE>
method read_field_desc.
data: el_desc type ref to cl_abap_elemdescr,
isddic type abap_bool,
field_d type dfies.
try.
el_desc ?= cl_abap_typedescr=>describe_by_data( field ).
isddic = el_desc->is_ddic_type( ).
check isddic = abap_true.
field_d = el_desc->get_ddic_field( ).
desc = field_d-scrtext_m.
****Catch all Global Execptions - like bad casts
catch cx_root. "#EC CATCH_ALL
endtry.
endmethod.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.