cancel
Showing results for 
Search instead for 
Did you mean: 

Strange problem with manditory fields

Former Member
0 Kudos

Hi,

I am making 3 fields manditory dynamically based on condition..

button1 selection : field 1 and field 2 should be mandatory and field 3 not

button2 selection : field 1 and field 2 no mandatory and field 3 is mandatory.

When i am selecting both buttons...Mandatory field mark ( *) coming correct.

But when i am saving with save button...it is asking input value for field which is not mandatory...

There is no * symbol to that field also...but still it is asking input value.

If anybody know solution please provide me...

Thanks,

Subba

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You should bind the inputfield to context attributes of type string and check if it is INITIAL OR NOT and then give the messages accordingly using the Message Manager.

For the Asterisk you should set the 'state' property accordingly.

Thanks,

Former Member
0 Kudos

Hi Shikil,

Thanks for reply...

I can't change data type of the field...Since all fields are directly mapped to standard data base tables...If i change data will

not be save in database....

Regards,

Subba

Former Member
0 Kudos

So use the following code:

First get the value of the field by getting the value of the context attribute as:

DATA lo_nd TYPE REF TO if_wd_context_node.

DATA lo_el TYPE REF TO if_wd_context_element.

DATA ls_el TYPE wd_this->Element_<nodename>.

DATA lv TYPE wd_this->Element_<nodename>-<attribute-name>.

  • navigate from <CONTEXT> to <Node> via lead selection

lo_nd_n_upload = wd_context->get_child_node( name = wd_this->wdctx_<nodename>).

  • get single attribute

lo_el_n_upload->get_attribute(

EXPORTING

name = `<attribute-name>`

IMPORTING

value = lv ).

Then check if the value is blank, call the Message Manager:

if lv IS INITIAL.

get message manager

data lo_api_controller type ref to if_wd_controller.

data lo_message_manager type ref to if_wd_message_manager.

lo_api_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = lo_message_manager

.

  • report message

CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_EXCEPTION

EXPORTING

MESSAGE_OBJECT =

ELEMENT =

ATTRIBUTE_NAME =

  • MSG_USER_DATA =

  • MESSAGE_TYPE = CO_TYPE_ERROR

  • IS_PERMANENT = ABAP_FALSE

  • SCOPE_PERMANENT_MSG = CO_MSG_SCOPE_CTXT_ELEMENT

  • MSG_INDEX =

  • CANCEL_NAVIGATION =

  • IS_VALIDATION_INDEPENDENT = ABAP_FALSE

  • ENABLE_MESSAGE_NAVIGATION =

  • VIEW =

RECEIVING

MESSAGE_ID =

and send the message to display to the user.

Hope it helps

Former Member
0 Kudos

Hi Shikal,

What are the parameters i need to pass this method..

CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_EXCEPTION

Thanks,

Subba

gill367
Active Contributor
0 Kudos

Instead of just making the field mandatory using the utility class write the logic in the eventhandler of the save button to check

if hte value has been entered or not.

the save button check for the values of the fields and if it is initial then throw the message.

>

> Hi Shikal,

>

> What are the parameters i need to pass this method..

>

> CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_EXCEPTION

>

> Thanks,

> Subba

and use REPORT_ATTRIBUTE_ERROR_MESSAGE instead.

* report message
CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_ERROR_MESSAGE
  EXPORTING
    MESSAGE_TEXT              =    'ERROR MESSASGE '   " message text that you want to display to the user
    ELEMENT                   =      lo_el_n_upload   " pass the context element which belongs to ur attribute
    ATTRIBUTE_NAME            =   `<attribute-name>`  "pass the attribute name here

    .

thanks

sarbjeet singh