**********************************************************************************GLOBAL DATA DECLARATION
*********************************************************************************
DATA: gt_rel_disp TYPE TABLE OF scustom.
TYPES: BEGIN OF ty_data,
state TYPE cnv_10940_relev,
END OF ty_data.
DATA: gv_cont_0100 TYPE REF TO cl_gui_custom_container,
gv_grid_0100 TYPE REF TO cl_gui_alv_grid,
gs_f4 TYPE lvc_s_f4,
gt_f4 TYPE lvc_t_f4,
gt_data TYPE TABLE OF ty_data,
gt_ret TYPE TABLE OF ddshretval,
gs_layo_0100 TYPE lvc_s_layo,
gs_fieldcat_0100 TYPE lvc_s_fcat,
gt_fieldcat_0100 TYPE lvc_t_fcat,
gt_exclude_0100 TYPE ui_functions,
gs_exclude TYPE ui_func,
gv_change.
CONSTANTS: gc_x VALUE 'X'.
FIELD-SYMBOLS: <itab> TYPE lvc_t_modi.
**********************************************************************************LOCAL CLASS DEFINITION
*********************************************************************************
*Class definition to handle the ONF4 event
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
DATA: gref_events_0100 TYPE REF TO lcl_event_handler.
METHODS: on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING sender
e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.
METHODS: data_change FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed
e_onf4.
PROTECTED SECTION.
DATA: lv2 TYPE c.
PRIVATE SECTION.
DATA: lv1 TYPE c.
ENDCLASS. "lcl_event_handler DEFINITION
**********************************************************************************LOCAL CLASS IMPLEMENTATION
*********************************************************************************
*Class implementation to handle the ONF4 event
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_f4.
DATA: ls_data LIKE LINE OF gt_data,
ls_sel LIKE LINE OF gt_ret,
ls_modi TYPE lvc_s_modi,
ls_fin_disp LIKE LINE OF gt_rel_disp.
* Add the custom F4 values; here we are adding 2 values 'Uncertain' and 'Relevant' for the field STATE
IF gt_data[] IS INITIAL.
ls_data-state = 'PUNE'.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ls_data-state = 'MUMBAI'.
APPEND ls_data TO gt_data.
ENDIF.
*Call the function module to display the custom F4 values
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CITY'
window_title = 'List of State entries'(002)
value_org = 'S'
TABLES
value_tab = gt_data[]
return_tab = gt_ret[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
" (note: gt_ret[] contains the row id selected by the user from the list of f4
" values)
IF sy-subrc = 0.
READ TABLE gt_ret INTO ls_sel INDEX 1.
ASSIGN er_event_data->m_data->* TO <itab>.
READ TABLE gt_rel_disp INDEX es_row_no-row_id INTO ls_fin_disp.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = 'CITY'.
ls_modi-value = ls_sel-fieldval.
APPEND ls_modi TO <itab>.
gv_change = gc_x.
ENDIF.
er_event_data>m_event_handled = gc_x.
" (to inform grid that f4 was handled manually)
ENDMETHOD.
METHOD data_change.
gv_change = gc_x.
ENDMETHOD. "data_changed
ENDCLASS. "lcl_event_handler IMPLEMENTATION
**********************************************************************************START-OF-SELECTION
*********************************************************************************
START-OF-SELECTION.
CALL SCREEN '0100'.
********************************************************************************** pbo - status_0100
*********************************************************************************
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
SET TITLEBAR '0100'.
ENDMODULE. "data_change
**********************************************************************************PBO - get_result_data
*********************************************************************************MODULE get_result_data_0100 OUTPUT.
DATA: gref_events_0100 TYPE REF TO lcl_event_handler.
IF gv_cont_0100 IS INITIAL.
*Create an object for the Grid container
CREATE OBJECT gv_cont_0100
EXPORTING
container_name = 'CONT1' "CONTAINER NAME
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
IF gv_grid_0100 IS INITIAL.
*Create an object for the ALV Grid
CREATE OBJECT gv_grid_0100
EXPORTING
i_parent = gv_cont_0100
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
*Register the field for which the custom F4 has to be displayed
gs_f4-fieldname = 'CITY'.
gs_f4-register = 'X'.
gs_f4-getbefore = space.
gs_f4-chngeafter = space.
APPEND gs_f4 TO gt_f4.
* (note: chngeafter set to 'X' only if any other field value has to be set based
* on the selected f4 value)
CALL METHOD gv_grid_0100->register_f4_for_fields
EXPORTING
it_f4 = gt_f4.
* Define layout attributes
gs_layo_0100-cwidth_opt = gc_x.
gs_layo_0100-sel_mode = 'D'.
gs_layo_0100-zebra = gc_x.
gs_layo_0100-grid_title = 'Display Result'(001).
* Define the field catalogue attributes
gs_fieldcat_0100-fieldname = 'ID'.
gs_fieldcat_0100-coltext = 'ID'.
gs_fieldcat_0100-col_pos = 1.
gs_fieldcat_0100-outputlen = 40.
gs_fieldcat_0100-datatype = 'NUMC'.
gs_fieldcat_0100-intlen = 40.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
CLEAR gs_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'CITY'.
gs_fieldcat_0100-coltext = 'City'.
gs_fieldcat_0100-col_pos = 2.
gs_fieldcat_0100-outputlen = 30.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 30.
gs_fieldcat_0100-f4availabl = gc_x.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'NAME'.
gs_fieldcat_0100-coltext = 'Name'.
gs_fieldcat_0100-col_pos = 3.
gs_fieldcat_0100-outputlen = 40.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 40.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'STREET'.
gs_fieldcat_0100-coltext = 'Street'.
gs_fieldcat_0100-col_pos = 4.
gs_fieldcat_0100-outputlen = 30.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 60.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'POSTBOX'.
gs_fieldcat_0100-coltext = 'PostBox'.
gs_fieldcat_0100-col_pos = 5.
gs_fieldcat_0100-outputlen = 20.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 20.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'POSTCODE'.
gs_fieldcat_0100-coltext = 'Postcode'.
gs_fieldcat_0100-col_pos = 20.
gs_fieldcat_0100-outputlen = 10.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 20.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
gs_fieldcat_0100-fieldname = 'COUNTRY'.
gs_fieldcat_0100-coltext = 'Country'.
gs_fieldcat_0100-col_pos = 5.
gs_fieldcat_0100-outputlen = 20.
gs_fieldcat_0100-datatype = 'CHAR'.
gs_fieldcat_0100-intlen = 20.
gs_fieldcat_0100-edit = gc_x.
APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
* Define the functions that has to be excluded
gs_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND gs_exclude TO gt_exclude_0100.
gs_exclude = cl_gui_alv_grid=>mc_fc_select_all.
APPEND gs_exclude TO gt_exclude_0100.
gs_exclude = cl_gui_alv_grid=>mc_fc_minimum.
APPEND gs_exclude TO gt_exclude_0100.
gs_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND gs_exclude TO gt_exclude_0100.
* Create an object for the local class
CREATE OBJECT gref_events_0100.
SET HANDLER gref_events_0100->on_f4 FOR gv_grid_0100.
SELect * FROM scustom INTO TABLE gt_rel_disp.
* Display data in ALV GRID format.
CALL METHOD gv_grid_0100->set_table_for_first_display
EXPORTING
i_bypassing_buffer = gc_x
is_layout = gs_layo_0100
it_toolbar_excluding = gt_exclude_0100
CHANGING
it_outtab = gt_rel_disp[]
it_fieldcatalog = gt_fieldcat_0100
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Raise a message
ENDIF.
ENDIF.
ENDMODULE. "get_result_data_0100 OUTPUT
**********************************************************************************PAI - user_command_0100
*********************************************************************************MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'SAVE'.
CALL METHOD gv_grid_0100->check_changed_data.
CHECK gv_change EQ 'X'.
CLEAR gv_change.
MODIFY SCUSTOM FROM TABLE gt_rel_disp.
COMMIT WORK.
when 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
********************************************************************************** SCREEN
*********************************************************************************
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE get_result_data_0100.
PROCESS AFTER INPUT.
MODULE user_command_0100.