Sunday, December 19, 2010

OVS help in the Web Dynpro application

In one of my Scenarios, I’ve to get the Job Id and Job Description from the Database Table for Creating a Position in the Organizational Structure. I have provided the Object Value Selector (OVS) which takes Job Id and Job Description with ‘*’ (For Exact Selection it is not necessary to Use ‘*’) as input and list out all the Job Id and Job Descriptions corresponding to that Selections. On selecting one of the Entries from the Output List, the corresponding Job Id and Job Description will get displayed in the Screen.

Introduction About Object Value Selector

Generic help like value help can only be used for the field to which it is binded i.e. its scope is limited to that structure to which it is binded. But there are scenarios where we need a search help that allow multiple input fields to be populated or take multiple fields for search criteria. In this case, OVS comes into picture. OVS provide us with the selection screen that can contain multiple input fields to which our selection criteria can be restricted and displaying results values that can be used to populate different input fields.

OVS makes use of the PHASE MODEL. We have two components in picture: OVS component and Consumer component. At certain point of time, OVS Component requires some information from consumer component. For this, OVS component fires OVS event.

The parameter PHASE_INDICATOR is used to indicate the type of information requested. An event handler method in the consumer component subscribes to the OVS event and collects the information requested. For handling back this information to the OVS component, it makes use of certain methods in the OVS component. The reference to the object OVS_CALLBACK_OBJECT containing these methods is provided by the OVS event. These methods include: SET_CONFIGURATION (), SET_INPUT_STRUCTURE (), SET_OUTPUT_TABLE ().

Phase_Indicator has four phases: Phase 0,1,2,3.

For Detail about different phases, you can go through the link.

http://help.sap.com/saphelp_erp2005/helpdata/en/30/d7fa41c915da6fe10000000a1550b0/content.htm

Procedure:

1. Create one Webdynpro Component with name ZWA_OVS_JOB.

2. Press Enter.

3. Declare the WDR_OVS Component in the used component list in your WD component as shown below.

4. Now go to the View, in the Properties Tab click the Create Controller Usage Button.

5. It will open a screen with Component Use Entries. There select the Component Use OVS with Interface Controller as shown below. Press Enter.

6. It will display as follows in the View Properties.

7. Go to the Context Tab, Right Click the Context and select Create à Attribute.

8. Give Attribute Name as JOB_ID with Type SHORT_D. In the Input Help Mode Field, Select ‘Object Value Selector’ from the dropdown. Then press F4 in the Field OVS Component Usage.

9. It will open a Pop-up. Select OVS and press Enter.

10. Press Enter.



11. Create another Attribute with Name JOB_DESC and Type STEXT.

12. In the Layout Tab of the View, Right click the ROOTUIELEMENTCONTAINER and give Insert Element. It will open a Pop-Up for Creating an Element.

13. Enter LABEL_JOBID in the Name Field and Select Label in the Type Field and Press Enter.

14. Create another UI Element with INPUT_JOBID in the Name Field and Select InputField in the Type Field and Press Enter.

15. Create another UI Element with TEXT_JOBDESC in the Name Field and Select TextView in the Type Field and Press Enter.

16. In the Label Properties, Select INPUT_JOBID from the Dropdown for the labelfor Field and Enter ‘Job Id in the Text Field.

17. Create Context binding For the INPUT_JOBID by Clicking the Button in the Right Side of the value in the Properties. It will open a Popup with the Context Element. In that Select the Attribute JOB_ID and Press Enter.

18. Then Create Context binding For the TEXT_JOBDESC by Clicking the Button in the Right Side of the text in the Properties. It will open a Popup with the Context Element. In that Select the Attribute JOB_DESC and Press Enter.

19. Declare one event handler method with Name ON_OVS in the Method tab of the view. Then Press F4 in the Column Event.

20. Select the Event OVS as shown below and Press Enter.



21. Double Click the Method ON_OVS and write the Following Coding.

ON_OVS
method ON_OVS .
* declare data structures for the fields to be displayed and
* for the table columns of the selection list, if necessary
types:
begin of lty_stru_input,
* add fields for the display of your search input here
job_id type string,
job_desc type string,
end of lty_stru_input.
  types:
begin of lty_stru_list,
* add fields for the selection list here
short type short_d,
stext type stext,
end of lty_stru_list.
  data: ls_search_input  type lty_stru_input,
lt_select_list type standard table of lty_stru_list,
ls_text type wdr_name_value,
lt_label_texts type wdr_name_value_list,
lt_column_texts type wdr_name_value_list,
lv_window_title type string,
lv_group_header type string,
lv_table_header type string.
  field-symbols:  type lty_stru_input,
type lty_stru_list.
  DATA : lv_short TYPE string,
lv_stext TYPE string.
  case ovs_callback_object->phase_indicator.
    when if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted
* in this phase you have the possibility to define the texts,
* if you do not want to use the defaults (DDIC-texts)
      ls_text-name = `JOB_ID`.  "must match a field name of search
ls_text-value = `Job Abbr`.
INSERT ls_text INTO TABLE lt_label_texts.
      ls_text-name = `JOB_DESC`.  "must match a field name of search
ls_text-value = `Job Description`.
INSERT ls_text INTO TABLE lt_label_texts.
      ls_text-name = `SHORT`.
ls_text-value = `Job Abbr`.
INSERT ls_text INTO TABLE lt_column_texts.
      ls_text-name = `STEXT`.
ls_text-value = `Job Description`.
INSERT ls_text INTO TABLE lt_column_texts.
      ovs_callback_object->set_configuration(
label_texts = lt_label_texts
column_texts = lt_column_texts
group_header = 'Job Abbreviation'
col_count = 2
row_count = 10 ).
    when if_wd_ovs=>co_phase_1.  "set search structure and defaults
*   In this phase you can set the structure and default values
* of the search structure. If this phase is omitted, the search
* fields will not be displayed, but the selection table is
* displayed directly.
* Read values of the original context (not necessary, but you
* may set these as the defaults). A reference to the context
* element is available in the callback object.
      ovs_callback_object->context_element->get_static_attributes(
importing static_attributes = ls_search_input ).
*     pass the values to the OVS component
ovs_callback_object->set_input_structure(
input = ls_search_input ).
    when if_wd_ovs=>co_phase_2.
* If phase 1 is implemented, use the field input for the
* selection of the table.
* If phase 1 is omitted, use values from your own context.
      if ovs_callback_object->query_parameters is not bound.
******** TODO exception handling
endif.
assign ovs_callback_object->query_parameters->*
to .
      if not  is assigned.
******** TODO exception handling
endif.
*     call business logic for a table of possible values
* lt_select_list = ???
      lv_short = -job_id.
lv_stext = -job_desc.
      REPLACE ALL OCCURRENCES OF '*' IN lv_short WITH '%' .
REPLACE ALL OCCURRENCES OF '*' IN lv_stext WITH '%' .
      IF lv_short NE ' ' AND lv_stext NE ' '.
        SELECT short stext  FROM hrp1000 INTO TABLE lt_select_list
WHERE plvar = '01' AND otype = 'C' AND langu = 'EN' AND
endda GE sy-datum AND ( short LIKE lv_short AND
stext LIKE lv_stext )
ORDER BY short ASCENDING.
      ELSEIF lv_short EQ ' ' AND lv_stext NE ' '.
        SELECT short stext FROM hrp1000 INTO TABLE lt_select_list
WHERE plvar = '01' AND otype = 'C' AND langu = 'EN' AND
endda GE sy-datum AND stext LIKE lv_stext
ORDER BY short ASCENDING.
      ELSEIF lv_short NE ' ' AND lv_stext EQ ' '.
        SELECT short stext FROM hrp1000 INTO TABLE lt_select_list
WHERE plvar = '01' AND otype = 'C' AND langu = 'EN' AND
endda GE sy-datum AND short LIKE lv_short
ORDER BY short ASCENDING.
      ENDIF.
      ovs_callback_object->set_output_table( output = lt_select_list ).
    when if_wd_ovs=>co_phase_3.
* apply result
      if ovs_callback_object->selection is not bound.
******** TODO exception handling
endif.
      assign ovs_callback_object->selection->* to .
      if  is assigned.
ovs_callback_object->context_element->set_attribute(
name = `JOB_ID`
value = -short ).
        ovs_callback_object->context_element->set_attribute(
name = `JOB_DESC`
value = -stext ).
      endif.
endcase.
endmethod.

22. Save the Application and Activate the Component.

23. Create Webdynpro Application, save it and Test the Application.

Output:

1. Press F4 in the Field Job Id. It will open a Pop-up.

2. Enter the Value with ‘*’ and Click on Start Search Button. It will display all the possible Entries corresponding to that Selection. If you want Exact Selection then no need to give ‘*’.

3. On selecting one of the Job Abbr and Clicking the Ok Button, the Job Id and its Description will be displayed in the Screen as follows.

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites