cancel
Showing results for 
Search instead for 
Did you mean: 

Check mandatory fields in ALV

Former Member
0 Kudos

Hi All,

How do I check the mandatory fields and throw error messages in an ALV

I'm able to do it using cl_wd_dynamic_tool=>check_mandatory_attr_on_view for a table.

But the message table is initial when the same method is called with respect to an ALV.

Do I have to loop the table and check for initial fields or is there a way out?

Any inputs are appreciated.

Thanks,

Indu.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks for you input Rajkumar though it din't actually solve the problem.

I've solved by using CHECK_MANDATORY_ATTRIBUTES method instead of CHECK_MANDATORY_ATTR_ON_VIEW.

Refer the standard example WDR_TEST_MANDATORY.

Thanks

Indu.

yesrajkumar
Active Participant
0 Kudos

Hi,

I have used the standard component u2018salv_wd_tableu2019 in my application and will be able to give example on the same.

In the WDDOINIT method of the component controller, use the following code to define column name, your own buttons, visible column for the same component usage.

DATA:

lr_salv_wd_table_usage TYPE REF TO if_wd_component_usage,

lr_salv_wd_table TYPE REF TO iwci_salv_wd_table.

*Check ALV component usage

lr_salv_wd_table_usage = wd_this->wd_cpuse_alv( ).

IF lr_salv_wd_table_usage->has_active_component( ) IS INITIAL.

lr_salv_wd_table_usage->create_component( ).

ELSE.

lr_salv_wd_table_usage->delete_component( ).

lr_salv_wd_table_usage->create_component( ).

ENDIF.

*Get ALV component

lr_salv_wd_table = wd_this->wd_cpifc_alv( ).

wd_this->mr_table type ref to CL_SALV_WD_CONFIG_TABLE.

*Get ConfigurationModel from ALV Component

wd_this->mr_table = lr_salv_wd_table->get_model( ).

*Set table settings

DATA:

lr_table_settings TYPE REF TO if_salv_wd_table_settings.

lr_table_settings ?= wd_this->mr_table .

lr_table_settings->set_visible_row_count( '5' ).

lr_table_settings->set_width( '100%' ).

DATA:

lr_header TYPE REF TO cl_salv_wd_header,

l_header_text TYPE string.

lr_header = lr_table_settings->get_header( ).

l_header_text = cl_wd_utilities=>get_otr_text_by_alias( 'CHECK_MANDATORY').

lr_header->set_text( l_header_text ).

lr_header->set_tooltip( l_header_text ).

"lr_table_settings->set_selection_mode( cl_wd_table=>e_selection_mode-multi_no_lead ).

*Set functions

IF wd_this->mb_no_maintain NE abap_true.

DATA:

lr_function TYPE REF TO cl_salv_wd_function,

lr_fe_button TYPE REF TO cl_salv_wd_fe_button,

l_btn_text TYPE string.

*Add the button here for validation on the top of the ALV

lr_function = lr_functions->create_function( 'CHECK_MANDATORY' ).

CREATE OBJECT lr_fe_button.

l_btn_text = cl_wd_utilities=>get_otr_text_by_alias( "ECK_MANDATORY'').

lr_fe_button->set_text( l_btn_text ).

lr_fe_button->set_tooltip( l_btn_text ).

lr_function->set_editor( lr_fe_button ).

After defining the buttons 'CHECK_MANDATORY', handle the actions for the same using the method u2018LIST_ACTIONu2019 which should have the event as u2018ON_FUNCTIONu2019, controller as u2018interface controlleru2019 and component use as the name you have given say u2018ALVu2019.

In the method u2018LIST_ACTIONu2019, handle the actions as below. This method will have the following importing parameters.

WDEVENT Importing CL_WD_CUSTOM_EVENT

R_PARAM Importing IF_SALV_WD_TABLE_FUNCTION

method list_action .

case r_param->id .

when 'CHECK_MANDATORY' .

"Do the validation here- Example code here"

data lo_nd_employee type ref to if_wd_context_node.

data lo_el_employee type ref to if_wd_context_element.

data ls_employee type wd_this->element_employee.

data lv_pernr like ls_employee-pernr.

navigate from <CONTEXT> to <EMPLOYEE> via lead selection

lo_nd_employee = wd_context->get_child_node( name = wd_this->wdctx_employee ).

get element via lead selection

lo_el_employee = lo_nd_employee->get_element( ).

get single attribute

lo_el_employee->get_attribute(

exporting

name = `PERNR`

importing

value = lv_pernr ).

*Check the input here

If lv_pernr 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_error_message

exporting

message_text = u2018Please input the personnel Numberu2019

Endif.

endcase.

endmethod.

Thanks,

Rajkumar.S

Edited by: Rajkumar S on Jan 25, 2009 4:25 PM