high performance web system

Upload: hinduforever

Post on 05-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 High Performance Web System

    1/9

    High performance of Web dynpro ABAP

    Added by xiaohong wu, last edited by Bharadwaj p on Nov 21, 2010 (view change)

    Performance for Web dynpro is very important, because it cover more than normal ABAP program,it's also related to Wgate, the HTTP request/response cycle, so the whole design is critical.

    First we still have to follow the performance rule for normal ABAP program when we receive thedata from database, but we have to add something more based on web side, please keep in mindthe basic rule:

    1. lower memory consumption, better performance.

    2. using MVC, split the component up if too large, usingif_wd_component_usage=>delete_component to delete all web dynpro component instances assoon as no longer needed

    3. Using dynamic navigation or dynamic component usages only if it is absolutely necessary.

    4. Set the lifetime of a view to when visible, if this view is displayed not too much.

    5. Keep context as small as possible, Create context only required by UI binding, use assistanceclass or other ABAP OO class as data exchange. Use singleton node, do not use any dynamicattributes if_wd_context_node_info->add_attribute, bad context design cause huge runtimememory.

    6. Don't raise exception in supply function, these cause runtime dump.

    7. Do not use container scrolling (scrollingModenone), create application screens that fits thestandard browser, avoid deep nesting of containers, groups and tabstrips, use the dynamic UIelement programming only if it's necessary

    Model part

    Use assistance class as model, Creating an assistance class for a component provides thefollowing benefits:

    You can store coding there that is required within the component, but is not linked directly withthe layout or with the function of a controller. This could be, for example, a call of the applicationlayer or UI-based editing of the data. Method calls of the assistance class are much better from aperformance point of view than calls of methods of a Web Dynpro controller.

    Assistance class can store the data in the memory, The instance is available to each controller ofthe component through the attribute WD_ASSIST and sub component usage. The instance ofassistance is in the cache at runtime can save the data has been changed. The assistance class isautomatically instantiated when a component is called.

    The second important function of the assistance class is the management of dynamic texts.

    Texts that are combined at runtime only and/or contain variables can be stored in the text pool ofthe assistance class as text symbols.

    In this tutorial I'm going to show you how to add buttons change, display, save, delete, cancel andexit on the WDA, all these buttons have the same function as SAP GUI, how to use assistanceclass to implement those functions and how to use dynamic programming to control the property ofUI elements.

    I also show you how to use the input-help components, use the transaction code to start the WDAand exit WDA.

  • 7/31/2019 High Performance Web System

    2/9

  • 7/31/2019 High Performance Web System

    3/9

  • 7/31/2019 High Performance Web System

    4/9

    lr_contact_node = wd_context->get_child_node(wd_this->wdctx_zcutomer).

    lr_contact_node->bind_table(new_items=lt_contact).

    Endmethod.

    Change and display button: I want to switch change/display mode, then I can change the data, Ibind the attribute readonly to the readonly property of input field of table column, I control theproperty by the button change and display. On event handler change, I set the value 'X', on eventhandler display, I set the value "".

    Method onactiongo_change.

    data: lr_node type ref to IF_WD_CONTEXT_NODE,

    lr_element type ref to IF_WD_CONTEXT_ELEMENT,

    lr_ restrict type wdy_boolean.

    lr_node = wd_context->get_child_node( wd_this->wdctx_readonly ).

    Lr_element = l_node->get_element( ).

    lr_restrict = space.

    *lr_restrict = "X" for display

    lr_element->set_attribute(exporting name = "READONLY" value = lr_restrict).

    Endmethod.

    The user select the data and change it, then they want to save the data has been changed, but theproblem is the customer table is singleton and the selection mode is single, the contact table is

    multiple selection, and the user doesn't want to save the data immediately, he wants to save thedata at the end, he may change his mind and cancel the changing or delete the data. Now you cansee the beauty of assistance, I'll show you how to do that in a minutes.

    Event onLeadSelect of table view:

    On the zcustomer table view add method to the onLeadSelect event property.

    Method onactionrow_selected_customer.

    data: lr_node type ref to IF_WD_CONTEXT_NODE,

    lr_element type ref to IF_WD_CONTEXT_ELEMENT,

    lr_customer type ref to if_main=>element_zcustomer,

    lwa_customer type table zcustomer.

    lr_node = wd_context->get_child_node( wd_this->wdctx_zcustomer ).

    lr_element = l_node->get_lead_selection( ).

    lr_element->get_static_attributes(importing static_attributes = lr_customer).

  • 7/31/2019 High Performance Web System

    5/9

    Clear lwa_customer.

    Move-corresponding lr_customer to lwa_customer.

    Append lwa_customer to wd_assist->tt_customer.

    Endmethod.

    On the zcontact table view I select the multiple selection.

    Method onactionrow_selected_contact.

    data: lr_node type ref to IF_WD_CONTEXT_NODE,

    lr_element type ref to IF_WD_CONTEXT_ELEMENT,

    lr_contact type ref to if_main=>element_zcontact.

    lt_contact type ref to if_main=>elements_zcontact,

    lwa_contact type zcontact,

    lt_contact type table zcontact.

    lr_node = wd_context->get_child_node( wd_this->wdctx_zcontact ).

    lt_contact = lr_node->get_selected_elements( ).

    Loop at lt_contact into lr_element.

    Move-corresponding lr_element to lwa_contact.

    Append lwa_contact to lt_contact.

    Endloop.

    wd_assist->tt_contact = lt_contact.

    Endmethod.

    Cancel button: When the user want to cancel the change, I just refresh all the data which has beenstore in the assistance class, I didn't go to database yet.

    Method onaction_cancel.

    Refresh wd_assist->tt_contact.

    Refresh wd_assist->tt_customer.

    Refresh wd_assist->td_contact.

    Refresh wd_assist->td_customer.

    Endmethod.

  • 7/31/2019 High Performance Web System

    6/9

    save button: When the user decide the save the data at the end, then I let the assistance class toperform this job.

    Method onaction_save.

    Call method wd_assist->save_contact().

    Call method wd_assist->save_customer().

    Refresh wd_assist->tt_contact.

    Refresh wd_assist->tt_customer.

    Endmethod.

    Delete button: Now I'going to show you the popup window when the user wants to delete the data, Ijust want to remind the user what he's doing.

    Method onaction_delete.

    Data: lr_window_manager type ref to if_wd_window_manager,

    Lr_component_api type ref to if_wd_component,

    Lr_compcontroller type ref to ig_componentcontroller.

    Lr_compcontroller = wd_this->get_componentcontroller_ctr().

    Lr_component_api = wd_comp_controller->wd_get_api().

    lr_window_manager = lr_component_api->get_window_manager().

    Lr_compcontroller->mr_window = lr_window_manager->create_window(window_name= "POPUP").

    Lr_compcontroller->mr_window->open().

    Endmethod.

    In the delete button I want to get a popup window to ask the client that they want to delete the valuethey selected.

    First add public attribute mr_window type if_wd_window to component controller.

    add 2 trays and 2 tables of zcustomer and zcontact into layout popup view, the context node andbinding are the same as main view. I set the value of context node zcustomer and zcontact fromthe assistance class of data which the user had selected in the wddoinit method. This is also

    another way to show you the power of assistance.

    On the layout of popup view, I add textview under ROOTUIELEMENTCONTAINER, text ="Are yougoing to delete these data?".

    Add extra buttons yes, no and close on the bottom of layout, the close button I close only the popupwindow, not the whole application.

    Method onaction_yes.

  • 7/31/2019 High Performance Web System

    7/9

    Call method wd_assist->delete_customer().

    Call method wd_assist->delete_contact().

    refresh wd_assist->td_contact.

    Refresh wd_assist->td_customer.

    Endmethod.

    Method onaction_no.

    Refresh wd_assist->td_contact.

    Refresh wd_assist->td_customer.

    Endmethod.

    Method onaction_close.

    Data: lr_compcontroller type ref to ig_componentcontroller.

    Lr_compcontroller = wd_this->get_componentcontroller_ctr().

    Lr_compcontroller->mr_window->close().

    Endmethod.

    Exit the application: On the main view the user want to exit the whole application in the normal way,so I trigger the exit plug, if the user wants to visit somewhere, you can also add the url of thatapplication in the exit plug.

    Method onaction_exit.

    Data: lr_main_window type ref to ig_main.

    Lr_main_window = wd_this->get_main_window_ctr().

    Lr_main_window->fire_exit_plug_plg().

    Endmethod.

    Create transaction code for WDA

    The fact is the user can also call the application by transaction code as normal, I'll show you how todo that. First create the application z_wd_component_demo. Goto SE93, create transaction code

    z_wd_comp and description, choose option Transaction with parameters (Parametertransaction)>continue>create parameter transaction, in the Transaction field enter WDYID andselect the checkbox Skip initial screen. Add the necessary entries to the Default Values table byusing the F4 help. The values are automatically available after you enter WDYID in the Transactionfield. Add z_wd_component_demo in the application. Run the transaction z_wd_comp, you'll triggerthe WD.

    Create freely programmed value help by component usage

    I also created a input value help component to limit the value help for my input field company code.

  • 7/31/2019 High Performance Web System

    8/9

    This is just an example to show you how to create the programmed value help in case there is notsearch help on DDIC or, the search help offer the too much data. This component usage can bereused in any where if you want.

    Create z_wd_comp_sh with the interface iwd_value_help in the implemented interfaces tab, clickthe Reimplement button. The context T001 of the component is from table T001, cardinality 0:N,the selection context node is from interface iwd_value_help, also bind to table t001.

    Method supply_t001.

    Data: lt_t001 type if_componentcontroller=>elements_t001.

    *this selection is just an example, normally you should get the

    *value from assistance

    Select * from t001 into corresponding fields of table lt_t001

    Where bukrs = "A" or bukrs ="B" or bukrs = "C".

    If sy-subrc = 0.

    Node->bind_table(new_items = lt_t001).

    Endif.

    Endmethod.

    In the event tab of component controller, I defined the event data_selected, vh_window_openedand vh_window_closed as interface.

    Overwrite set_value_help_listener.

    Method set_value_help_listener.

    Wd_this->value_help_listener = listener.

    Endmethod.

    Overwrite do_copy method.

    Method onactiondo_copy.

    Data: lr_node type ref to if_wd_context_node,

    Lr_element type ref to if_wd_context_element,

    Ls_t001 type if_v_default=>element_t001,

    Ls_selection type if_v_default=>element_selection.

    Lr_node = wd_context->get_child_node('T001').

    Lr_element = lr_node->get_lead_selection(). Lr_element=>get_static_attributes(importingstatic_attributes = ls_t001).

  • 7/31/2019 High Performance Web System

    9/9

    Lr_node = wd_context->get_child_node('SELECTION').

    Lr_node->bind_structure(new_item = ls_t001).

    Wd_comp_controller->fire_data_selected_evt().

    Wd_comp_controller->value_help_listener->close_window().

    Endmethod.

    On the main component z_wd_component_demo, define the usage usage_sh in the usedcomponents tab of z_wd_comp_sh. Modify the main view add usage_sh in the property tab,change the input value help mode from search help to user-defined programming, input helpcomponent usage usage_sh. Add event handler method on_data_selected to data_selected ofusage_sh.

    Method on_data_selected.

    Data: lr_node type ref to if_wd_context_node,

    ls_input type if_main=>element_input,

    Ls_sel type if_v_default=>element_selection.

    Lr_node = wd_contex->get_child_node('SELECTION').

    Lr_node->get_static_attributes(importing static_attributes = ls_sel).

    Ls_input-bukrs = ls_sel-bukrs.

    Lr_node =wd_context->get_child_node('INPUT').

    Lr_node->bind_structure (new_item =ls_input).

    Endmethod.

    Add assistance class to sub component: For the more complicated situation, we have to split up thecomponent and add the sub component z_wd_component_sub into main componentz_wd_component_demo, and add the assistance into the sub component, add thez_wd_component_sub into component usage of z_wd_component_demo as sub.

    Over write the wddoinit method of z_wd_component_demo

    Method wddoinit.

    Data: lr_ui_usage type ref to if_wd_component_usage.

    Lr_ui_usage = wd_this->wd_cpuse_sub().

    If lr_ui_usage->has_active_component() is initial.

    Lr_ui_usage->create_component(assistance_class = wd_assist).

    Endif.

    Endmethod.