Professional Documents
Culture Documents
Log On
Join Us
Getting Started
Search for:
Products
Services & Support
About SCN
Downloads
Industries
Training & Education
Partnership
Developer Center
Lines of Business
University Alliances
Events & Webinars
Innovation
Newsletters
Store
Activity
Communications
Actions
BrowseMore
I had the need to give a user the ability to load an excel document into SAP. I wanted to build a
generic load option to allow importing any excel document and building a corresponding dynamic
context node and dynamic table. I created a generic method so this can be used from any ABAP WD
application.
Create a reference attribute on the view as follows:
Add a transparent container "TBL_CONTAINER" on your view layout where you wish the table to be
displayed. Then add the following code:
Test Output:
endwhile.
endloop.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"END - DETERMINE ROW/COLUMN COUNT AND BUILD COLUMN HEADER TEXTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
root_node_info = wd_context->get_node_info( ).
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"BEGIN - CREATE A 'CONTEXT NODE' TO HOLD THE EXCEL DATA
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
check ( wd_create_wd_context = abap_true ).
clear lt_col_attributes. refresh lt_col_attributes.
lv_i = 1.
while lv_i <= lv_column_cnt.
clear lv_column_nm.
get_column_txt lv_i lv_column_nm.
lv_col_attribute-name = lv_column_nm.
lv_col_attribute-type_name = 'STRING'.
insert lv_col_attribute into table lt_col_attributes.
lv_i = lv_i + 1.
endwhile.
root_node_info->add_new_child_node(
name
= wd_create_wd_context_nm
is_mandatory
= abap_false
is_mandatory_selection
= abap_false
is_multiple
= abap_true
is_multiple_selection
= abap_true
is_singleton
= abap_false
is_initialize_lead_selection = abap_false
is_static
= abap_false
attributes
= lt_col_attributes ).
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"END - CREATE A 'CONTEXT NODE' TO HOLD THE EXCEL DATA
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"BEGIN - CREATE A DYNAMIC TABLE FOR BINDING TO 'CONTEXT NODE'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
clear lt_alv_cat. refresh lt_alv_cat.
lv_i = 1.
while lv_i <= lv_column_cnt.
clear lv_column_nm.
get_column_txt lv_i lv_column_nm.
lv_alv_cat-fieldname = lv_column_nm.
lv_alv_cat-datatype = 'STRG'.
append lv_alv_cat to lt_alv_cat.
lv_i = lv_i + 1.
endwhile.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_alv_cat
importing
ep_table
= lv_ref_dyn_tbl.
assign lv_ref_dyn_tbl->* to <fs_dyn_tbl>.
check <fs_dyn_tbl> is assigned.
create data lv_dyn_tbl_line like line of <fs_dyn_tbl>.
assign lv_dyn_tbl_line->* to <fs_dyn_tbl_wa>.
clear lv_table_column.
clear lv_caption.
call method cl_wd_input_field=>new_input_field
exporting
bind_value = lv_column_bound_nm
id
= lv_column_nm
read_only = 'X'
receiving
control = lv_ui_col_input_field.
lv_table_column = cl_wd_table_column=>new_table_column( ).
lv_table_column->set_table_cell_editor( lv_ui_col_input_field ).
lv_caption = cl_wd_caption=>new_caption( ).
lv_caption->set_text( lv_column_nm ).
lv_table_column->set_header( lv_caption ).
lv_column_group->add_column( lv_table_column ).
lv_i = lv_i + 1.
endwhile.
lv_ui_table->add_grouped_column( lv_column_group ).
lv_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( lv_ui_table ).
lv_ui_table->set_layout_data( lv_ui_matrix_head_data ).
if not ( uielement_container is initial ).
call method uielement_container->add_child( exporting the_child = lv_ui_table ).
endif.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"END - CREATE GUI ELEMENT TABLE AND BIND TO 'CONTEXT NODE'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
catch cx_fdt_excel_core into ex_excel_core.
call method ex_excel_core->if_message~get_text( receiving result = lv_errtext ).
catch cx_root into ex.
message id sy-msgid type sy-msgty number sy-msgno into lv_errtext with sy-msgv1 sy-msgv2 symsgv3 sy-msgv4.
endtry.
528 Views Tags: webdynpro, abap_webdynpro, web_dynpro_abap, webdynpro_abap, abap_web_dynpro
1 Comment
Very nice! I just might have a use for this....thinking of building a "wizard" to help config HCM
P&F...using a spreadsheet to collect the info and then uploading it would be great!
Like (1)
Actions
Login to follow, like, comment, share and bookmark content.
LoginRegister
Follow SCN
Site Index
Contact Us
SAP Help Portal
Privacy
Terms of Use
Legal Disclosure
Copyright