SAP White Paper Solutions for Cross-Industry Name/ Industry Solution Name (optional)/
Document Details
Versio n
For any info on this document please contact: Name Email ID Anumeha Khandelwal anumeha.khandelwal@sap .com
Contact No
CONTENT
PURPOSE..............................................................................................................................................4 ABSTRACT.............................................................................................................................................4 DESCRIPTION.........................................................................................................................................4 3.1 SCENARIO ......................................................................................................................................4
Purpose
The document aims at providing a reusable ABAP code for developing a dynamic Table UI in Webdynpro for ABAP. Note: This was a requirement in Value mapping Tool . The following is implemented in the development of the tool . The main objective of the document is to provide the code to develop dynamic UI. Creating and activating a Webdynpro for ABAP application is not explained here. Minor changes would be required in the code as per the requirement of respective application .
Abstract
Ideally in any Webdynpro application , UI elements are developed using static context attributes. However there are situation where the attributes of a certain UI are not available before hand and are known only at runtime, mostly in case of user interaction or cases where display conditions are based on user input. In these situation there is a need to develop a dynamic UI elements.
Procedure
1. Start ABAP Workbench (SE80) and select Web- Dynpro-Comp./ Intf . from the available object list. 2. Create a Webdynpro Component. 3. Save it and assign it to a package . Here $TMP. 4. Create a new view and assign he view to a window. 5. Create a view context for the MainView. 6. Add attributes .
**** To get Root Node info in the Context. rootnode_info = wd_context->get_node_info( ). tabname_node = wd_context->get_child_node( name = 'XREFDATA' ). **** To get the TableName from the Input Field tabname_node->get_attribute( EXPORTING name = 'REFIDENT' IMPORTING value = tablename ). TRANSLATE tablename TO UPPER CASE.
**** To get structure name of the table name select STRUCTURE from ZVM_FILE_HDR into structname where REFIDENT eq tablename . endselect. TRANSLATE structname TO UPPER CASE. * tabname = structname. **** To Create a Table Node in the context Dynamically cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = rootnode_info node_name = structname structure_name = structname is_multiple = abap_true ) . dyn_node = wd_context->get_child_node( name = structname ). **** To Get the ref to ROOTUIELEMENTCONTAINER in the view CALL METHOD view->get_root_element RECEIVING root_view_element = rootelem. rootnode ?= rootelem . **** if Group_2 already exists in the, to remove it. **** this case only occurs, if you are running application just by refreshing. **** Precautionary Check for existence of Group_2 rootnode->remove_child( id = 'GROUP_2' ). **** To create a new Group group_2 = cl_wd_group=>new_group( view = view id = 'GROUP_2' design = '01' enabled = abap_true has_content_padding = abap_true scrolling_mode = '02' visible = '02' ). **** To add a caption to the Group capt_gr2 = cl_wd_caption=>new_caption( view = view "ID = 'CAPT_GR2' enabled = abap_true image_first = abap_true text = 'Dynamic Group' text_direction = '02' visible = '02' ). **** To set the Caption to the Group_2 group_2->set_header( capt_gr2 ).
**** To set the layout for the Group_2 cl_wd_grid_layout=>new_grid_layout( container = group_2 cell_padding = '0' cell_spacing = '0' col_count = '2' stretched_horizontally = abap_true stretched_vertically = abap_true ). cl_wd_flow_data=>new_flow_data( element = group_2 cell_design = '04' v_gutter = '00' ). **** Add the Group_2 to ROOTUIELEMENTCONTAINER rootnode->add_child( group_2 ) . **** Create a Table UI Element from Context and assigning it to Group_2. new_tab = cl_wd_dynamic_tool=>create_table_from_node( ui_parent = group_2 table_id = 'TESTTAB' node = dyn_node ).
* create internal table of (tabletype ) CREATE DATA stru_tab TYPE TABLE OF (structname). ASSIGN stru_tab->* TO <tab>. ASSIGN stru_tab->* TO <fsym_itab1>. ASSIGN stru_tab->* TO <fsym_itab2>. CREATE DATA stru_wa TYPE (structname). * ASSIGN stru_wa->* TO <fsym_warea1>. ASSIGN stru_wa->* TO <fsym_warea2>. * DATA wa_tab1 TYPE <fsym_itab1>.
* Get table content * SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>. *****Get field content node****** DATA lo_nd_file_upload TYPE REF TO if_wd_context_node. DATA lo_el_file_upload TYPE REF TO if_wd_context_element. DATA ls_file_upload TYPE wd_this->element_file_upload. DATA lv_file_contents LIKE ls_file_upload-file_contents. * DATA it_stndTable1 TYPE STANDARD TABLE OF tabname. * DATA it_stndTable2 TYPE STANDARD TABLE OF tabname. * Data wa_stndTable1 TYPE tabname. * Data wa_stndTable2 TYPE tabname.
* navigate from <CONTEXT> to <FILE_UPLOAD> via lead selection lo_nd_file_upload = wd_context->get_child_node( name = wd_this->wdctx_file_upload ). * get element via lead selection lo_el_file_upload = lo_nd_file_upload->get_element( ). * get single attribute lo_el_file_upload->get_attribute( EXPORTING name = `FILE_CONTENTS` IMPORTING value = lv_file_contents ). CALL METHOD cl_abap_conv_in_ce=>create EXPORTING input = lv_file_contents encoding = 'UTF-8' replacement = '?' ignore_cerr = abap_true RECEIVING conv = loc_conv. *Read the file contents TRY. CALL METHOD loc_conv->read IMPORTING data = var_string. CATCH cx_sy_conversion_codepage. *Should ignore errors in code conversions CATCH cx_sy_codepage_converter_init. *Should ignore errors in code conversions CATCH cx_parameter_invalid_type. CATCH cx_parameter_invalid_range. ENDTRY. if structname eq 'ZPLANTXREF'. elseif structname eq 'ZXREFGENERIC'. elseif structname eq 'ZXREFGENERICMULTI'. endif. SPLIT var_string AT cl_abap_char_utilities=>NEWLINE INTO TABLE itab. LOOP AT itab INTO watab. var_string = watab-field_row. * SPLIT var_string AT ',' INTO TABLE <fsym_itab1>. SPLIT var_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE <fsym_itab1>. LOOP AT <fsym_itab1> INTO <fsym_warea2>. APPEND <fsym_warea2> TO <tab>. ENDLOOP. ENDLOOP.
endmethod.
1.Result
You have now created a Web Dynpro component which contains one view VIEW1. On view VIEW1 a Group with Label, InputField and Button. Once you input the file and click on upload, the result is displayed in a new group UI element (Dynamic Group) along with a table. Furthermore, you have created a Web Dynpro application (as handle for the Web Dynpro component) which can be started directly via URL. The result screen is a table which displays file(provided by user) data.
This concept is applied to the Value mapping tool , which is being developed n ABAP . Following link can be accessed to have an idea of the concept. http://inst50084596.blr4.sap.corp:50400/sap/bc/webdynpro/sap/zvaluemaptool?saplanguage=EN