cancel
Showing results for 
Search instead for 
Did you mean: 

How to write eeror meeage same employee id insert on employee table?

Former Member
0 Kudos

Hi

How to write eeror meeage same employee id insert on employee table?

ex: i can insert the employee id 80004080 in employee table 2nd time to trigger error message.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

this code write onaction method


*         get message manager
       
data lo_api_controller     type ref to if_wd_controller.
       
data lo_message_manager    type ref to if_wd_message_manager.

 
DATA: it_emp_gt1 TYPE TABLE OF YTMS_GT_EMP_DETA,
        wa_emp_gt1
TYPE YTMS_GT_EMP_DETA.

  
DATA: it_emp_gt2 TYPE TABLE OF YTMS_GT_EMP_DETA,
        wa_emp_gt2
TYPE YTMS_GT_EMP_DETA.

 
DATA lv_value TYPE string.

    lo_api_controller ?= wd_This->Wd_Get_Api( ).

  it_emp_gt1 = lt_emp_group_travel.
   
SORT it_emp_gt1 by emp_id.
  it_emp_gt2 = it_emp_gt1.


  
LOOP AT it_emp_gt1 INTO wa_emp_gt1.
    lv_value = sy-tabix.
    lv_value = lv_value +
1.
   
READ TABLE it_emp_gt2 INTO wa_emp_gt2 INDEX lv_value.
   
if sy-subrc = 0.

     
if wa_emp_gt1-emp_id = wa_emp_gt2-emp_id.
*
       
CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER
          RECEIVING
            MESSAGE_MANAGER = lo_message_manager
            .

*         report message
       
CALL METHOD lo_message_manager->RAISE_ERROR_MESSAGE
         
EXPORTING
            MESSAGE_TEXT  =
'Duplicate Employee Number are not allowed'.

     
CLEAR : wa_emp_gt2,wa_emp_gt1.

       
ENDIF.


     
endif.
   
ENDLOOP.

Answers (2)

Answers (2)

ramakrishnappa
Active Contributor
0 Kudos

Hi Ram,

To achieve your requirement proceed as below

  • Create an action ON_ENTER on input field of table cell
  • Whenever the user enters a new record, on enter event validate if its a valid or duplicate, write this logic in WDDOBEFOREACTION( ) method

Sample: write this in wddobeforeaction( ) method

DATA lo_api_controller TYPE REF TO if_wd_view_controller.

 
DATA lo_action         TYPE REF TO if_wd_action.

  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 'ON_ENTER' OR 'SAVE'.

               "Here read your table entries and check if any duplicate entries in table


              

               " if duplicates found, then raise error message using method report


          

             lo_message_manager = wd_this->wd_get_api( )->get_message_manager( ). 

         " report message 

        CALL METHOD lo_message_manager->report_attribute_error_message 

          EXPORTING 

            message_text   = 'Duplicate entries are not allowed' 

            element        = lo_element

            attribute_name = 'PERNR'.  " Attribute Name



   
ENDCASE.

 
ENDIF.

Hope this helps you.

Regards,

Rama

former_member197475
Active Contributor
0 Kudos

Hi Ram,

1. It is always better to handle your validation in WDDOBEFOREACTION method.

2. Now get your Employee ID(lv_empid) from your context.

3.Now check whether the lv_empid exist in your table ZTABLE_EMP. Follow the below query.

Select single EMP_ID

into lv_compare_emp_id

from ZTABLE_EMP

where EMP_ID = lv_empid.

4. Now if your sy-subrc fails, write an error message.

Try it out.

BR,

RAM.