cancel
Showing results for 
Search instead for 
Did you mean: 

Using Select options how to validate

former_member198064
Participant
0 Kudos

Hi Experts,

I am using webdynpro abap component select options.In select options i am using vbeln field i want to validate the entered value.How to validate it.Can give me for this solution is there any example provide me.

Accepted Solutions (0)

Answers (1)

Answers (1)

ChandraMahajan
Active Contributor
0 Kudos

Hi,

you need to retrieve the value of vbeln from select option and then put the code to validate it.

below is the code to read MATNR value. On simmilar lines write the code to read VBELN in the button event method and then validate it as usual.


* retrieve the date data from select option
  rt_matnr =
    wd_this->m_handler->get_range_table_of_sel_field(
       i_id           = 'MATNR' ).

* Assign this to a field symbol
  ASSIGN rt_matnr->* TO <fs_matnr>.

* Create dynamic work area and assign to FS
  CREATE DATA l_data LIKE LINE OF <fs_matnr>.
  ASSIGN l_data->* TO <fs_any>.
  LOOP AT <fs_matnr> INTO <fs_any>.
    ASSIGN COMPONENT 'SIGN' OF STRUCTURE <fs_any> TO <fs_field>.
    IF sy-subrc = 0 .
      ls_matnr-sign = <fs_field>.
    ENDIF.                             " IF sy-subrc = 0 .
    ASSIGN COMPONENT 'OPTION' OF STRUCTURE <fs_any> TO <fs_field>.
    IF sy-subrc = 0 .
      ls_matnr-option = <fs_field>.
    ENDIF.                             " IF sy-subrc = 0 .
    ASSIGN COMPONENT 'LOW' OF STRUCTURE <fs_any> TO <fs_field>.
    IF sy-subrc = 0 .
      ls_matnr-low = <fs_field>.
    ENDIF.                             " IF sy-subrc = 0 .
    ASSIGN COMPONENT 'HIGH' OF STRUCTURE <fs_any> TO <fs_field>.
    IF sy-subrc = 0 .
      ls_matnr-high = <fs_field>.
    ENDIF.                             " IF sy-subrc = 0 .
    APPEND ls_matnr TO lt_matnr.
    CLEAR ls_matnr.
  ENDLOOP.                             " LOOP AT <fs_matnr> INTO <fs_any>.

**Once you get the values in internal table (lt_matnr) in this case, validate it  and then display error message accordingly

Thanks,

Chandra

former_member198064
Participant
0 Kudos

Hi Chandra sekhar ,

Can you give me the clear idea for validation.I have done initially in wddoinit

method WDDOINIT .
* Reference variable used instantiate the select-options component
DATA
lr_cmp_usage TYPE REF TO if_wd_component_usage.

* Variables used to create the select-options fields and
* define its initial values
DATA:
lr_field TYPE REF TO data.

FIELD-SYMBOLS:
<fs_field> TYPE ANY,
<fs_range> TYPE INDEX TABLE.

* Instantiate the select-options component
lr_cmp_usage = wd_this->wd_cpuse_cmp_sel_opt( ).
IF lr_cmp_usage->has_active_component( ) IS INITIAL.
lr_cmp_usage->create_component( ).
ENDIF.

* Sets the helper reference
wd_this->m_sel_opt = wd_this->wd_cpifc_cmp_sel_opt( ).
wd_this->m_helper = wd_this->m_sel_opt->init_selection_screen( ).

* Hide the standard select-options components.
wd_this->m_helper->set_global_options(
i_display_btn_cancel = abap_false
i_display_btn_check = abap_false
i_display_btn_reset = abap_false ).

* Adding a block (type Tray) to the select-options
wd_this->m_helper->add_block(
i_id = `BL01`
i_block_type = if_wd_select_options=>mc_block_type_tray
i_title = `Flight Booking` ).

* Adding a parameter field to the created block
* Create a reference to the type of airline code
CREATE DATA lr_field TYPE s_carr_id.

* Sets the airline code initial value
ASSIGN lr_field->* TO <fs_field>.
<fs_field> = 'AA '.

* Add the parameter to the group
wd_this->m_helper->add_parameter_field(
i_id = `CARRID`
i_within_block = `BL01`
i_value = lr_field ).
FREE lr_field.
UNASSIGN <fs_field>.

* Adding a select-options field to the created block
* Create a reference to the connection number range table
lr_field = wd_this->m_helper->create_range_table( `S_CONN_ID` ).

* Add the select-option to the group
wd_this->m_helper->add_selection_field(
i_id = `CONNID`
i_within_block = `BL01`
it_result = lr_field ).
FREE lr_field.
endmethod.

and in button i have done as

method ONACTIONON_EXECUTE .
  TYPES:
lty_r_connid TYPE RANGE OF s_conn_id.

DATA
lr_sbook TYPE REF TO if_wd_context_node.

* Variables used to retrieve the values of select-options fields
DATA
lt_sel_item TYPE if_wd_select_options=>tt_selection_screen_item.
FIELD-SYMBOLS:
<fs_sel_item> LIKE LINE OF lt_sel_item,
<fs_carrid> TYPE s_carr_id,
<fs_connid> TYPE lty_r_connid.

* Get the selection-screen items
wd_this->m_helper->get_selection_screen_items(
IMPORTING et_selection_screen_items = lt_sel_item ).

* Retrieve the values from the select-options items
LOOP AT lt_sel_item ASSIGNING <fs_sel_item>.
CASE <fs_sel_item>-m_id.
WHEN `CARRID`.
ASSIGN <fs_sel_item>-m_value->* TO <fs_carrid>.
WHEN `CONNID`.
ASSIGN <fs_sel_item>-mt_range_table->* TO <fs_connid>.
ENDCASE.
ENDLOOP.

* Retrieve the data from the database, for simplicity, the
* SELECT statement has been implemented here.
SELECT * FROM sbook
INTO TABLE wd_this->t_sbook
WHERE carrid = <fs_carrid>
AND connid IN <fs_connid>.

* Bind the data to the context
lr_sbook = wd_context->get_child_node( name = `T_SBOOK`).
lr_sbook->bind_table( wd_this->t_sbook ).

endmethod.

now can you provide me the code for carrid and connid validation how has to be done.Please give me this solution

ChandraMahajan
Active Contributor
0 Kudos

Hi,

Refer my earlier code and also look into below thread

Once you get the entries from select option into your internal table, you can validate it against the master table (or for other checks) and display error message (for e.g Matetrial is not Valid etc).

Thanks,

Chandra