Quantcast
Channel: SCN : All Content - Web Dynpro ABAP
Viewing all articles
Browse latest Browse all 3667

How to Report one attribute error message for multiple fields in Web Dynpro ABAP

$
0
0

Purpose:

Application for describing the procedure to report an attribute error message for multiple fields  in the given context element

 

Scenario:

I would like to explain the functionality of how to report an attribute error message for multiple fields during validations.


Usually, we report  attribute error message per attribute but for the requirement to show single attribute error message for many input fields cannot be achieved by using REPORT_ATTRIBUTE_ERROR_MESSAGE( ) method, this document guides through the process of achieving the requirement by using method REPORT_ELEMENT_ERROR_MESSAGE( )

 

Pre-requisite:

Basic knowledge of Webdynpro ABAP,& OO ABAP

 

Step by step Process


Step1:

 

Go to t-code SE80, and create web dynpro component with a view V_MAIN & window W_MAIN as below

1.PNG

Step2:

 

Go to the context tab of view V_MAIN and create a node INPUT with attributes as shown below

 

Note: I have chosen the attributes from table PA0001 - for demo purpose

2.PNG

 

Step3:

 

Now, we need to create form container with input fields.

 

Go to layout tab of view V_MAIN and right click on ROOTUIELEMENTCONTAINER as below

3.png

 

Step 4:

Choose context node INPUT and check the "Create Form in New Container" and also choose all attributes and click on "OK" as shown below

4.PNG

 

Step 5:

 

Create a button and assign an action for the event OnAction as shown below

5.PNG

 

Step 5.1:

 

Now, go to WDDOBEFOREACTION( ) method of view V_MAIN and write the below code

 

WDDOBEFOREACTION( )

METHOD wddobeforeaction .

  DATA lo_api_controller       TYPE REF TO if_wd_view_controller.

  DATA lo_action               TYPE REF TO if_wd_action.

  DATA lo_message_manager     TYPE REF TO if_wd_message_manager.

  DATA lt_attributes           TYPE string_table.

  DATA lo_nd_input TYPE REF TO if_wd_context_node.

  DATA lo_el_input TYPE REF TO if_wd_context_element.

  DATA ls_input TYPE wd_this->element_input.

 

 

  lo_api_controller = wd_this->wd_get_api( ).

  lo_action = lo_api_controller->get_current_action( ).

 

  IF lo_action IS BOUND.

    CASE lo_action->name.

      WHEN 'CHECK_DATA'.

        "-----------------------------------

        "Read data from context

 

 

        lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).

 

  "get element via lead selection

        lo_el_input = lo_nd_input->get_element( ).

 

 

  "get all declared attributes

        lo_el_input->get_static_attributes(

          IMPORTING

            static_attributes = ls_input ).

 

        "-----------------------------------

        "-----------------------------------

        " this method returns the attributes for

        " which the data is not filled

 

        lt_attributes = check_attriubutes( ls_input ).

 

        " if no attributes found for errors, return the control

        IF lt_attributes[] IS INITIAL.

          RETURN.

        ENDIF.

 

        CALL METHOD lo_api_controller->get_message_manager

          RECEIVING

            message_manager = lo_message_manager.

 

  "         report message

      

  CALL METHOD lo_message_manager->report_element_error_message

          EXPORTING

            message_text = 'Please fill all the fields'

            element      = lo_el_input

            attributes   = lt_attributes.


    ENDCASE.

  ENDIF.

ENDMETHOD.

 

 

Create a method CHECK_ATTRIBUTES( ) in view for checking attributes whether the fields are filled and writ the below code

 

Note: this method gets input structure and check for a field for value and it collects all the empty fields for error message display

 

Parameters:

parms_check_attr.PNG

 

CHECK_ATTRIBUTES( )

METHOD check_attriubutes .

  DATA lo_strdescr         TYPE REF TO cl_abap_structdescr.

  DATA lt_components    TYPE cl_abap_structdescr=>component_table.

  DATA ls_components   LIKE LINE OF lt_components.

 

FIELD-SYMBOLS: <lv_value> TYPE any.

 

 

  lo_strdescr ?=  cl_abap_structdescr=>describe_by_data( is_input ).

 

  "return if no input str passed

  IF lo_strdescr IS NOT BOUND.

    RETURN.

  ENDIF.

 

  lt_components = lo_strdescr->get_components( ).

 

  LOOP AT lt_components INTO ls_components.

 

    ASSIGN COMPONENT ls_components-name OF STRUCTURE is_input TO <lv_value>.

 

    "collect attributes if not filled

 

    IF <lv_value> IS ASSIGNED AND <lv_value> IS INITIAL.

      APPEND ls_components-name TO rt_attributes.

    ENDIF.

  ENDLOOP.

 

 

 

ENDMETHOD.

 

 

 

Now, activate the component

 

Step 6:


Create web dynpro application as shown below

6.PNG

 

Output:

 

Initial output screen looks as below

o1.PNG

 

 

When user presses button CHECK_DATA, only 1 attribute error message is shown for all input fields as below

o3.PNG

 

Now, user fills Personnel No, End date & start date and presses the button check data again, the output looks as below

 

o4.PNG

 

 

Hope this helps those looking for reporting one attribute error message for many input fields.

 

 

 

Your valuable feedback /suggestions/comments are always welcome


Viewing all articles
Browse latest Browse all 3667

Trending Articles