‎2006 Mar 02 8:20 PM
Hi all,
My requirement is like this. I need to display the output of ALV in editable mode and handle the edited values in my program. I nnow how to display ALV output in editable mode but I dont have any idea as how to handle edited values in program . can anyone please help me out with this.
Regards,
Varun.
‎2006 Mar 02 8:23 PM
Hi Varun,
Please set the 'EDIT' flag at fields catalog:
Data : WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: ITAB_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.
CLEAR WA_FIELDCAT.
<b> WA_FIELDCAT-EDIT = 'X'.</b>
MODIFY ITAB_FLDCAT FROM WA_FIELDCAT TRANSPORTING EDIT
HERE FIELDNAME = < field NAme>.
Define User Command and try to change the values at EDItable cells :
*--Call ALV GRID Display using internal table TAB_DATA(Variant table)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_PF_STATUS'
I_CALLBACK_USER_COMMAND = <b>'FRM_USER_COMMAND'</b>
*---Subroutine to handle user actions on the output.
FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'SELECT'. "Select Values
Chang values at editable fields.
ENDCASE.
*--then use the belolw REFRESH this will show all the changed values.
RS_SELFIELD-REFRESH = 'X'. .
ENDFORM
Regards,
Lanka
Message was edited by: Lanka Murthy
‎2006 Mar 02 8:23 PM
Hi Varun,
Please set the 'EDIT' flag at fields catalog:
Data : WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: ITAB_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.
CLEAR WA_FIELDCAT.
<b> WA_FIELDCAT-EDIT = 'X'.</b>
MODIFY ITAB_FLDCAT FROM WA_FIELDCAT TRANSPORTING EDIT
HERE FIELDNAME = < field NAme>.
Define User Command and try to change the values at EDItable cells :
*--Call ALV GRID Display using internal table TAB_DATA(Variant table)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_PF_STATUS'
I_CALLBACK_USER_COMMAND = <b>'FRM_USER_COMMAND'</b>
*---Subroutine to handle user actions on the output.
FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'SELECT'. "Select Values
Chang values at editable fields.
ENDCASE.
*--then use the belolw REFRESH this will show all the changed values.
RS_SELFIELD-REFRESH = 'X'. .
ENDFORM
Regards,
Lanka
Message was edited by: Lanka Murthy
‎2006 Mar 02 8:27 PM
Hi Lanka,
<b>Where will the edited values wil be stored ?</b>Do you want me to use any push button like SELECT ?
Lanka, can you please explain me in detail ?
Regards,
Varun
Message was edited by: varun sonu
‎2006 Mar 02 9:05 PM
Hi Varun,
In FORM and ENDFORM --Read the table <TAB_DATA> (Internal table that you are passing to ALV function.
READ TABLE <TAB_DATA> INDEX RS_SELFIELD-TABINDEX.
Change the editable values by calling a POP-up function so that user can enter his values.
Then modify the <TAB_DATA>
Regards,
Lanka
‎2006 Mar 02 9:25 PM
Hi Lanka,
Chek this code. You will get a clear of what I am doing. Why do I need a popup ? I want to make changes in the editable output and capture that value into a variable.
REPORT ZALV_EDIT.
type-pools: slis.
*- Fieldcatalog
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*- For Events
DATA:IT_EVENTS TYPE SLIS_T_EVENT.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
data vbeln1 like vbap-vbeln.
data: begin of itab occurs 0,
vblen like vbap-vbeln,
posnr like vbap-posnr,
check(1),
end of itab.
select vbeln
posnr
up to 10 rows
into table itab
from vbap.
DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'CHECK'.
X_FIELDCAT-FIELDNAME = 'CHECK'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '1'.
X_FIELDCAT-checkbox = 'X'.
X_FIELDCAT-INPUT = 'X'. "edit
X_FIELDCAT-EDIT = 'X'. "edit
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'VBELN'.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
X_FIELDCAT-INPUT = 'X'. "edit
X_FIELDCAT-EDIT = 'X'. "edit
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'POSNR'.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELDCAT
I_CALLBACK_PF_STATUS_SET = 'FRM_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
TABLES
T_OUTTAB = ITAB[]
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.
FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
case sy-ucomm.
when 'SELECT'.
read table itab index rs_selfield-tabindex.
vbeln1 = rs_selfield-value.
endcase.
RS_SELFIELD-REFRESH = 'X'.
ENDFORM.
form frm_pf_status using rt_extab type slis_t_extab.
set pf-status 'ZVJ'.
endform.
Regards,
Varun.
‎2006 Mar 02 9:28 PM
Hi Varun,
I have just given a suggestion as you can use pop-up:
Please add the following at your code :
when 'SELECT'.
read table itab index rs_selfield-tabindex.
vbeln1 = rs_selfield-value.
<u>MODIFY ITAB INDEX RS_SELFIELD-TABINDEX.</u>
endcase.
Regards,
Lanka
‎2006 Mar 02 8:52 PM
Hi Varun,
Check the example given by SAP in se38.
<b>BCALV_TEST_GRID_EDITABLE.</b>
‎2006 Mar 02 8:58 PM
Hi Phani,
I am using Functional Modules. Not only that to understand the program one needs to understand classes and all that stuff like that. I am not aware of classes concept.
Regards,
Vijay,
‎2006 Mar 02 8:59 PM
The selected record index value is stored in structure rs_selfield of type slis_selfield. This will also contain details for the field and respective value.
Read internal table with index rs_selfield-tabindex and update the value.
Use debugging mode for a clear idea.
‎2006 Mar 02 9:31 PM
Hi ,
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:
<b>get_cell_value</b>
Gets the cell value. You pass the address of the cell to the interface.
<b>modify_cell</b>
Modifies the cell value addressed via parameters.
<b>add_protocol_entry</b>
Add a log entry. You make use of standard message interface with message type, message id, etc
<b>protocol_is_visible</b>
Make the error table visible or not.
<b>refresh_protocol</b>
Refreshing log entries.
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
Utilizing these methods and attributes you can check and give proper message and also modify the cell content.
Check the below Code for reference
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. " handle_data_changed
Regards,
Vara
‎2006 Mar 02 9:36 PM
Hi all,
Thank you all very much for helping me to sort out problem.
You all have a good one.
Regards,
Varun.
‎2006 Mar 03 4:54 AM
Hi Varun
easiest way to do this is
in the usercommand of the REUSE_ALV_GRID_DISPLAY
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
I_CALLBACK_USERCOMMAND = 'STORE_EDITABLE_FIELDs'.
END FUNCTION.
FORM 'STORE_EDITABLE_FIELDs'.
when 'SAVE'.
Data ref1 type ref to cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = ref1.
call method ref1->check_changed_data
*here ur editable fields are stored in ur internal table
ENDFORM.