Customized search for a field in editable ALV
Abstarct:
To add customized search help for the field in editable ALV using OOPS concept. This program is to add search help to the field reason for movement, when posting a material document using LI21 transaction. For posting material document you can call MB11 using BDC .
Procedures:
- Define a class, and inside the class, define methods for F4 search help in public sections.
PUBLIC SECTION.
METHODS: on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname* e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.
- In private sections, give the data declarations and also the method to fill the F4 help table.
TYPES: BEGIN OF onf4_event_parameters_type.
TYPES: g_fieldname TYPE lvc_fname.
TYPES: g_row_no TYPE lvc_s_roid.
TYPES: g_event_data TYPE REF TO cl_alv_event_data.
TYPES: g_bad_cells TYPE lvc_t_modi.
TYPES: g_display TYPE char01.
TYPES: END OF onf4_event_parameters_type.
DATA: f4_params TYPE onf4_event_parameters_type.
DATA:f4_itab TYPE STANDARD TABLE OF t157e.
- Also write the double click method in private section, which is used to place the value into the field after search help.
- Define the fieldcat for the search help (note: fields which you want to display on click of search help).
- Call a new screen, in which you are going to display the values of search help.
- Set the envent_handled = X. er_event_data->m_event_handled = ‘X’.
- On click of serach help, you can get the row id using the field f4_params-g_row_no-row_id.
- First read the final internal table , that we will be using to display the ALV, so we can get the entries corresponding to the line we select in the workarea.
- Then fetch values from the table that you want to display for F4 search help and put it in an internal table.
- Assign that internal table to the f4 internal table( DATA:f4_itab TYPE STANDARD TABLE OF t157e.)
- In the Double click event, use field symbols and assign the data that you get from the f4_params-event data
ASSIGN f4_params-g_event_data->m_data->* TO <itab>.
ls_modi-row_id = f4_params-g_row_no-row_id.
ls_modi-fieldname = f4_params-g_fieldname.
- Read the f4_itab table and pass the value to ls_modi-value and finally append ls_modi to <itab>. This will place the value in the field of search help.
13.On click of F4: