Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Setting a field in Select option

 

Step 1: Go to Tcode SE80 and Create a Webdynpro Component. Assign the component to the package or save it in the local object.

clip_image001

Step 2 : To the main Component, Add the component WDR_SELECT_OPTIONS in the used components tab. To use the functionality of the another webdynpro component it has to be added to our Component used components list where as if it is a standard interface it has to be added to the Implemented Interface.

clip_image002

Step 3: Add the interface controller of WDR_SELECT_OPTIONS in the view controller in which we need to use the select options. Doing so will create a method in the interface of the view and this method will return the object reference for the interface of the select options using which we can get the access to the select-option methods.
Click on the create controller usage button.

clip_image003

From the popup choose the interface controller of the select-options component.

clip_image004

clip_image005

Step 3: Go to Layout and insert View Container UI Element. This View Container UI Element is used to display the View of the other component into our View. Whenever we call the select options method and create a selection screen the output will be displayed in the view of the select options component. To display the output here in our view we need the screen into our view. For which we need view container to embed the view of the select options to our view.
Right click on the rootuielementcontainer and select insert element to insert a UI element in the view.

clip_image006

Provide the ID and Type for the UI element and press enter.

clip_image007

clip_image008

Step 4: Go to Window controller. Expand the Window. Right click on the Select_options(UI Container Created in previous step) and embed the view of the standard component(WDR_SELECT_OPTIONS) to be displayed in our window.

clip_image009

Press F4 help on the View to be embedded to choose the view.

clip_image010

Choose the view WND_SELECTION_SCREEN in which selection parameters will be displayed.

clip_image011
Press Enter after choosing the View.

clip_image012

You can see the view embedded to the view container.

clip_image013

Step 5: Now we have to write the coding in the WDDOINIT method to initialize the selection field on the screen. Go the method WDDOINIT of the View.Using Code Wizard generate the coding as mentioned below.

clip_image014

Step 6: First we need to Instantiate the Used Component to check for the active component usages. While adding the interface controller of the select option in the properties of the view two methods will be created in the interface for the views.
A method will be created with the naming convention wd_cpuse_ followed by the component name which we have given for select options. This method will return the object reference for the component usage using which we will check whether the component usage is active or not.
In Code wizard, general tab choose the option Instantiate Used component and select the select option which we added using the F4 Help.

clip_image015

Choose the  component select_options.

clip_image016

clip_image017

Code will be generated as below.

clip_image018

Step 7: To access the method of another component we need the object reference to the interface controller of the component. While adding the interface controller of the select options component to the view controller, a method will be created with the naming convention wd_cpifc followed by the component name which we provided for it. This method will returns the object reference for the interface controller of the select option.
Using code wizard choose the radio button method call in used controller and provide the component name using F4 help.

clip_image019

Double click on the select options component.

clip_image020

Now choose the method INIT_SELECTION_SCREEN which will return you the reference to the select options interface if_wd_select_options.

clip_image021

Select the method INIT_SELECTION_SCREEN.

clip_image022

clip_image023

Code will be generated as below.

clip_image024

The reference variable lv_r_helper_class will contain the object reference to the select options interface.

Step 8:
The interface if_wd_select_options contains a method called create_range_table which is used to create a range for the select option field.Using the ABAP Object pattern call the method Create table range from the interface we are using (IF_WD_SELECT_OPTIONS).

clip_image025

clip_image026

clip_image027

clip_image028

clip_image029

Code will be generated as below.

clip_image030

Replace me with object which refers to the interface IF_WD_SELECT_OPTIONS. Pass the Data element in the place of the type name and create a range table of type ref to data same as the receiving parameter RT_RANGE_TABLE.

Modify the code as below.

clip_image031

Call the Method add selection field using the same procedure as mentioned above to set the selection field on the screen.

clip_image032

Code will be generated as below.

clip_image033

Replace “me” with the object referring to the IF_WD_SELECT_OPTIONS. Pass the range table which we received from the returning parameter in the previous step.

clip_image034

Step 10 : Save and activate the component and create an application to test the component.

clip_image035

clip_image036

clip_image037

Output:

clip_image038

We have some default buttons here in the screen to disable this button go back to the method WDDOINIT do the following. Call the method set global options and set the buttons which you don’t need as ABAP_FALSE. Click on the pattern and choose abap object pattern, Enter the interface “IF_WD_SELECT_OPTIONS” and choose the method “SET_GLOBAL_OPTIONS”.

clip_image039

Code wizard will generate the following code.

clip_image040

Remove the comments and set the buttons you don’t need as ABAP_FALSE.

clip_image041

Here I had disabled the buttons check and execute. The Output will look like.

clip_image042

Codes in the WDDOINIT Method

 

* instantiate the used component.
data lo_cmp_usage type ref to if_wd_component_usage.
lo_cmp_usage
=   wd_this->wd_cpuse_select_options( ).
if lo_cmp_usage->has_active_component( ) is initial.
  lo_cmp_usage
->create_component( ).
endif.
* call the method in the used controller
data lo_interfacecontroller type ref to iwci_wdr_select_options .
  lo_interfacecontroller
=   wd_this->wd_cpifc_select_options( ).
   
data lv_r_helper_class type ref to if_wd_select_options.
    lv_r_helper_class
= lo_interfacecontroller->init_selection_screen(
   
).
*
* create the range table.
 
data rt_range_table type ref to data.
 
call method lv_r_helper_class->create_range_table
 
exporting

    i_typename    
= ‘ebeln’
*    i_length       =

*    i_decimals     =
  receiving
    rt_range_table
= rt_range_table.
* add selection field
 
call method lv_r_helper_class->add_selection_field
  
exporting

     i_id                        
= ‘ebeln’
*     i_within_block               = mc_id_main_block

*     i_description                =
*     i_is_auto_description        = abap_true
     it_result                   
= rt_range_table
     i_obligatory                
=
abap_true
*     i_complex_restrictions       =

*     i_use_complex_restriction    = abap_false
*     i_no_complex_restrictions    = abap_false
*     i_value_help_type            = if_wd_value_help_handler=>co_prefix_none
*     i_value_help_id              =
*     i_value_help_mode            =
*     i_value_help_structure       =
*     i_value_help_structure_field =
*     i_help_request_handler       =
*     i_lower_case                 =
*     i_memory_id                  =
*     i_no_extension               = abap_false
*     i_no_intervals               = abap_false
*     i_as_checkbox                = abap_false
*     i_as_dropdown                = abap_false
*     it_value_set                 =
     i_read_only                 
= abap_false
*     i_dont_care_value            =

*     i_explanation                =
*     i_tooltip                    =
*     i_is_nullable                = abap_true
*     i_format_properties          =
*     i_suggest_values             =
    
.
* set global options
  
call method lv_r_helper_class->set_global_options
 
exporting

    i_display_btn_cancel 
= abap_true
    i_display_btn_check  
=
abap_false
    i_display_btn_reset  
=
abap_true
    i_display_btn_execute
= abap_false 
.

About Arun

0 Comments:

Post a Comment

Powered by Blogger.