‎2007 Oct 04 4:22 PM
I have an OO ALV program that allows the User to change fields in the display and then it will update a data base when they click on the SAVE button. I need to have an edit to check two fields both of which have the value 'X' or ' '. I need to edit them when a change occurs to check that if one field is 'X' the other must not be 'X' and produce an error message when it occurs. I'm stumped on how to do this. I tried going back to the table when field A is changed and getting field B and doing the check, but that won't work because they may have changed field B and while it was X it may now be ' '. The best place to check it would be down where I get ready to save it, but I don't know how to set the error indicator on the row/column and produce the message identifying all the rows in error at that point.
‎2007 Oct 04 4:31 PM
Hi
see the sample code
Example:
REPORT sapmz_hf_alv_grid .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
TABLES: zsflight.
To allow the declaration of o_event_receiver before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
*----
G L O B A L I N T E R N A L T A B L E S
*----
*DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
To include a traffic light and/or color a line the structure of the
table must include fields for the traffic light and/or the color
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for traffic light
TYPES: traffic_light TYPE c.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
*----
G L O B A L D A T A
*----
DATA: ok_code LIKE sy-ucomm,
Work area for internal table
g_wa_sflight TYPE st_sflight,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver.
DATA:
Work area for screen 200
g_screen200 LIKE zsflight.
Data for storing information about selected rows in the grid
DATA:
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
*----
C L A S S E S
*----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
----
CLASS lcl_event_receiver IMPLEMENTATION
----
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
Event handler method for event toolbar.
CONSTANTS:
Constants for button type
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.
DATA:
ls_toolbar TYPE stb_button.
Append seperator to the normal toolbar
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
Append a new button that to the toolbar. Use E_OBJECT of
event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
This class has one attribute MT_TOOLBAR which is of table type
TTB_BUTTON. The structure is STB_BUTTON
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'CHANGE'.
PERFORM change_flight.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*----
S T A R T - O F - S E L E C T I O N.
*----
START-OF-SELECTION.
SET SCREEN '100'.
&----
*& Module USER_COMMAND_0100 INPUT
&----
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Module STATUS_0100 OUTPUT
&----
MODULE status_0100 OUTPUT.
DATA:
For parameter IS_VARIANT that is sued to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant,
Utillity field
l_lines TYPE i.
After returning from screen 200 the line that was selected before
going to screen 200, should be selected again. The table gi_index_rows
was the output table from the GET_SELECTED_ROWS method in form
CHANGE_FLIGHT
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = gi_index_rows.
CALL METHOD cl_gui_cfw=>flush.
REFRESH gi_index_rows.
ENDIF.
Read data and create objects
IF go_custom_container IS INITIAL.
Read data from datbase table
PERFORM get_data.
Create objects for container and ALV grid
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
Create object for event_receiver class
and set handlers
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
Layout (Variant) for ALV grid
l_layout-report = sy-repid. "Layout fo report
*----
Setup the grid layout using a variable of structure lvc_s_layo
*----
Set grid title
gs_layout-grid_title = 'Flights'.
Selection mode - Single row without buttons
(This is the default mode
gs_layout-sel_mode = 'B'.
Name of the exception field (Traffic light field) and the color
field + set the exception and color field of the table
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
gs_layout-info_fname = 'LINE_COLOR'.
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
Value of traffic light field
g_wa_sflight-traffic_light = '1'.
Value of color field:
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
*-- End of grid setup -
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid. This is not necessary in this
example as there is only one control on the screen
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0200 INPUT
&----
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT200'.
LEAVE TO SCREEN 100.
WHEN'SAVE'.
PERFORM save_changes.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
&----
*& Form get_data
&----
FORM get_data.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
ENDFORM. " load_data_into_grid
&----
*& Form change_flight
&----
Reads the contents of the selected row in the grid, ans transfers
the data to screen 200, where it can be changed and saved.
----
FORM change_flight.
DATA:l_lines TYPE i.
REFRESH gi_index_rows.
CLEAR g_selected_row.
Read index of selected rows
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
Check if any row are selected at all. If not
table gi_index_rows will be empty
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a line'.
EXIT.
ENDIF.
Read indexes of selected rows. In this example only one
row can be selected as we are using gs_layout-sel_mode = 'B',
so it is only ncessary to read the first entry in
table gi_index_rows
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Transfer data from the selected row to screenm 200 and show
screen 200
CLEAR g_screen200.
MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
LEAVE TO SCREEN '200'.
ENDFORM. " change_flight
&----
*& Form save_changes
&----
Changes made in screen 200 are written to the datbase table
zsflight, and to the grid table gi_sflight, and the grid is
updated with method refresh_table_display to display the changes
----
FORM save_changes.
DATA: l_traffic_light TYPE c.
Update traffic light field
Update database table
MODIFY zsflight FROM g_screen200.
Update grid table , traffic light field and color field.
Note that it is necessary to use structure g_wa_sflight
for the update, as the screen structure does not have a
traffic light field
MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
clear g_wa_sflight-line_color.
ELSE.
g_wa_sflight-traffic_light = '3'.
clear g_wa_sflight-line_color.
ENDIF.
MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
Refresh grid
CALL METHOD go_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN '100'.
ENDFORM. " save_changes
chk this blog
/people/vijaybabu.dudla/blog/2006/07/21/topofpage-in-alv-using-clguialvgrid
Regards
Anji
‎2007 Oct 04 4:31 PM
Hi
see the sample code
Example:
REPORT sapmz_hf_alv_grid .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
TABLES: zsflight.
To allow the declaration of o_event_receiver before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
*----
G L O B A L I N T E R N A L T A B L E S
*----
*DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
To include a traffic light and/or color a line the structure of the
table must include fields for the traffic light and/or the color
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for traffic light
TYPES: traffic_light TYPE c.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
*----
G L O B A L D A T A
*----
DATA: ok_code LIKE sy-ucomm,
Work area for internal table
g_wa_sflight TYPE st_sflight,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver.
DATA:
Work area for screen 200
g_screen200 LIKE zsflight.
Data for storing information about selected rows in the grid
DATA:
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
*----
C L A S S E S
*----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
----
CLASS lcl_event_receiver IMPLEMENTATION
----
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
Event handler method for event toolbar.
CONSTANTS:
Constants for button type
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.
DATA:
ls_toolbar TYPE stb_button.
Append seperator to the normal toolbar
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
Append a new button that to the toolbar. Use E_OBJECT of
event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
This class has one attribute MT_TOOLBAR which is of table type
TTB_BUTTON. The structure is STB_BUTTON
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'CHANGE'.
PERFORM change_flight.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*----
S T A R T - O F - S E L E C T I O N.
*----
START-OF-SELECTION.
SET SCREEN '100'.
&----
*& Module USER_COMMAND_0100 INPUT
&----
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Module STATUS_0100 OUTPUT
&----
MODULE status_0100 OUTPUT.
DATA:
For parameter IS_VARIANT that is sued to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant,
Utillity field
l_lines TYPE i.
After returning from screen 200 the line that was selected before
going to screen 200, should be selected again. The table gi_index_rows
was the output table from the GET_SELECTED_ROWS method in form
CHANGE_FLIGHT
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = gi_index_rows.
CALL METHOD cl_gui_cfw=>flush.
REFRESH gi_index_rows.
ENDIF.
Read data and create objects
IF go_custom_container IS INITIAL.
Read data from datbase table
PERFORM get_data.
Create objects for container and ALV grid
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
Create object for event_receiver class
and set handlers
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
Layout (Variant) for ALV grid
l_layout-report = sy-repid. "Layout fo report
*----
Setup the grid layout using a variable of structure lvc_s_layo
*----
Set grid title
gs_layout-grid_title = 'Flights'.
Selection mode - Single row without buttons
(This is the default mode
gs_layout-sel_mode = 'B'.
Name of the exception field (Traffic light field) and the color
field + set the exception and color field of the table
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
gs_layout-info_fname = 'LINE_COLOR'.
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
Value of traffic light field
g_wa_sflight-traffic_light = '1'.
Value of color field:
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
*-- End of grid setup -
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid. This is not necessary in this
example as there is only one control on the screen
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0200 INPUT
&----
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT200'.
LEAVE TO SCREEN 100.
WHEN'SAVE'.
PERFORM save_changes.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
&----
*& Form get_data
&----
FORM get_data.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
ENDFORM. " load_data_into_grid
&----
*& Form change_flight
&----
Reads the contents of the selected row in the grid, ans transfers
the data to screen 200, where it can be changed and saved.
----
FORM change_flight.
DATA:l_lines TYPE i.
REFRESH gi_index_rows.
CLEAR g_selected_row.
Read index of selected rows
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
Check if any row are selected at all. If not
table gi_index_rows will be empty
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a line'.
EXIT.
ENDIF.
Read indexes of selected rows. In this example only one
row can be selected as we are using gs_layout-sel_mode = 'B',
so it is only ncessary to read the first entry in
table gi_index_rows
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Transfer data from the selected row to screenm 200 and show
screen 200
CLEAR g_screen200.
MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
LEAVE TO SCREEN '200'.
ENDFORM. " change_flight
&----
*& Form save_changes
&----
Changes made in screen 200 are written to the datbase table
zsflight, and to the grid table gi_sflight, and the grid is
updated with method refresh_table_display to display the changes
----
FORM save_changes.
DATA: l_traffic_light TYPE c.
Update traffic light field
Update database table
MODIFY zsflight FROM g_screen200.
Update grid table , traffic light field and color field.
Note that it is necessary to use structure g_wa_sflight
for the update, as the screen structure does not have a
traffic light field
MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
clear g_wa_sflight-line_color.
ELSE.
g_wa_sflight-traffic_light = '3'.
clear g_wa_sflight-line_color.
ENDIF.
MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
Refresh grid
CALL METHOD go_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN '100'.
ENDFORM. " save_changes
chk this blog
/people/vijaybabu.dudla/blog/2006/07/21/topofpage-in-alv-using-clguialvgrid
Regards
Anji
‎2007 Oct 04 4:41 PM
Here is the first half of the program that shows the Methods I'm using and what I've tried to do. Maybe that will help make things clearer.
program ZPAPAI0022_UPDT_MERIT_ELIG_ONG
MESSAGE-ID ZF.
*Original program data fields copied from ZFIFMR0020_CF_FIXED
*----
-
TABLES, ITABS AND STRUCTURES
*----
-
TABLES: ZHCM_MERIT_ELIG, "Merit Increase Eligibility Table
PA0001,
SSCRFIELDS. "Screen fields
**Define the structure to hold the header for a journal
TYPES: BEGIN OF I_MERIT,
PERNR LIKE P0001-PERNR,
GSBER LIKE P0001-GSBER,
WERKS LIKE P0001-WERKS,
SNAME LIKE P0001-SNAME,
BEGDA LIKE P0001-BEGDA,
CPLAN LIKE T71CA-CPLAN,
ELIGIBLE LIKE ZHCM_MERIT_ELIG-ELIGIBLE,
NOT_ELIGIBLE LIKE ZHCM_MERIT_ELIG-NOT_ELIGIBLE,
EMPCT LIKE ZHCM_MERIT_ELIG-EMPCT,
STATUS LIKE ZHCM_MERIT_ELIG-STATUS,
CELLTAB type LVC_T_STYL,
END OF I_MERIT.
TYPES: BEGIN OF T_MERIT_OUT_ALV,
PERNR LIKE P0001-PERNR,
GSBER LIKE P0001-GSBER,
WERKS LIKE P0001-WERKS,
SNAME LIKE P0001-SNAME,
BEGDA LIKE P0001-BEGDA,
CPLAN LIKE T71CA-CPLAN,
ELIGIBLE LIKE ZHCM_MERIT_ELIG-ELIGIBLE,
NOT_ELIGIBLE LIKE ZHCM_MERIT_ELIG-NOT_ELIGIBLE,
EMPCT LIKE ZHCM_MERIT_ELIG-EMPCT,
STATUS LIKE ZHCM_MERIT_ELIG-STATUS,
CELLTAB type LVC_T_STYL,
END OF T_MERIT_OUT_ALV.
DATA:
I_ALV_MERIT TYPE STANDARD TABLE
OF T_MERIT_OUT_ALV
WITH HEADER LINE.
types: begin of ty_merit_change,
PERNR LIKE ZHCM_MERIT_ELIG-PERNR, "Personnel Number
GSBER LIKE ZHCM_MERIT_ELIG-GSBER, "Business Area
WERKS LIKE ZHCM_MERIT_ELIG-WERKS, "Personnel Area
CPLAN LIKE ZHCM_MERIT_ELIG-CPLAN, "Merit Elig Code
BEGDA like ZHCM_MERIT_ELIG-BEGDA, "Effective Date
ELIGIBLE LIKE ZHCM_MERIT_ELIG-ELIGIBLE, "Elgibility Indicator
NOT_ELIGIBLE LIKE ZHCM_MERIT_ELIG-NOT_ELIGIBLE,
EMPCT LIKE ZHCM_MERIT_ELIG-EMPCT,
STATUS LIKE ZHCM_MERIT_ELIG-STATUS,
end of ty_merit_change.
DATA: I_MERIT_CHANGE TYPE HASHED TABLE
OF ty_merit_change
WITH UNIQUE KEY PERNR GSBER WERKS
WITH HEADER LINE.
DATA: ZTIME(6) TYPE C,
ITAB_EXPORT(10) TYPE C,
ZDATA_CHNGED TYPE C VALUE 'N',
REPLY TYPE C,
WS_LINE_CNT TYPE I.
DATA: BEGIN OF WS,
REC_CNT(10) TYPE P, "Processed records
CANCELLED(1) TYPE C, "file read cancelled
COMMAND_LINE LIKE RLGRAP-FILENAME,
FILENAME LIKE RLGRAP-FILENAME,
FILETYPE LIKE RLGRAP-FILETYPE,
FILELGTH(40) TYPE C,
MAPPE LIKE APQI-GROUPID, "jc01182007
SUM LIKE BPBY-WLJHR,
NUMBERS(10) TYPE C VALUE '0123456789',
DATETIME(16) TYPE C,
E(1) TYPE C VALUE 'E', "LANGUAGE CODE
COUNT TYPE I, "COUNT FOR FILE HEADER
DTF(60) TYPE C,
DIRFILE(60) TYPE C,
NO_RECORDS(1) TYPE C,
ARK(3) TYPE C VALUE 'ARK',
ONE TYPE C VALUE '1',
COLON(1) TYPE C VALUE ':',
MARK(1) TYPE C VALUE 'X',
FYR(4) TYPE C,
FILERR(1) VALUE 'N',
BUDREL(1) VALUE 'Y',
DATE LIKE SY-DATUM,
date_cur(10), "jc01182007
date_new(10), "jc01182007
date_out type sy-datum, "jc01182007
TIME LIKE SY-UZEIT,
DOCTYPE LIKE BKPF-BLART,
LINES TYPE I,
rfipex like zfmcfblock-fipex,
END OF WS.
*SYS_HDR constains the system ID and the client
DATA: BEGIN OF SYS_HDR,
SYS LIKE SY-SYSID,
FIL(1) TYPE C VALUE '/',
CLT LIKE SY-MANDT,
END OF SYS_HDR.
*Contains the report name and the user id.
DATA: BEGIN OF RPT_AND_USER,
RPT LIKE SY-REPID,
FIL(1) TYPE C VALUE '/',
USR LIKE SY-UNAME,
END OF RPT_AND_USER.
*Object oriented data fields
data: ok_code like sy-ucomm,
save_ok like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
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,
gs_layout type lvc_s_layo.
local class to handle semantic checks
class lcl_event_receiver definition deferred.
data: g_event_receiver type ref to lcl_event_receiver.
types: begin of ty_mod_cells,
row_id like lvc_s_modi-row_id,
PERNR LIKE ZHCM_MERIT_ELIG-PERNR, "Personnel Number
GSBER LIKE ZHCM_MERIT_ELIG-GSBER, "Business area
WERKS LIKE ZHCM_MERIT_ELIG-WERKS, "Personnel Area
ELIGIBLE LIKE ZHCM_MERIT_ELIG-ELIGIBLE, "Eligible Flag
NOT_ELIGIBLE LIKE ZHCM_MERIT_ELIG-NOT_ELIGIBLE, "Not Eligible
end of ty_mod_cells.
data: it_mod_cells type standard table of ty_mod_cells
with header line.
data: zit_mod_cells type standard table of ty_mod_cells
with header line.
data: it_hold_mod_cells type standard table of ty_mod_cells
with header line.
START OF COMMENT ************
***************************************************************
LOCAL CLASS Definition
***************************************************************
**§4.Define and implement event handler to handle event DATA_CHANGED.
**
class lcl_event_receiver definition.
*
public section.
methods:
handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed,
handle_top_of_page
for event print_top_of_page of cl_gui_alv_grid.
*
*
private section.
This flag is set if any error occured in one of the
following methods:
data: error_in_data type c.
data: ls_good type lvc_s_modi.
data: s_mod_cells type ty_mod_cells.
*
Methods to modularize event handler method HANDLE_DATA_CHANGED:
*
**....................................................................
This is a suggestion how you could comment your checks in each
*method:
**.....
CHECK: fieldname(old/new value) !<comp> fieldname(old/new value)
IF NOT: (What to tell the user is wrong about the input)
**......
Remarks:
fieldname: fieldname of table for the corresponding column
(old/new value): ckeck with value of GT_OUTTAB or MT_GOOD_CELLS.
!<comp> : the value is valid if the condition <comp> holds.
**
*.
*
methods: check_cplan
importing
ps_good_cplan type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods: check_eligible
importing
ps_good_eligible type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods: check_not_eligible
importing
ps_good_not_eligible type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods: check_begda
importing
ps_good_begda type lvc_s_modi
pr_data_changed type ref to cl_alv_changed_data_protocol.
*
*
endclass. "lcl_event_receiver DEFINITION
**----
-
class lcl_event_receiver implementation.
method handle_data_changed.
*
*
error_in_data = space.
clear i_merit_change.
refresh i_merit_change.
*
semantic checks
*
Identify columns which were changed and check input
against output table gt_outtab or other new input values of one row.
*
Table er_data_changed->mt_good_cells holds all cells that
are valid according to checks against their DDIC data.
No matter in which order the input was made this table is
ordered by rows (row_id). For each row, the entries are
sorted by columns according to their order in the fieldcatalog
(not the defined order using field COL_POS but the order
given by the position of the record in the fieldcatalog).
*
The order is relevant if new inputs in several columns of
the same row are dependent.
*
**§5.Loop over table MT_GOOD_CELLS to check all values that are
valid due to checks according to information of the DDIC.
data: ls_merit_change type ty_merit_change.
refresh i_merit_change.
loop at er_data_changed->mt_good_cells into ls_good.
case ls_good-fieldname.
check if column CPLAN of this row was changed
when 'CPLAN'.
call method check_cplan
EXPORTING
ps_good_cplan = ls_good
pr_data_changed = er_data_changed.
when 'ELIGIBLE'.
call method check_eligible
EXPORTING
ps_good_eligible = ls_good
pr_data_changed = er_data_changed.
when 'NOT_ELIGIBLE'.
call method check_not_eligible
EXPORTING
ps_good_not_eligible = ls_good
pr_data_changed = er_data_changed.
when 'BEGDA'.
call method check_begda
EXPORTING
ps_good_begda = ls_good
pr_data_changed = er_data_changed.
endcase.
endloop.
*
*
**§7.Display application log if an error has occured.
if error_in_data eq 'X'.
call method er_data_changed->display_protocol.
refresh it_mod_cells.
else.
append lines of it_mod_cells to it_hold_mod_cells.
endif.
*
*
*
endmethod. "handle_data_changed
**----
-
*
method handle_top_of_page.
write: /,'Event: PRINT_TOP_OF_PAGE'(001).
endmethod. "handle_top_of_page
**----
-
*
*
method check_cplan.
*..................................................
Overview of checks according to field CPLAN
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
*...................................................
data: l_cplan type CMP_PLAN.
data s_alv type t_merit_out_alv.
data: s_merit_change type ty_merit_change.
Get new cell value to check it.
call method pr_data_changed->get_cell_value
EXPORTING
i_row_id = ps_good_cplan-row_id
i_fieldname = ps_good_cplan-fieldname
IMPORTING
e_value = l_cplan.
In case of error, create a protocol entry in the application log.
Possible values for message type ('i_msgty'):
*
if L_cplan = 'MERE' OR
L_cplan = 'MERA' OR
L_cplan = 'MERS' OR
L_cplan = 'MERU' OR
L_cplan = 'NOEV'.
ELSE.
call method pr_data_changed->add_protocol_entry
EXPORTING
i_msgid = 'ZF'
i_msgno = '095'
i_msgty = 'E'
i_msgv1 = 'Invalid Plan Code'
i_fieldname = ps_good_cplan-fieldname
i_row_id = ps_good_cplan-row_id.
error_in_data = 'X'.
exit.
endif.
modify table i_merit_change from s_merit_change.
clear s_mod_cells.
s_mod_cells-row_id = ls_good-row_id.
s_mod_cells-pernr = s_alv-pernr.
s_mod_cells-gsber = s_alv-gsber.
s_mod_cells-werks = s_alv-werks.
s_mod_cells-pernr = s_alv-pernr.
ZDATA_CHNGED = 'Y'.
append s_mod_cells to it_mod_cells.
endmethod. "check_cplan
method check_ELIGIBLE.
*..................................................
Overview of checks according to field CPLAN
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
*...................................................
data: l_ELIGIBLE type CMP_CELIG.
data s_alv type t_merit_out_alv.
data s_alv2 type t_merit_out_alv.
data: s_merit_change type ty_merit_change.
data: znot_eligible like zhcm_merit_elig-not_eligible.
Get new cell value to check it.
call method pr_data_changed->get_cell_value
EXPORTING
i_row_id = ps_good_eligible-row_id
i_fieldname = ps_good_eligible-fieldname
IMPORTING
e_value = l_eligible.
READ TABLE IT_MOD_CELLS INDEX ps_good_eligible-row_id
into zit_mod_cells.
IF SY-SUBRC = 0.
MOVE ZIT_MOD_CELLS-NOT_ELIGIBLE TO ZNOT_ELIGIBLE.
ELSE.
READ TABLE I_ALV_MERIT INDEX ps_good_eligible-row_id
into s_alv.
IF SY-SUBRC = 0.
MOVE S_ALV-NOT_ELIGIBLE TO ZNOT_ELIGIBLE.
ENDIF.
ENDIF.
IF L_ELIGIBLE = 'X' AND
ZNOT_ELIGIBLE = 'X'.
call method pr_data_changed->add_protocol_entry
EXPORTING
i_msgid = 'ZF'
i_msgno = '095'
i_msgty = 'E'
i_msgv1 = 'ELIGIBLE & NOT ELIGIBLE BOTH = X'
i_fieldname = ps_good_eligible-fieldname
i_row_id = ps_good_eligible-row_id.
*
error_in_data = 'X'.
exit.
endif.
READ TABLE I_ALV_MERIT INDEX ps_good_eligible-row_id into s_alv.
clear s_mod_cells.
s_mod_cells-row_id = ls_good-row_id.
s_mod_cells-pernr = s_alv-pernr.
s_mod_cells-gsber = s_alv-gsber.
s_mod_cells-werks = s_alv-werks.
s_mod_cells-pernr = s_alv-pernr.
s_mod_cells-eligible = l_eligible.
s_mod_cells-not_eligible = s_alv-not_eligible.
ZDATA_CHNGED = 'Y'.
append s_mod_cells to it_mod_cells.
endmethod. "check_eligible
method check_NOT_ELIGIBLE.
*..................................................
Overview of checks according to field NOT_ELIGIBLE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
data: l_NOT_ELIGIBLE type CMP_CELIG.
data s_alv type t_merit_out_alv.
data s_alv2 type t_merit_out_alv.
data: s_merit_change type ty_merit_change.
data: ZELIGIBLE LIKE ZHCM_MERIT_ELIG-ELIGIBLE.
Get new cell value to check it.
call method pr_data_changed->get_cell_value
EXPORTING
i_row_id = ps_good_not_eligible-row_id
i_fieldname = ps_good_not_eligible-fieldname
IMPORTING
e_value = l_not_eligible.
READ TABLE IT_MOD_CELLS INDEX ps_good_not_eligible-row_id
into zit_mod_cells.
IF SY-SUBRC = 0.
MOVE ZIT_MOD_CELLS-ELIGIBLE TO ZELIGIBLE.
ELSE.
READ TABLE I_ALV_MERIT INDEX ps_good_not_eligible-row_id
into s_alv.
IF SY-SUBRC = 0.
MOVE S_ALV-ELIGIBLE TO ZELIGIBLE.
ENDIF.
ENDIF.
IF L_NOT_ELIGIBLE = 'X' AND
ZELIGIBLE = 'X'.
call method pr_data_changed->add_protocol_entry
EXPORTING
i_msgid = 'ZF'
i_msgno = '095'
i_msgty = 'E'
i_msgv1 = 'ELIGIBLE & NOT ELIGIBLE BOTH = X'
i_fieldname = ps_good_not_eligible-fieldname
i_row_id = ps_good_not_eligible-row_id.
error_in_data = 'X'.
exit.
endif.
READ TABLE I_ALV_MERIT INDEX ps_good_not_eligible-row_id
into s_alv.
IF SY-SUBRC = 0.
S_MERIT_CHANGE = S_ALV.
S_ALV-NOT_ELIGIBLE = L_NOT_ELIGIBLE.
modify table i_merit_change from s_merit_change.
ENDIF.
READ TABLE I_ALV_MERIT INDEX ps_good_not_eligible-row_id
into s_alv.
clear s_mod_cells.
s_mod_cells-row_id = ls_good-row_id.
s_mod_cells-pernr = s_alv-pernr.
s_mod_cells-gsber = s_alv-gsber.
s_mod_cells-werks = s_alv-werks.
s_mod_cells-pernr = s_alv-pernr.
s_mod_cells-eligible = zit_mod_cells-eligible.
s_mod_cells-not_eligible = L_not_eligible.
ZDATA_CHNGED = 'Y'.
append s_mod_cells to it_mod_cells.
endmethod. "check_not_eligible
‎2007 Oct 04 4:48 PM
Hi,
May this way
*----------------------------------------------------------------------*
* Module Pai INPUT *
*----------------------------------------------------------------------*
* PAI module *
*----------------------------------------------------------------------*
module pai input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when 'EXIT'.
perform f_exit_program.
when 'SAVE'.
perform f_save_data.
endcase.
endmodule. " Pai INPUT
*&---------------------------------------------------------------------*
* Form f_save_data *
*&---------------------------------------------------------------------*
* After save *
*----------------------------------------------------------------------*
form f_save_data .
data : p_index like sy-index.
refresh : i_message, i_message1.
call method g_grid->check_changed_data
importing
e_valid = v_valid.
if not v_valid is initial.
if save_ok eq 'SAVE'.
perform f_validate_data_before_save. "<<<<<< do your validation
" and Push all errors into a internal table i_message
endif.
if not i_message[] is initial.
perform f_display_status_logs. "<<<< display Error logs
else.
"<<<<<<< Save your data to table
endif.
endif.
endform.
a®
‎2007 Oct 04 5:33 PM
Hello Richard
If I understand you correctly the two checkbox fields basically should function like two radiobuttons: only one of them can be active (perhaps both can be inactive as initial state).
You may have a look at at my sample report which demonstrates the use of radiobuttons on ALV list:
<a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ALVGridListUsingRadio+Buttons">ALV Grid List Using Radio Buttons</a>
Regards
Uwe