‎2007 Aug 07 2:20 PM
‎2007 Aug 07 2:23 PM
Hi,
alv list u cannot edit.
if u want to edit a grid.
use layout-edit = 'X'.
or if u want to edit a single column while creating the fieldcat give
fieldcat-edit = 'X'.
after reuse_alv_fieldcat_merge write like this.
Field-symbols: <lfs_fieldcat> TYPE slis_fieldcat_alv.
LOOP AT FCAT ASSIGNING <lfs_fieldcat>.
CASE <lfs_fieldcat>-fieldname.
WHEN 'FIELD'.
<lfs_fieldcat>-edit = 'X'.
ENDCASE.
ENDLOOP.
the edited values will be reflected in the internal table which u r showing in the grid.
loop at I_TAB.
read table I_TAB into outtab.
*filling the modified data in the grid into outtab
append outtab.
endloop.
modify DB_TABLE from table outtab.
<b>reward if helpful</b>
rgds,
bharat.
‎2007 Aug 07 2:24 PM
Hi,
We have demo porgrams in SAP itself ..
BCALV_EDIT_01
BCALV_EDIT_02
BCALV_EDIT_03
BCALV_EDIT_04
BCALV_EDIT_05
BCALV_EDIT_06
BCALV_EDIT_07
BCALV_EDIT_08
BCALV_FIELDCAT_TEST
BCALV_FULLSCREEN_GRID_EDIT
BCALV_GRID_EDIT
BCALV_GRID_EDIT_DELTA
BCALV_GRID_EDIT_DELTAM01
Regards
Sudheer
‎2007 Aug 07 2:24 PM
Hi
Making ALV Grid Editable
This may be one of the mostly-used functionalities of the ALV Grid since as a developer we prefer to use an ALV Grid instead of a table control for some reasons that are known by all of you (at least for the sake of appearance). In fact, making the ALV Grid editable has nothing to do with events. However, since controlling data input which is explained in the next section is related, it is better that we deal with this topic here.
To make a column editable, it will be sufficient to set the field EDIT in the field catalog. The ALV Grid perceives if there are some editable fields and adds buttons for editing purposes. If you do not need these new buttons, you know how to exclude them.
To make individual cells editable, we will utilize the table we used for making a cell a pushbutton. As you remember, it was of type LVC_T_STYL. If you have not added this inner table, add it now. For this procedure; add the name of the field to the field FIELDNAME, and pass cl_gui_alv_grid=>mc_style_enabled to make a field editable and cl_gui_alv_grid=>mc_style_disabled to make a field non-editable, to the field STYLE. You can use the one with disable when you make an entire column editable and want just a few of cells along it non-editable. As you remember from the pushbutton section we must tell the layout about this styling field.
e.g. ps_layout-stylefname = CELLSTYLES .
Now, lets solidify the procedure by code parts below. We want our column SEATSMAX entirely editable except the case CARRID is XY which is a rare case and we want our cells along the column PLANETYPE editable if their respective CONNID fields contain the value 02.
Assume we have added our style table (CELLSTYLES) to our list data table and tell the layout structure about it and we adjust the field catalog so that the column SEATSMAX has the property EDIT set to X.
FORM adjust_editables USING pt_list LIKE gt_list[] .
DATA ls_listrow LIKE LINE OF pt_list .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
LOOP AT pt_list INTO ls_listrow .
IF ls_listrow-carrid = 'XY' .
ls_stylerow-fieldname = 'SEATSMAX' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled .
APPEND ls_stylerow TO lt_styletab .
ENDIF .
IF ls_listrow-connid = '02' .
ls_stylerow-fieldname = 'PLANETYPE' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .
APPEND ls_stylerow TO lt_styletab .
ENDIF .
INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles .
MODIFY pt_list FROM ls_listrow .
ENDLOOP .
ENDFORMAs usual, cell based settings override entire column settings. You can dynamically switch between cases in any proper part of your execution. Just fill your inner table as required and refresh table display; for entire column settings, set or unset the property EDIT of the field catalog for the column and reset the field catalog using set_frontend_fieldcatalog.
As the last condition to be met for editability, you must call the method set_ready_for_input passing 1 to the parameter i_ready_for_input.
Using this method you can switch between editable and non-editable mode. As you guess, passing 0 to the parameter while calling the method, switches to non-editable mode.
Controlling Data Changes
As we can now make our ALV Grid editable we may require controlling input data. The ALV Grid has events data_changed and data_changed_finished. The former method is triggered just after the change at an editable field is perceived. Here you can make checks for the input. And the second event is triggered after the change is committed.
You can select the way how the control perceives data changes by using the method register_edit_event. You have two choices:
i. After return key is pressed: To select this way, to the parameter i_event_id pass cl_gui_alv_grid=>mc_evt_enter.
ii. After the field is modified and the cursor is moved to another field: For this, pass cl_gui_alv_grid=>mc_evt_modifies to the same parameter.
To make events controlling data changes be triggered, you must select either way by calling this method. Otherwise, these events will not be triggered.
To control field data changes, ALV Grid uses an instance of the class CL_ALV_CHANGED_DATA_PROTOCOL and passes this via the event data_changed. Using methods of this class, you can get and modify cell values and produce error messages. Here are some of those methods:
get_cell_value
Gets the cell value. You pass the address of the cell to the interface.
modify_cell
Modifies the cell value addressed via parameters.
add_protocol_entry
Add a log entry. You make use of standard message interface with message type, message id, etc
protocol_is_visible
Make the error table visible or not.
refresh_protocol
Refreshing log entries.
Table 16 Methods to use for controlling data changes
With the reference of the instance, you can reach information about modifications. These useful attribute tables are:
MT_MOD_CELLS
Contains addresses of modified cells with row_ids and fieldnames.
MP_MOD_ROWS
Contains modified rows. Its type is generic.
MT_GOOD_CELLS
Contains cells having proper values
MT_DELETED_ROWS
Contains rows deleted from the list
MT_INSERTED_ROWS
Contains rows inserted to the list
Table 17 Attribute tables to be used for controlling data changes
Utilizing these methods and attributes you can check and give proper message and also modify the cell content.
FORM handle_data_changed USING ir_data_changed
TYPE REF TO cl_alv_changed_data_protocol.
DATA : ls_mod_cell TYPE lvc_s_modi ,
lv_value TYPE lvc_value .
SORT ir_data_changed->mt_mod_cells BY row_id .
LOOP AT ir_data_changed->mt_mod_cells
INTO ls_mod_cell
WHERE fieldname = 'SEATSMAX' .
CALL METHOD ir_data_changed->get_cell_value
EXPORTING i_row_id = ls_mod_cell-row_id
i_fieldname = 'CARRID'
IMPORTING e_value = lv_value .
IF lv_value = 'THY' AND ls_mod_cell-value > '500' .
CALL METHOD ir_data_changed->add_protocol_entry
EXPORTING
i_msgid = 'SU'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = 'This number can not exceed 500 for '
i_msgv2 = lv_value
i_msgv3 = 'The value is et to ''500'''
i_fieldname = ls_mod_cell-fieldname
i_row_id = ls_mod_cell-row_id .
CALL METHOD ir_data_changed->modify_cell
EXPORTING i_row_id = ls_mod_cell-row_id
i_fieldname = ls_mod_cell-fieldname
i_value = '500' .
ENDIF .
ENDLOOP .
ENDFORM"handledatachangedThe event data_changed makes you aware about F4 functions. It sets the appropriate parameter from the group with respect to where it was triggered. These parameters are { E_ONF4, E_ONF4_BEFORE, E_ONF4_AFTER }.
Regards
Vivek Saxena
<b><i>
*Reward if useful</i></b>
Message was edited by:
vivek SAXENA
‎2007 Aug 07 2:27 PM
&----
*& Report ZDEMO_ALVGRID_EDIT *
*& *
&----
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic ALV grid, Enhanced to display specific fields as *
*& editable depending on field value *
&----
REPORT ZDEMO_ALVGRID_EDIT .
TABLES: ekko.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
field_style TYPE lvc_t_styl, "FOR DISABLE
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
wa_fieldcat TYPE lvc_s_fcat,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE lvc_s_layo, "slis_layout_alv,
gd_repid LIKE sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM set_specific_field_attributes.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
FORM build_fieldcatalog.
wa_fieldcat-fieldname = 'EBELN'.
wa_fieldcat-scrtext_m = 'Purchase Order'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_m = 'Material Number'.
wa_fieldcat-col_pos = 4.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
wa_fieldcat-edit = 'X'. "sets whole column to be editable
wa_fieldcat-col_pos = 7.
wa_fieldcat-outputlen = 15.
wa_fieldcat-datatype = 'CURR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos = 8.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
FORM build_layout.
Set layout field for field attributes(i.e. input/output)
gd_layout-stylefname = 'FIELD_STYLE'.
gd_layout-zebra = 'X'.
ENDFORM. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
FORM display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gd_repid
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout
it_fieldcat_lvc = it_fieldcat
i_save = 'X'
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
ENDFORM. " DATA_RETRIEVAL
&----
*& Form set_specific_field_attributes
&----
populate FIELD_STYLE table with specific field attributes
----
form set_specific_field_attributes .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
Populate style variable (FIELD_STYLE) with style properties
*
The NETPR field/column has been set to editable in the fieldcatalog...
The following code sets it to be disabled(display only) if 'NETPR'
is gt than 10.
LOOP AT it_ekko INTO wa_ekko.
IF wa_ekko-netpr GT 10.
ls_stylerow-fieldname = 'NETPR' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
APPEND ls_stylerow TO wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ENDIF.
ENDLOOP.
endform. " set_specific_field_attributes
Check this link.............
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_editable.htm
Regards,
Pavan
‎2007 Aug 07 2:39 PM
Hi
set the attribute as
wa_fieldcat-edit = 'X'.
and close all the solved threads with points,
regds,
kiran.M
‎2007 Aug 07 2:58 PM
Hi,
Please look in to the transaction DWDM for more examples.
Regs,
Venkat Ramanan N