02-08-2007 10:21 AM
Hi Gurus,
please help me the sample code for alv report in which the coloums are editable. And also explain me theoritically.
Thanks in Advance
Ravi Kanth .G
02-08-2007 10:24 AM
Thsi doc will be very useful for ALV,
And a sample code is below,
*&---------------------------------------------------------------------*
*& Report ZKB_EDIT_ALV
*&---------------------------------------------------------------------*
REPORT zkb_edit_alv.
DATA: i_zkb_test TYPE TABLE OF zkb_test,
w_zkb_test TYPE zkb_test.
DATA: o_grid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
DATA: lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo,
ls_sort TYPE lvc_s_sort,
lt_sort TYPE lvc_t_sort,
ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
START-OF-SELECTION.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module display_alv_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display_alv_9000 OUTPUT.
IF o_container IS INITIAL.
SELECT * FROM zkb_test INTO TABLE i_zkb_test.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
* Create a custom container control for ALV Control
CREATE OBJECT o_container
EXPORTING
container_name = 'CONTAINER'.
* Create a ALV Control
CREATE OBJECT o_grid
EXPORTING i_parent = o_container.
PERFORM build_field_catalgue.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = ls_layo
CHANGING
it_outtab = i_zkb_test
it_fieldcatalog = lt_fcat
it_sort = lt_sort[].
ENDIF.
ENDIF.
ENDMODULE. " display_alv_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'UPDATE'.
CALL METHOD o_grid->check_changed_data.
MODIFY zkb_test FROM TABLE i_zkb_test.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
MESSAGE 'Data updated' TYPE 'I'.
ENDIF.
* Refresh the same in ALV
CALL METHOD o_grid->refresh_table_display.
ENDCASE.
ENDMODULE. " user_command_9000 INPUT
*&---------------------------------------------------------------------*
*& Form build_field_catalgue
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalgue .
DATA: ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-cprog
i_internal_tabname = 'I_ZKB_TEST'
i_structure_name = 'ZKB_TEST'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = ls_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'FCAT Error' TYPE 'I'.
EXIT.
ENDIF.
LOOP AT ls_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = ls_fieldcat-fieldname. "Fieldname
ls_fcat-ref_table = ls_fieldcat-tabname. "DDIC ref struct
ls_fcat-inttype = ls_fieldcat-inttype. "Data type
ls_fcat-outputlen = ls_fieldcat-outputlen. "Column width
ls_fcat-coltext = ls_fieldcat-seltext_m. "Column Header
ls_fcat-seltext = ls_fieldcat-seltext_m. "Column Desc
ls_fcat-ref_field = ls_fieldcat-ref_fieldname. "Reference field
ls_fcat-ref_table = ls_fieldcat-ref_tabname. "Reference table
CASE ls_fieldcat-fieldname.
WHEN 'MANDT' OR 'SNO'.
ls_fcat-edit = ' '.
WHEN OTHERS.
ls_fcat-edit = 'X'.
ENDCASE.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDFORM. " build_field_catalgue
Regards
Kathirvel
02-08-2007 10:24 AM
Thsi doc will be very useful for ALV,
And a sample code is below,
*&---------------------------------------------------------------------*
*& Report ZKB_EDIT_ALV
*&---------------------------------------------------------------------*
REPORT zkb_edit_alv.
DATA: i_zkb_test TYPE TABLE OF zkb_test,
w_zkb_test TYPE zkb_test.
DATA: o_grid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
DATA: lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo,
ls_sort TYPE lvc_s_sort,
lt_sort TYPE lvc_t_sort,
ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
START-OF-SELECTION.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module display_alv_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display_alv_9000 OUTPUT.
IF o_container IS INITIAL.
SELECT * FROM zkb_test INTO TABLE i_zkb_test.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
* Create a custom container control for ALV Control
CREATE OBJECT o_container
EXPORTING
container_name = 'CONTAINER'.
* Create a ALV Control
CREATE OBJECT o_grid
EXPORTING i_parent = o_container.
PERFORM build_field_catalgue.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = ls_layo
CHANGING
it_outtab = i_zkb_test
it_fieldcatalog = lt_fcat
it_sort = lt_sort[].
ENDIF.
ENDIF.
ENDMODULE. " display_alv_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'UPDATE'.
CALL METHOD o_grid->check_changed_data.
MODIFY zkb_test FROM TABLE i_zkb_test.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
MESSAGE 'Data updated' TYPE 'I'.
ENDIF.
* Refresh the same in ALV
CALL METHOD o_grid->refresh_table_display.
ENDCASE.
ENDMODULE. " user_command_9000 INPUT
*&---------------------------------------------------------------------*
*& Form build_field_catalgue
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalgue .
DATA: ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-cprog
i_internal_tabname = 'I_ZKB_TEST'
i_structure_name = 'ZKB_TEST'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = ls_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'FCAT Error' TYPE 'I'.
EXIT.
ENDIF.
LOOP AT ls_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = ls_fieldcat-fieldname. "Fieldname
ls_fcat-ref_table = ls_fieldcat-tabname. "DDIC ref struct
ls_fcat-inttype = ls_fieldcat-inttype. "Data type
ls_fcat-outputlen = ls_fieldcat-outputlen. "Column width
ls_fcat-coltext = ls_fieldcat-seltext_m. "Column Header
ls_fcat-seltext = ls_fieldcat-seltext_m. "Column Desc
ls_fcat-ref_field = ls_fieldcat-ref_fieldname. "Reference field
ls_fcat-ref_table = ls_fieldcat-ref_tabname. "Reference table
CASE ls_fieldcat-fieldname.
WHEN 'MANDT' OR 'SNO'.
ls_fcat-edit = ' '.
WHEN OTHERS.
ls_fcat-edit = 'X'.
ENDCASE.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDFORM. " build_field_catalgue
Regards
Kathirvel
02-08-2007 10:28 AM
hi
good
go to se38 give BCALV* and than put f4 ,you ll get lots of example related to various scenarios,test them and use for your requirement.
Thanks
mrutyun^
02-08-2007 10:30 AM
Hi RaviKanth,
when you are filling up the FIELDCATALOG you have to give this statement.
WA_FIELDCAT-FIELDNAME = 'EBELP'.
WA_FIELDCAT-COL_POS = '2'.
WA_FIELDCAT-JUST = 'C'.
WA_FIELDCAT-SELTEXT_L = 'Item Number'.
WA_FIELDCAT-LOWERCASE = 'X'.
<b> WA_FIELDCAT-EDIT = 'X'.</b> " This is the statement.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
Thanks
Vikranth Khimavath
Message was edited by:
Khimavath Vikranth
02-08-2007 10:33 AM
Hi All,
Thanks for giving valuable answers.
Vikranth can u give me the answer after editing we have to save those changes into the database. For that what is the code we have to written.
Thanks,
Ravi Kanth
02-08-2007 10:36 AM
Hi Ravi,
Check this link.It has a sample code and theory.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_editable.htm
regards,
Priya.
02-08-2007 10:36 AM
Hello Ravi,
<b>To modify database or ztable from the ALV grid</b>,you need to do the following:
---You have to modify the field Catalog fields (fields that you want to make <b>editable).Set the field EDIT as 'X'</b>.For example if you want to make the field below editable:
ls_fcat-fieldname = 'CARRID'.
...
...
<b>ls_fcat-edit = 'X'.</b>
APPEND ls_fcat TO pt_fieldcat.
---Call the method below before you call the set_table_for_first_display.
<b>CALL METHOD ALV_GRID_INSTANCE->set_ready_for_input</b>
EXPORTING
i_ready_for_input = 0. ( For Display ) and ('1' for Edit )
After this put the set_table_for_first_display.
Now if the ALV data has changed,and you want to change the database or ztable,then in your pf status give a function code for SAVE button in the GUI.
In the PAI of the screen,in user command module write the following:
WHEN 'SAVE'.
<b>call method gr_alvgrid->check_changed_data</b>
importing e_valid = l_valid.
if l_valid = 'X'.
<b>MODIFY spfli FROM TABLE itab_spfli.</b>
endif.
(l_valid is a flag.
DATA:l_valid type c.
If you want to check if the user has entered any value on the grid, use the Method : CALL METHOD gr_alvgrid->check_changed_data.
This method returns a flag l_valid which can be checked to see if the data on the ALV grid has been changed or not.)
Also check:
<b>https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ec31e990-0201-0010-f4b6-c02d876ce033</b>
Regards,
Beejal
**Reward if this helps
02-08-2007 10:40 AM
Hi Rawal,
Thanks for your valuable suggestion. can you explain that concept with out object oriented. coz am using reuse_alv_grid_display.
Thanks
02-08-2007 10:57 AM
1. To make a field editable , in the fieldcatalog
wa_fieldcat-edit = 'X'.
2. to get the changed data reflected in internal table
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
I_CALLBACK_USERCOMMAND = 'USER_COMMAND'.
3. FORM USER_COMMAND using p_ucomm like sy-ucomm ......
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
CASE P_UCOMM.
ENDCASE.
ENDFORM.
02-08-2007 11:23 AM
hi,
inorder to change in alv grid and modify the changes to database table
we have to use field catalog-edit = x
and use user-command for modifying database
thank u
03-28-2007 8:28 AM
IN WHICH COLUMN U WANT TO MAKE IT EDITABLE NOTHING TO DO
MUCH FOR IT...AM SENDING U A SAMPLE CODE FOR IT..
JUST WRITE IT IN UR OWN CODE WHERE U DEFINE THE FIELD CATALOD FOR ALV DISPLAY..
wa_fieldcat-fieldname = 'EXNUM'.
wa_fieldcat-seltext_m = 'EXCISE INVOICE'.
wa_fieldcat-tabname = 'T_FINAL'.
WA_FIELDCAT-EDIT = 'X'. " THIS MAKES PERTICULAR COLUMN EDITABLE
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENJOY...