program bcalv_edit_08.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This report implements an ALV Grid Control with an application
* specific F4 help. The following aspects are dealth with:
* o how to replace the standard f4 help
* NOTE: This example uses a second ALV Grid Control to
* provide an application specific F4 help.
* This is probalbly NOT the usual way to
* provide such a functionality.
* However, the purpose of this report is not to
* show you how to implement an F4 help, but to
* explain how you pass the selected value to ALV,
* how you take values of other cells into account, etc.
* For this purpose, it does not matter how the f4 help
* is actually implemented.
*
* o how to pass the selected value to the ALV Grid Control
* o how to build an f4 help, whose value range depend on
* a value of another cell.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* We use table SBOOK with columns CLASS and SMOKER ready for input.
* The idea of this scenario is that it is only allowed to smoke
* in the first class (value 'F' of field CLASS).
* The application specific f4 help can be called for column CLASS:
* o if the value of column SMOKER in the same row is 'X', only class
* 'F' can be chosen
* o if the value of column SMOKER in the same row is ' ', all
* classes are allowed ('F','C','Y'). Thus, the f4 help shows all
* values.
* o if the value of column SMOKER in the same row is not valid
* (syntactically or semantically), a message is shown and
* no f4 help pops up.
*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* Note that this report is rather long because the columns CLASS and
* SMOKER are checked semantically which does not belong to the f4 help
* implementation. Class lcl_application_dc handles semantic checks.
* Local class lcl_application_f4 handles event ONF4 to build up
* the f4 help, to pass the value to the ALV Grid Control and
* to check whether the value of the SMOKER column is valid.
*
* 1. Register event ONF4 at frontend using method
* register_f4_for_fields. For this purpose, you pass a table
* with all fields, for which you want to implement your own
* f4 help.
* 1b. If the value range in your f4 help depends on other
* values of cells that are input enabled, set the
* GETBEFORE parameter.
* 2. Implement an event handler method for event ONF4.
* 3. Call your own f4 help. To customize your popup check
* first if the cell is ready for input (event parameter E_DISPLAY).
* 4. Check whether the value your f4 help depends on is valid.
* 5. If not already caught by your own f4 help, check whether
* the triggered cell was ready for input by using E_DISPLAY
* and if not, exit.
* 6. After the user selected a value, pass it to the ALV Grid Control:
* 6a. Define a field symbol of type: LVC_T_MODI and a structure of
* type LVC_S_MODI to pass the value later on.
* 6b. Dereference attribute M_DATA to your field symbol and add
* the selected value to the table to which this symbol points to.
* 7. Inform the ALV Grid Control that an own f4 help has been processed
* to suppress the standard f4 help.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This report implements an ALV Grid Control with an application
* specific F4 help. The following aspects are dealth with:
* o how to replace the standard f4 help
* NOTE: This example uses a second ALV Grid Control to
* provide an application specific F4 help.
* This is probalbly NOT the usual way to
* provide such a functionality.
* However, the purpose of this report is not to
* show you how to implement an F4 help, but to
* explain how you pass the selected value to ALV,
* how you take values of other cells into account, etc.
* For this purpose, it does not matter how the f4 help
* is actually implemented.
*
* o how to pass the selected value to the ALV Grid Control
* o how to build an f4 help, whose value range depend on
* a value of another cell.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* We use table SBOOK with columns CLASS and SMOKER ready for input.
* The idea of this scenario is that it is only allowed to smoke
* in the first class (value 'F' of field CLASS).
* The application specific f4 help can be called for column CLASS:
* o if the value of column SMOKER in the same row is 'X', only class
* 'F' can be chosen
* o if the value of column SMOKER in the same row is ' ', all
* classes are allowed ('F','C','Y'). Thus, the f4 help shows all
* values.
* o if the value of column SMOKER in the same row is not valid
* (syntactically or semantically), a message is shown and
* no f4 help pops up.
*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* Note that this report is rather long because the columns CLASS and
* SMOKER are checked semantically which does not belong to the f4 help
* implementation. Class lcl_application_dc handles semantic checks.
* Local class lcl_application_f4 handles event ONF4 to build up
* the f4 help, to pass the value to the ALV Grid Control and
* to check whether the value of the SMOKER column is valid.
*
* 1. Register event ONF4 at frontend using method
* register_f4_for_fields. For this purpose, you pass a table
* with all fields, for which you want to implement your own
* f4 help.
* 1b. If the value range in your f4 help depends on other
* values of cells that are input enabled, set the
* GETBEFORE parameter.
* 2. Implement an event handler method for event ONF4.
* 3. Call your own f4 help. To customize your popup check
* first if the cell is ready for input (event parameter E_DISPLAY).
* 4. Check whether the value your f4 help depends on is valid.
* 5. If not already caught by your own f4 help, check whether
* the triggered cell was ready for input by using E_DISPLAY
* and if not, exit.
* 6. After the user selected a value, pass it to the ALV Grid Control:
* 6a. Define a field symbol of type: LVC_T_MODI and a structure of
* type LVC_S_MODI to pass the value later on.
* 6b. Dereference attribute M_DATA to your field symbol and add
* the selected value to the table to which this symbol points to.
* 7. Inform the ALV Grid Control that an own f4 help has been processed
* to suppress the standard f4 help.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
data: ok_code like sy-ucomm,
save_ok like sy-ucomm,
g_container type scrfname value 'CC1',
g_grid type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container,
gt_fieldcat type lvc_t_fcat,
g_max type i value 100.
save_ok like sy-ucomm,
g_container type scrfname value 'CC1',
g_grid type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container,
gt_fieldcat type lvc_t_fcat,
g_max type i value 100.
class lcl_application_f4 definition deferred.
class lcl_application_dc definition deferred.
class lcl_application_dc definition deferred.
data: g_onf4 type ref to lcl_application_f4,
g_dc type ref to lcl_application_dc.
data: gt_outtab type table of sbook.
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_application_f4: local class to handle own F4.
*
* Definition:
* ~~~~~~~~~~~
class lcl_application_f4 definition.
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_application_f4: local class to handle own F4.
*
* Definition:
* ~~~~~~~~~~~
class lcl_application_f4 definition.
public section.
methods:
methods:
on_f4 for event onf4 of cl_gui_alv_grid
importing e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display.
importing e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display.
methods: reset.
methods: show_f4.
methods: show_f4.
private section.
**
* attributes for creating an own F4-Help
* (using a second ALV Grid Control
**
data: f4_alv type ref to cl_gui_alv_grid,
f4_cont type ref to cl_gui_custom_container.
**
* attributes for creating an own F4-Help
* (using a second ALV Grid Control
**
data: f4_alv type ref to cl_gui_alv_grid,
f4_cont type ref to cl_gui_custom_container.
types: begin of f4_itab_type.
types: value type s_class.
types: descr(20) type c.
types: end of f4_itab_type.
types: value type s_class.
types: descr(20) type c.
types: end of f4_itab_type.
data: f4_itab type table of f4_itab_type.
data: fieldcatalog type lvc_t_fcat.
data: fieldcatalog type lvc_t_fcat.
**
* attributes to store event parameters
* (after the CALL SCREEN command, the event parameters
* are not accessible)
**
types: begin of onf4_event_parameters_type.
types: c_fieldname type lvc_fname.
types: cs_row_no type lvc_s_roid.
types: cr_event_data type ref to cl_alv_event_data.
types: ct_bad_cells type lvc_t_modi.
types: c_display type char01.
types: end of onf4_event_parameters_type.
* attributes to store event parameters
* (after the CALL SCREEN command, the event parameters
* are not accessible)
**
types: begin of onf4_event_parameters_type.
types: c_fieldname type lvc_fname.
types: cs_row_no type lvc_s_roid.
types: cr_event_data type ref to cl_alv_event_data.
types: ct_bad_cells type lvc_t_modi.
types: c_display type char01.
types: end of onf4_event_parameters_type.
data: f4_params type onf4_event_parameters_type.
**
* Methods to create own F4-Help
* (This is done using a second ALV Grid Control)
**
methods: init_f4.
methods: build_fieldcatalog.
methods: fill_f4_itab importing smoker type c.
methods: fill_f4_itab importing smoker type c.
methods: on_double_click for event double_click of cl_gui_alv_grid
importing es_row_no.
importing es_row_no.
**
* Methods to check whether the values which the F4-Help needs
* are correct
* (The entries of the F4-Help of field CLASS depend on the value
* of field SMOKER. If field SMOKER of the same row is syntaktically
* or semantically not correct, this has to be handled during ONF4.
**
methods: smoker_cell_is_bad
returning value(r_flag) type i.
* Methods to check whether the values which the F4-Help needs
* are correct
* (The entries of the F4-Help of field CLASS depend on the value
* of field SMOKER. If field SMOKER of the same row is syntaktically
* or semantically not correct, this has to be handled during ONF4.
**
methods: smoker_cell_is_bad
returning value(r_flag) type i.
endclass. "lcl_application_f4 DEFINITION
*
* lcl_application_f4 (Definition)
*===============================================================
* class lcl_application_dc: local class to handle event data_changed.
*
* Definition:
* ~~~~~~~~~~~
class lcl_application_dc definition.
*
* lcl_application_f4 (Definition)
*===============================================================
* class lcl_application_dc: local class to handle event data_changed.
*
* Definition:
* ~~~~~~~~~~~
class lcl_application_dc definition.
public section.
methods: handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed
e_onf4 e_onf4_before e_onf4_after.
for event data_changed of cl_gui_alv_grid
importing er_data_changed
e_onf4 e_onf4_before e_onf4_after.
private section.
* This flag is set if any error occured in one of the
* following methods:
data: error_in_data type c.
* following methods:
data: error_in_data type c.
methods:
perform_semantic_checks
importing
pr_data_changed type ref to cl_alv_changed_data_protocol.
perform_semantic_checks
importing
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods: check_smoker
importing
ps_good_smoker type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
importing
ps_good_smoker type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods: check_class
importing
ps_good_class type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
importing
ps_good_class type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
endclass. "lcl_application_dc DEFINITION
*
* lcl_application_dc (Definition)
*===============================================================
*
* lcl_application_dc (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_application_f4 (Implementation)
*
class lcl_application_f4 implementation.
*§2. Implement an event handler method for event ONF4.
method on_f4.
* Save event parameter as global attributes of this class
* (maybe solved differently if you use a function module!)
f4_params-c_fieldname = e_fieldname.
f4_params-cs_row_no = es_row_no.
f4_params-cr_event_data = er_event_data.
f4_params-ct_bad_cells = et_bad_cells.
f4_params-c_display = e_display.
* (maybe solved differently if you use a function module!)
f4_params-c_fieldname = e_fieldname.
f4_params-cs_row_no = es_row_no.
f4_params-cr_event_data = er_event_data.
f4_params-ct_bad_cells = et_bad_cells.
f4_params-c_display = e_display.
*§3. Call your own f4 help. To customize your popup check
* first if the cell is ready for input (event parameter E_DISPLAY).
* (parameter E_DISPLAY is checked later in method on_double_click)
* first if the cell is ready for input (event parameter E_DISPLAY).
* (parameter E_DISPLAY is checked later in method on_double_click)
* (Probably, you would call a function module at this point,
* pass the needed event parameter and call the popup screen
* within that function module. This is not done in this example
* to avoid scattering its code).
* pass the needed event parameter and call the popup screen
* within that function module. This is not done in this example
* to avoid scattering its code).
call screen 101 starting at 10 10.
*§7. Inform the ALV Grid Control that an own f4 help has been processed
* to suppress the standard f4 help.
* to suppress the standard f4 help.
er_event_data->m_event_handled = 'X'.
endmethod. "on_f4
*---------------------------------------------------------------------
method show_f4.
data: ls_outtab type sbook.
endmethod. "on_f4
*---------------------------------------------------------------------
method show_f4.
data: ls_outtab type sbook.
* initialize own f4 help if needed
if f4_cont is initial.
call method init_f4.
endif.
if f4_cont is initial.
call method init_f4.
endif.
*§4. Check whether the value your f4 help depends on is valid.
* The possible values of field CLASS depend on
* the value of field SMOKER of the same row.
* You have to check that this value is valid:
if smoker_cell_is_bad( ) eq 1.
leave screen.
endif.
* the value of field SMOKER of the same row.
* You have to check that this value is valid:
if smoker_cell_is_bad( ) eq 1.
leave screen.
endif.
* determine value of column SMOKER and use appropriate f4 table
read table gt_outtab into ls_outtab index f4_params-cs_row_no-row_id
.
call method fill_f4_itab( ls_outtab-smoker ).
read table gt_outtab into ls_outtab index f4_params-cs_row_no-row_id
.
call method fill_f4_itab( ls_outtab-smoker ).
* refresh list of values in f4 help and show it
call method f4_alv->refresh_table_display.
* CAUTION: Do not use method REFRESH_TABLE_DISPLAY for
* your editable ALV Grid instances while handling events
* DATA_CHANGED or ONf4. You would overwrite intermediate
* values of your output table on frontend.
* 'f4_alv' is a non-editable ALV Grid Control for the
* application specific F4-Help. Therefore, calling
* REFRESH_TABLE_DISPLAY for this instance has no
* negative effect.
call method f4_alv->refresh_table_display.
* CAUTION: Do not use method REFRESH_TABLE_DISPLAY for
* your editable ALV Grid instances while handling events
* DATA_CHANGED or ONf4. You would overwrite intermediate
* values of your output table on frontend.
* 'f4_alv' is a non-editable ALV Grid Control for the
* application specific F4-Help. Therefore, calling
* REFRESH_TABLE_DISPLAY for this instance has no
* negative effect.
call method cl_gui_cfw=>flush.
endmethod. "show_f4
endmethod. "show_f4
*--------------------------------------------------------------------
method init_f4.
data: ls_layout type lvc_s_layo.
* build fieldcatalog entries for f4
call method build_fieldcatalog.
data: ls_layout type lvc_s_layo.
* build fieldcatalog entries for f4
call method build_fieldcatalog.
* create controls
create object f4_cont
exporting container_name = 'CC_ONF4'.
create object f4_cont
exporting container_name = 'CC_ONF4'.
create object f4_alv
exporting i_parent = f4_cont.
exporting i_parent = f4_cont.
* hide toolbar
ls_layout-no_toolbar = 'X'.
ls_layout-no_toolbar = 'X'.
call method f4_alv->set_table_for_first_display
exporting
is_layout = ls_layout
changing
it_fieldcatalog = fieldcatalog
it_outtab = f4_itab.
exporting
is_layout = ls_layout
changing
it_fieldcatalog = fieldcatalog
it_outtab = f4_itab.
* register event double click on backend
set handler me->on_double_click for f4_alv.
set handler me->on_double_click for f4_alv.
* flush since 'ls_layout' is local!
call method cl_gui_cfw=>flush.
call method cl_gui_cfw=>flush.
endmethod. "init_f4
*-----------------------------------------------------
method fill_f4_itab.
data ls_f4_itab type f4_itab_type.
*-----------------------------------------------------
method fill_f4_itab.
data ls_f4_itab type f4_itab_type.
* Delete all entries in f4_itab to determine
* offered values dynamically
clear f4_itab[].
* create entries depending on SMOKER field
if smoker is initial.
ls_f4_itab-value = 'C'.
ls_f4_itab-descr = text-t03. "Business Class
append ls_f4_itab to f4_itab.
ls_f4_itab-value = 'Y'.
ls_f4_itab-descr = text-t04. "Economie Class
append ls_f4_itab to f4_itab.
ls_f4_itab-value = 'F'.
ls_f4_itab-descr = text-t05. "First Class
append ls_f4_itab to f4_itab.
else.
ls_f4_itab-value = 'F'.
ls_f4_itab-descr = text-t05. "First Class
append ls_f4_itab to f4_itab.
endif.
endmethod. "fill_f4_itab
*----------------------------------------------------
method build_fieldcatalog.
data: ls_fcat type lvc_s_fcat.
* offered values dynamically
clear f4_itab[].
* create entries depending on SMOKER field
if smoker is initial.
ls_f4_itab-value = 'C'.
ls_f4_itab-descr = text-t03. "Business Class
append ls_f4_itab to f4_itab.
ls_f4_itab-value = 'Y'.
ls_f4_itab-descr = text-t04. "Economie Class
append ls_f4_itab to f4_itab.
ls_f4_itab-value = 'F'.
ls_f4_itab-descr = text-t05. "First Class
append ls_f4_itab to f4_itab.
else.
ls_f4_itab-value = 'F'.
ls_f4_itab-descr = text-t05. "First Class
append ls_f4_itab to f4_itab.
endif.
endmethod. "fill_f4_itab
*----------------------------------------------------
method build_fieldcatalog.
data: ls_fcat type lvc_s_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'VALUE'.
ls_fcat-coltext = text-t02.
ls_fcat-inttype = 'S_CLASS'.
ls_fcat-outputlen = 5.
append ls_fcat to fieldcatalog.
clear ls_fcat.
ls_fcat-fieldname = 'DESCR'.
ls_fcat-coltext = text-t01.
ls_fcat-inttype = 'C'.
ls_fcat-outputlen = 20.
append ls_fcat to fieldcatalog.
endmethod. "build_fieldcatalog
*-----------------------------------------------------
method on_double_click.
ls_fcat-fieldname = 'VALUE'.
ls_fcat-coltext = text-t02.
ls_fcat-inttype = 'S_CLASS'.
ls_fcat-outputlen = 5.
append ls_fcat to fieldcatalog.
clear ls_fcat.
ls_fcat-fieldname = 'DESCR'.
ls_fcat-coltext = text-t01.
ls_fcat-inttype = 'C'.
ls_fcat-outputlen = 20.
append ls_fcat to fieldcatalog.
endmethod. "build_fieldcatalog
*-----------------------------------------------------
method on_double_click.
*§5. If not already caught by your own f4 help, check whether
* the triggered cell was ready for input by using E_DISPLAY
* and if not, exit.
if f4_params-c_display eq 'X'.
leave screen.
endif.
* the triggered cell was ready for input by using E_DISPLAY
* and if not, exit.
if f4_params-c_display eq 'X'.
leave screen.
endif.
*§6. After the user selected a value, pass it to the ALV Grid Control:
*§ 6a. Define a field symbol of type: LVC_T_MODI and a structure of
* type LVC_S_MODI to pass the value later on.
field-symbols type lvc_t_modi.
data: ls_modi type lvc_s_modi,
ls_f4_itab type f4_itab_type.
* type LVC_S_MODI to pass the value later on.
field-symbols
data: ls_modi type lvc_s_modi,
ls_f4_itab type f4_itab_type.
*§ 6b. Dereference attribute M_DATA into your field symbol and add
* the selected value to the table to which this symbol points to.
assign f4_params-cr_event_data->m_data->* to.
ls_modi-row_id = f4_params-cs_row_no-row_id.
ls_modi-fieldname = f4_params-c_fieldname.
* the selected value to the table to which this symbol points to.
assign f4_params-cr_event_data->m_data->* to
ls_modi-row_id = f4_params-cs_row_no-row_id.
ls_modi-fieldname = f4_params-c_fieldname.
read table f4_itab into ls_f4_itab index es_row_no-row_id.
ls_modi-value = ls_f4_itab-value.
append ls_modi to.
append ls_modi to
leave screen.
endmethod. "on_double_click
*-----------------------------------------------------
method reset.
field-symbols type lvc_t_modi.
endmethod. "on_double_click
*-----------------------------------------------------
method reset.
field-symbols
assign f4_params-cr_event_data->m_data->* to .
clear[].
endmethod. "reset
*-----------------------------------------------------
method smoker_cell_is_bad.
data: ls_bad_cell type lvc_s_modi. "#EC NEEDED
clear
endmethod. "reset
*-----------------------------------------------------
method smoker_cell_is_bad.
data: ls_bad_cell type lvc_s_modi. "#EC NEEDED
r_flag = 0. "no error initially
* Determine if value of smoker cell of the same
* row has a bad value. If so, a message pops up
* instead of our F4 help.
read table f4_params-ct_bad_cells into ls_bad_cell
with key fieldname = 'SMOKER'
row_id = f4_params-cs_row_no-row_id.
if sy-subrc eq 0.
r_flag = 1.
message i000(0k) with text-i01 text-i02.
* NOTE: Although there is a bad value present
* the ALV Grid Control shows no error protocol.
* However, the bad value is saved in the
* protocol and event DATA_CHANGED_FINISHED is
* not raised.
endif.
* row has a bad value. If so, a message pops up
* instead of our F4 help.
read table f4_params-ct_bad_cells into ls_bad_cell
with key fieldname = 'SMOKER'
row_id = f4_params-cs_row_no-row_id.
if sy-subrc eq 0.
r_flag = 1.
message i000(0k) with text-i01 text-i02.
* NOTE: Although there is a bad value present
* the ALV Grid Control shows no error protocol.
* However, the bad value is saved in the
* protocol and event DATA_CHANGED_FINISHED is
* not raised.
endif.
endmethod. "smoker_cell_is_bad
*=====================================================
*=====================================================
endclass. "lcl_application_f4 IMPLEMENTATION
*
* lcl_application_f4 (Implementation)
*===================================================================
* lcl_application_f4 (Implementation)
*===================================================================
*===============================================================
* class lcl_application_dc (Implementation)
*
class lcl_application_dc implementation.
method handle_data_changed.
*
error_in_data = space.
* class lcl_application_dc (Implementation)
*
class lcl_application_dc implementation.
method handle_data_changed.
*
error_in_data = space.
* Distinguish, if DATA_CHANGED was raised because of an
* own F4-help.
* Event DATA_CHANGED provides parameter E_ONF4
* for this purpose.
if not e_onf4 is initial.
* Add your special handling here if needed.
* Event DATA_CHANGED provides parameters E_ONF4_AFTER
* and E_ONF4_BEFORE to distinguish the context
* additionally.
* own F4-help.
* Event DATA_CHANGED provides parameter E_ONF4
* for this purpose.
if not e_onf4 is initial.
* Add your special handling here if needed.
* Event DATA_CHANGED provides parameters E_ONF4_AFTER
* and E_ONF4_BEFORE to distinguish the context
* additionally.
* In general, semantic checks should be the same no matter if
* they have been entered by hand or using an application
* specific F4 help. So you probably do not need these parameters.
else.
call method perform_semantic_checks( er_data_changed ).
endif.
* they have been entered by hand or using an application
* specific F4 help. So you probably do not need these parameters.
else.
call method perform_semantic_checks( er_data_changed ).
endif.
if error_in_data = 'X'.
call method er_data_changed->display_protocol.
endif.
call method er_data_changed->display_protocol.
endif.
endmethod. "handle_data_changed
*------------------------------------
* private methods
*------------------------------------
method perform_semantic_checks.
*
* In this snenario, only values of cells in columns CLASS or SMOKER
* can be changed. These fields have a value range defined
* in the ABAP dictionary.
* Thus, after ALVs syntaktical check, we only need to
* check if the user tried to enter a smoker seat for
* a class other than 'F' or vice versa.
*
data: ls_good type lvc_s_modi.
*------------------------------------
* private methods
*------------------------------------
method perform_semantic_checks.
*
* In this snenario, only values of cells in columns CLASS or SMOKER
* can be changed. These fields have a value range defined
* in the ABAP dictionary.
* Thus, after ALVs syntaktical check, we only need to
* check if the user tried to enter a smoker seat for
* a class other than 'F' or vice versa.
*
data: ls_good type lvc_s_modi.
loop at pr_data_changed->mt_good_cells into ls_good.
case ls_good-fieldname.
when 'SMOKER'.
call method check_smoker
exporting
ps_good_smoker = ls_good
pr_data_changed = pr_data_changed.
case ls_good-fieldname.
when 'SMOKER'.
call method check_smoker
exporting
ps_good_smoker = ls_good
pr_data_changed = pr_data_changed.
when 'CLASS'.
call method check_class
exporting
ps_good_class = ls_good
pr_data_changed = pr_data_changed.
endcase.
endloop.
call method check_class
exporting
ps_good_class = ls_good
pr_data_changed = pr_data_changed.
endcase.
endloop.
endmethod. "perform_semantic_checks
*--------------------------------------
method check_smoker.
data: l_smoker type s_smoker,
l_class type s_class,
ls_outtab type sbook,
ls_good_class type lvc_s_modi. "#EC NEEDED
*--------------------------------------
method check_smoker.
data: l_smoker type s_smoker,
l_class type s_class,
ls_outtab type sbook,
ls_good_class type lvc_s_modi. "#EC NEEDED
* first get value of smoker cell:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_smoker-row_id
i_fieldname = ps_good_smoker-fieldname
importing
e_value = l_smoker.
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_smoker-row_id
i_fieldname = ps_good_smoker-fieldname
importing
e_value = l_smoker.
* If it's a non smoker there is no problem at all
* because every value of CLASS shall be possible then.
if l_smoker is initial.
exit.
endif.
* because every value of CLASS shall be possible then.
if l_smoker is initial.
exit.
endif.
* If not, value of cell CLASS has to be 'F'.
* First check if the value of field CLASS has been
* changed/entered newly, too:
read table pr_data_changed->mt_good_cells into ls_good_class
with key row_id = ps_good_smoker-row_id
fieldname = 'CLASS'.
if sy-subrc eq 0.
* get that new value:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_smoker-row_id
i_fieldname = 'CLASS'
importing
e_value = l_class.
else.
* get current value
read table gt_outtab into ls_outtab index ps_good_smoker-row_id.
l_class = ls_outtab-class.
endif.
* First check if the value of field CLASS has been
* changed/entered newly, too:
read table pr_data_changed->mt_good_cells into ls_good_class
with key row_id = ps_good_smoker-row_id
fieldname = 'CLASS'.
if sy-subrc eq 0.
* get that new value:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_smoker-row_id
i_fieldname = 'CLASS'
importing
e_value = l_class.
else.
* get current value
read table gt_outtab into ls_outtab index ps_good_smoker-row_id.
l_class = ls_outtab-class.
endif.
* Since we have a smoker his class has to be 'F':
if l_class ne 'F'.
call method pr_data_changed->add_protocol_entry
exporting
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = text-m01 "Klasse
i_msgv2 = l_class
i_msgv3 = text-m02 "nicht erlaubt für Raucher
i_fieldname = ps_good_smoker-fieldname
i_row_id = ps_good_smoker-row_id.
if l_class ne 'F'.
call method pr_data_changed->add_protocol_entry
exporting
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = text-m01 "Klasse
i_msgv2 = l_class
i_msgv3 = text-m02 "nicht erlaubt für Raucher
i_fieldname = ps_good_smoker-fieldname
i_row_id = ps_good_smoker-row_id.
error_in_data = 'X'.
endif.
endmethod. "check_smoker
*--------------------------------------
method check_class.
data: l_smoker type s_smoker,
l_class type s_class,
ls_outtab type sbook,
ls_good_smoker type lvc_s_modi. "#EC NEEDED
endif.
endmethod. "check_smoker
*--------------------------------------
method check_class.
data: l_smoker type s_smoker,
l_class type s_class,
ls_outtab type sbook,
ls_good_smoker type lvc_s_modi. "#EC NEEDED
* first get value of class cell:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_class-row_id
i_fieldname = ps_good_class-fieldname
importing
e_value = l_class.
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_class-row_id
i_fieldname = ps_good_class-fieldname
importing
e_value = l_class.
* If it's CLASS 'F' there is no problem at all
* because every value of SMOKER shall be possible then.
if l_class eq 'F'.
exit.
endif.
* because every value of SMOKER shall be possible then.
if l_class eq 'F'.
exit.
endif.
* If not, value of cell SMOKER has to be initial.
* First check if the value of field CLASS has been
* changed/entered newly, too:
read table pr_data_changed->mt_good_cells into ls_good_smoker
with key row_id = ps_good_class-row_id
fieldname = 'SMOKER'.
if sy-subrc eq 0.
* get that new value:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_class-row_id
i_fieldname = 'SMOKER'
importing
e_value = l_smoker.
else.
* get current value
read table gt_outtab into ls_outtab index ps_good_class-row_id.
l_smoker = ls_outtab-smoker.
endif.
* First check if the value of field CLASS has been
* changed/entered newly, too:
read table pr_data_changed->mt_good_cells into ls_good_smoker
with key row_id = ps_good_class-row_id
fieldname = 'SMOKER'.
if sy-subrc eq 0.
* get that new value:
call method pr_data_changed->get_cell_value
exporting
i_row_id = ps_good_class-row_id
i_fieldname = 'SMOKER'
importing
e_value = l_smoker.
else.
* get current value
read table gt_outtab into ls_outtab index ps_good_class-row_id.
l_smoker = ls_outtab-smoker.
endif.
* Since the class is not 'F' it has to be a non smoking person:
if not l_smoker is initial.
call method pr_data_changed->add_protocol_entry
exporting
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'W'
i_msgv1 = text-m03 "Als Raucher dürfen Sie Klasse
i_msgv2 = l_class
i_msgv3 = text-m04 "nicht buchen
i_fieldname = ps_good_class-fieldname
i_row_id = ps_good_class-row_id.
if not l_smoker is initial.
call method pr_data_changed->add_protocol_entry
exporting
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'W'
i_msgv1 = text-m03 "Als Raucher dürfen Sie Klasse
i_msgv2 = l_class
i_msgv3 = text-m04 "nicht buchen
i_fieldname = ps_good_class-fieldname
i_row_id = ps_good_class-row_id.
error_in_data = 'X'.
endif.
endif.
endmethod. "check_class