cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory Check on Drop Down Fields

Former Member
0 Kudos

Hi,

  I am relatively new with the Web Dynpro Development and during one of the developments, i have a requirement of setting Dropdown by Index Field Mandatory. For your information, The cardinality of the field is set to 0....n and i have tried the following options with no effect.

1. Set State property to "Required" and using cl_wd_dynamic_tool=>check_mandatory_attr_on_view

Could you please guide me or provide me with a sample code as to how to make a Dropdown Field have a mandatory check in Web Dynpro

Thanx....

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184578
Active Contributor
0 Kudos

Hi,

What is the first value(item) selected in your Drop Down by Index? You can read the drop down value and check if it is initial or not an then display an error.

* Read the drop down value using get_attribute( ) method

Then if lv_dd_val is not initial.

use report_attribute_error_message( ) method of message manager to display error and highlight the drop down.

hope this helps,

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

  By default, i have set it as blank. The main reason being that based on the selection from the drop down, corresponding data in other fields have to be populated.

I have tried using report_attribute_error_message( ). The problem i face using this is the  'ELEMENT' parameter where i am not able to read the context node of the drop down using get_element method.

Thanx...

former_member184578
Active Contributor
0 Kudos

Hi,

Try this code:


  DATA lo_nd_dd_node TYPE REF TO if_wd_context_node.

   DATA lo_el_dd_node TYPE REF TO if_wd_context_element.

   DATA lv_value  TYPE wd_this->element_node-value.

   DATA lo_api_controller     TYPE REF TO if_wd_controller.

   DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

  * dd_node is the name of Drop Down Node, replace with your node name

   lo_nd_dd_node = wd_context->get_child_node( name = wd_this->wdctx_dd_node ).

   lo_el_dd_node = lo_nd_dd_node->get_element( ). " Get DD context element

*  Read Drop Down value

   lo_el_node->get_attribute(

     EXPORTING

       name `VALUE`

     IMPORTING

       value = lv_value).

   IF lv_value IS INITIAL.

*Report Error

     lo_api_controller ?= wd_this->wd_get_api( ).

     CALL METHOD lo_api_controller->get_message_manager

       RECEIVING

         message_manager = lo_message_manager.

     CALL METHOD lo_message_manager->report_attribute_error_message

       EXPORTING

         message_text   = 'Your Message Here'

         element        =   lo_el_dd_node  " Context element of Drop Down Node

         attribute_name = 'VALUE'. " Attribute Name to which texts of DD is bound

ENDIF.

hope this helps u,

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

I now did a small work around. I added a initial line to the binding internal table of the drop down and have set the Lead_Selection_index of the initial line as default.

I then used your report_attribute_error_message code. Now the message is populating but i am not able to high light the drop down field as red.

I have set the correct attribute name but still it does not high light the field

Thanx....

former_member184578
Active Contributor
0 Kudos

Hi,

Did you passed the Element correctly? Please share your code.

Regards,

Kiran

Former Member
0 Kudos

Hi,

* Context Node Details

View Name: V_ENTRY

Context Node Name: N_NATURE_COMPL

Context Node Attribute: WRKDESC

*  Code Details

DATA: LV_NC_INDEX TYPE I.

DATA: LO_NCN_ELEMENT TYPE REF TO IF_WD_CONTEXT_ELEMENT. 

LO_NCN_ELEMENT = WD_THIS->NC_CONTEXT_NODE->GET_ELEMENT( ).

LV_NC_INDEX = WD_THIS->NC_CONTEXT_NODE->GET_LEAD_SELECTION_INDEX( ).

  IF LV_NC_INDEX = 6.

    LO_MESSAGE_MANAGER->REPORT_ATTRIBUTE_ERROR_MESSAGE(

                MESSAGE_TEXT        = 'Enter Nature of Complaint'

                ELEMENT                   = LO_NCN_ELEMENT

                ATTRIBUTE_NAME    = 'WRKDESC' ).

  ENDIF.

Former Member
0 Kudos

Hi Kiran,

pls ignore the previous post

* Context Node Details

View Name: V_ENTRY

Context Node Name: N_NATURE_COMPL

context Node Attribute: WRKDESC

*  Code Details

DATA: LV_NC_INDEX TYPE I.

DATA: LO_NCN_ELEMENT TYPE REF TO IF_WD_CONTEXT_ELEMENT. 

LO_API_CONTROLLER ?= WD_THIS->WD_GET_API( ).

  CALL METHOD LO_API_CONTROLLER->GET_MESSAGE_MANAGER

    RECEIVING

      MESSAGE_MANAGER = LO_MESSAGE_MANAGER.

LO_NCN_ELEMENT = WD_THIS->NC_CONTEXT_NODE->GET_ELEMENT( ).

LV_NC_INDEX = WD_THIS->NC_CONTEXT_NODE->GET_LEAD_SELECTION_INDEX( ).

  IF LV_NC_INDEX = 6.

    LO_MESSAGE_MANAGER->REPORT_ATTRIBUTE_ERROR_MESSAGE(

                MESSAGE_TEXT      = 'Enter Nature of Complaint'

                ELEMENT           = LO_NCN_ELEMENT

                ATTRIBUTE_NAME    = 'WRKDESC' ).

  ENDIF.

Former Member
0 Kudos

Hi Kiran,

  For your info, we have NW 7.02 with EHP3.

  Is there any note update v need to do

Regards

Ekalavya

former_member184578
Active Contributor
0 Kudos

Hi,

You code looks correct. Does NC_CONTEXT_NODE has the context node N_NATURE_COMPL reference which was initialized prior?

Try reading the attribute WRKDESC using get_attribute( ) method ( using code wizard) and check.

Regards,

Kiran

former_member184578
Active Contributor
0 Kudos

Hi,

There are no notes available for this issue. You may have to implement the 'Unified Rendering Corrections 702' relevant to your Support Pack version ( for ex: SAP Note 1785035/ 1785035 .. so on) which may fix the issue.

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

   I tried the following options based on your suggestion.

1. I used the get_attribute method as suggested by u and i was able to fetch the value for the attribute WRKDESC sucessfully.

2. I later changed the cardinality of node N_NATURE_COMPL to 1...1, deleted the drop down by index and created an input field and assigned the attribute WRKDESC to the input field. I then used the get_attribute and the REPORT_ATTRIBUTE_ERROR_MESSAGE. I was able to generate the error message as well as highlight the field in red.

Thanx

Regards

Ekalavya

Former Member
0 Kudos

Hi,

Can we check it ourselves or do v need to take the help of the basis team.

if v an check it ourselves, how cn v do it.

Regards

Ekalavya

former_member184578
Active Contributor
0 Kudos

Hi,

As you said, it's working for Input field but not for Drop down, you need to implement the relevant unified correction for your netweaver version or import the latest support pack.  You can check the Unified correction notes in service market place - http://service.sap.com/notes

hope this helps,

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

Thank you for all the help....I will check the notes and will co-ordinate with the basis team...

Regards

Ekalavya