cancel
Showing results for 
Search instead for 
Did you mean: 

Stoping mandatory fields

Former Member
0 Kudos

Hi Experts,

I know in WD abap i can check the mandatory fields using folowing method which i found in one of the thread......

cl_wd_dynamic_tool=>check_mandatory_attr_on_view(

EXPORTING

view_controller = lo_view_controller

display_messages = abap_true

IMPORTING

messages = lt_msg ).

But problem is that it is just displaing me an error message without stoping furthur navigation......

wht i m doing is i have a search button, when i click on that button i have to check mandatory fields and if mandatory fields are not filled i have to stop furthur processing...... i m using above code for that....... i think i missing something...... i tried searching it but have not got solution yet.......

regards

Amit

Accepted Solutions (1)

Accepted Solutions (1)

pranav_nagpal2
Contributor
0 Kudos

Hi Amit,

Check this code after checking for mandatory fields you have to just loop at the msg_tab it is like an internal table if you try to see it using a break point...... i hope this will solve your issue........

 data:lo_view_controller type ref to if_wd_view_controller,
       lv_flag type i,
        msg_tab type cl_wd_dynamic_tool=>t_check_result_message_tab.

  field-symbols: <lv_fs> type any.

  lo_view_controller = wd_this->wd_get_api( ).



  cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
  exporting
    view_controller = lo_view_controller
    display_messages = abap_true
    importing
      messages = msg_tab ).

loop at msg_tab assigning <lv_fs>.
  if <lv_fs> is initial.
  exit.
  elseif <lv_fs> is not initial.
  lv_flag = 3.
  endif.
endloop.
 check lv_flag ne 3.

data lo_componentcontroller type ref to ig_componentcontroller .
lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).

  lo_componentcontroller->methupdate(
  ).

regards

Pranav

Former Member
0 Kudos

Hi All,

Thanks for your reply.....

@Pranav:- it was very helpful reply but now problem is that i want to display message depending on the field which is not filled. like say i have 3 fields X, Y and Z now say if X is empty i want to display message X is mandatory similarly for Y and Z...... please tell me how to over write the message displayed by SAP by default...

@Bala:- In the link you have provided there is a reply from Kishan... is that similar to checking all the fields for null or initial values......... i m new to WD ABAP i didnt get that code if you can throw some light on it....

Regards

Amit

Former Member
0 Kudos

Amit,

you can write your own message like this

use the code wizard and read the context attribute fr which u want to check the initial value

  • 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.

you need to do this for every field

  • if lv_x is the variable that holds the attribute value

if lv_x is initial.

  • report message

CALL METHOD lo_message_manager->REPORT_ERROR_MESSAGE

EXPORTING

MESSAGE_TEXT = 'lv_x is initial'.

endif.

Thanks

Bala Duvvuri

arjun_thakur
Active Contributor
0 Kudos

Hi Amit,

I don't think displaying seprate msg for each and every field would be possible using cl_wd_dynamic_tool=>check_mandatory_attr_on_view. If you want to display seprate msgs, then you should check each and every field individually.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi Bala,

I m using the code given by Pranav. i put a break point on <lv_fs> and it hae a variable named attribute_name which contains the name of the context attribute.... but when i tried using it to display the message depending on the field which is empty it is giving me an error that <lv_fs> doesnot contain any such structure... so now the problem is i dont know which field user has left blank.......

regards

Amit

pranav_nagpal2
Contributor
0 Kudos

Hi Amit,

you have to made some changes in code thn.....

declare an internal table and work area this way.....

types:
    begin of t_check_result_message,
      t100_message      type symsg,
      context_element   type ref to if_wd_context_element,
      attribute_name    type string,
    end of t_check_result_message .


    Data msg_tab type standard table of t_check_result_message .

data wa_msgtab TYPE t_check_result_message.

now loop at msg_tab INTO wa_msgtab.

this work area will now contain the field you are looking for.........

but here also you will get the context attribute name.... now put some "if" condition or "case" and you can display the message.... before that in check_mandatory_attr_on_view you have to pass DISPLAY_MESSAGES = ABAP_FALSE.....

regards

Pranav

Answers (3)

Answers (3)

Former Member
0 Kudos

THANKSSSS A LOT EVERYONE..............

Solved...........

arjun_thakur
Active Contributor
0 Kudos

Hi Amit,

I would suggest you to make a flag variable. Now if your code for checking mandatory fields returns an error, set the flag variable to '1'. After that write this line of code:

CHECK lv_flag IS INITIAL.

THis code will allow further execution only if the flag varaible is initial.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Amit,

you may want to check this thread

https://forums.sdn.sap.com/click.jspa?searchID=20183234&messageID=6646145

Thanks

Bala Duvvuri