cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check these data whether valid ?

Former Member
0 Kudos

Hi,experts,

I need check fields wheter valid in the webdynpro for abap application.

action:

1. In the context, I config 200 attributes for binding 200 fields with f4 help in the main_view.

2. Create fields(200) which every field bind attribute in the view(main_view) in the WDA .

3. When run the application, I need check these data whether valid after users clicked the save button for saving these attributes.

Now, if the user type error data,and then click the save button , the WDA will down.

The following is code:

METHOD onactionsave_addr_data .

DATA lo_nd_ee_test TYPE REF TO if_wd_context_node.

DATA lo_el_ee_test TYPE REF TO if_wd_context_element.

DATA ls_ee_test TYPE wd_this->element_ee_test.

DATA return TYPE bapireturn1.

lo_nd_ee_test = wd_context->get_child_node( 'EE_TEST' ).

lo_el_ee_test = lo_nd_ee_test->get_element( ).

lo_el_ee_test->get_static_attributes(

IMPORTING

static_attributes = ls_ee_test ).

CALL FUNCTION 'Z_HR_ESS_CREATE_INFOTYPE_0006'

EXPORTING

pernr = item_pernr

sub_1_ty1 = ls_ee_test-sub_1_ty1

sub_2_ty2 = ls_ee_test-sub_1_ty1

sub_3_ty3 = ls_ee_test-sub_1_ty1

sub_4_ty4 = ls_ee_test-sub_1_ty1

......

sub_200_ty200 = ls_ee_test-sub_200_ty200

IMPORTING

return = return.

ENDMETHOD.

Problem:

How can I check these data !!whether valid!! through config these context or type code in the WDA?

Best regards,

Tao

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

lr_validation is an instance of the interface IF_WD_VALIDATION. so you do not need to create an object, alternatively you can call the method like if_wd_validation~is_attribute_valid() and the return value is of abap_bool type..

regards,

srini gollakaram..

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> hi,

>

> lr_validation is an instance of the interface IF_WD_VALIDATION. so you do not need to create an object, alternatively you can call the method like if_wd_validation~is_attribute_valid() and the return value is of abap_bool type..

>

> regards,

>

> srini gollakaram..

Your advice is incorrect in that the IS_ATTRIBUTE_VALID does not do what you say - check my thread above. Also what you post doesn't even make sense. How exactly do you expect to call if_wd_validation~is_attribute_valid since it is an interface. You need an object instance of a class. Please refrain from posting blaintantly incorrect information.

Former Member
0 Kudos

Dear Thomas,

Thanks a lot for your help in advance.

I finished the method which I write the code in a assistant class as your hint for checking the data validation.

And then, My WDA invoke the method which is in the assistant class when user click the save button in the main_view.

Thanks again for your help!

Best regards,

Tao

Answers (3)

Answers (3)

Former Member
0 Kudos

hi,

we had better take suggestions from Thomas jung to overcome the above problem.. I have seen his demos which are all quite interesting... waiting for thomas's solution for the above problem...

srini

Former Member
0 Kudos

hi,

If you have to validate the user input fields ,try the following interface which is

data: lr_validation TYPE REF TO if_wd_validation,

lr_attribute_valid TYPE abap_bool.

lr_attribute_valid = lr_validation->is_attribute_valid( element = lr_element

attribute_name = ' NAME OF YOUR BOUND ATTRIBUTE ')

IF lr_attribute_valid EQ abap_false.

DISPLAY ERROR MESSAGE*****

ENDIF.

hope this would be helpful..

regards,

Srini gollakaram

Former Member
0 Kudos

Hi,

Thanks a lot for your help!

Do you tell me how to create the lr_validation object?

Thanks again.

Best regards,

tao

Former Member
0 Kudos

Dear,Srini,

Thanks a lot for your help!

I try to using the code:

data: lr_validation TYPE REF TO if_wd_validation,

lr_attribute_valid TYPE abap_bool.

Create object lr_validation.

lr_attribute_valid = lr_validation->is_attribute_valid(

element = lr_element

attribute_name = 'SUB_1_TY1' ).

IF lr_attribute_valid EQ abap_false.

DISPLAY ERROR MESSAGE*****

ENDIF.

But the system tell me "lr_validation is not object reference".

I don't know how to create the object: lr_validation.

Do your give me some hint? Thanks again.

Thanks again.

Best regards,

tao

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

First of all, I don't really appreciate that you sent me this exact same question via direct email this morning and didn't mention that it was also posted on the SDN Forums. In the future it would be most polite if you inform someone that you also posted a question to SDN so that they can answer it there and perform duplicate work that can't be searched by others.

As I told you in the email, the method HAS_VAL_ERRORS_FOR_WINDOW will not work because it doesn't before the validation. It only checks the message manager to see a message has been placed in the queue.

The method is_attribute_valid is also part of the message manager and appears to be similar. It only checks the message manager queue to see if anything has been placed in there for a particular attribute. It doesn't do a domain value check as you are looking for. I know of no framework API that will perform the domain check for you - especially if this is a DDic value help domain and not a simple domain. I only know of the API that will check for mandatory fields. Everything else it would seem is the responsibility of the application developer to code at the model level.

Former Member
0 Kudos

Dear, Thomas,

I am very sorry. I hope to solve the problem as soon as possible, So I give you email after I post the massage.

I think you are right, and I will finish the WDA as your hint. But I am really unhappy to write the code "Select * from table_name where fields_name = attribute_value" in my WDA.

I apologize again.

Best regards,

tao

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> But I am really unhappy to write the code "Select * from table_name where fields_name = attribute_value" in my WDA.

> tao

I know that it isn't exactly what you meant - but this logic shouldn't be in your WDA at all. It should be in a model object (Assistance Class or some other service object). Perhaps you can write something very generic, but imagine that this will only work for very basic data dictionary domains. Otherwise you are going to have to perform SQL against the check tables themselves - just not in the WDA itself hopefully.

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi

you want to validate your context before saving.

write code in WDDOBEFOREACTION method of your view, which is called before every event handler execution.

Read your attribute and perform validation and if the data is incorrect through an error message.

to show Error Message this code is useful.

data: l_current_controller type ref to if_wd_controller,

l_message_manager type ref to if_wd_message_manager.

l_current_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD l_current_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = l_message_manager

.

  • report message

CALL METHOD l_message_manager->REPORT_ERROR_MESSAGE

EXPORTING

MESSAGE_TEXT = 'Error Message'

.

Abhi

Former Member
0 Kudos

Hi, Abhi,

Thanks a lot for your hint in advance.

I type the code as above in the method WDDOBEFOREACTION. But when I run the WDA, I found the error message is throw as if the typed data is valid.

and then, I change your code:

WDDOBEFOREACTION.

data l_current_controller type ref to if_wd_controller.

data l_message_manager type ref to if_wd_message_manager.

DATA isempty TYPE wdy_boolean.

l_current_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD l_current_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = l_message_manager

.

CALL METHOD l_message_manager->HAS_VAL_ERRORS_FOR_WINDOW

RECEIVING

HAS_VALIDATION_ERRORS = isempty.

IF isempty = abap_true.

CALL METHOD l_message_manager->REPORT_ERROR_MESSAGE

EXPORTING

MESSAGE_TEXT = 'Error Message'

endif.

endmethod.

But the method METHOD l_message_manager->HAS_VAL_ERRORS_FOR_WINDOW don't work.

Do you give me some hint? thanks a lot.

Best regards,

tao