2009 Feb 16 9:40 AM
kindly send me a ALV sample piece of code where a particular column is edited by the user. This ALV is displayed using Factory method
Thanks,
Ginni
kindly send me a ALV sample piece of code where a particular column is edited by the user. This ALV is displayed using Factory method
Thanks,
Ginni
2009 Feb 16 9:43 AM
Hi,
Go to se38: BCALV* and press F4.
you will get all standard SAP ALV examples
Thanks,
Sendil
2009 Feb 16 9:44 AM
Hi,
see this example.
data
w_lay TYPE lvc_s_layo.
w_lay-grid_title = 'Flight details'.
w_lay-zebra = 'X'.
w_lay-edit = 'X'.
w_lay-CWIDTH_OPT = 'X'.
CALL METHOD r_alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'FS'
is_layout = w_lay( layout structure )
CHANGING
it_outtab = itab
it_fieldcatalog = t_cat.
2009 Feb 16 9:45 AM
2009 Feb 16 9:46 AM
Hi,
Dont Hasitate to search on SCN.
Go through BCALV* programes.
2009 Feb 16 9:47 AM
2009 Feb 16 9:47 AM
Hi Ginni,
For your requirement you need to use lvc_s_fcat .
If you want a column should be editable by the end-user then you need to make the EDIT field of the field catalog table 'X' for that paricular field .
In the following code Select and carrid field is editable.Try this code -
REPORT yh1333_alv.
DATA : w_cont TYPE REF TO cl_gui_custom_container,
w_grid TYPE REF TO cl_gui_alv_grid.
DATA : fs_fcat TYPE lvc_s_fcat,
fs_layo TYPE lvc_s_layo,
t_fcat TYPE lvc_t_fcat.
fs_layo-language = 'D'.
DATA : BEGIN OF fs_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE d,
price TYPE sflight-price,
w_check(1) TYPE c,
END OF fs_sflight,
fs_sflight1 LIKE sflight,
t_sflight LIKE TABLE OF fs_sflight.
START-OF-SELECTION.
SELECT carrid connid fldate price FROM sflight
INTO TABLE t_sflight .
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STAT'.
* SET TITLEBAR 'xxx'.
CREATE OBJECT w_cont
EXPORTING
* parent =
container_name = 'CONT'
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT w_grid
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = w_cont
* i_appl_events = space
* i_parentdbg =
* i_applogparent =
* i_graphicsparent =
* i_name =
* i_fcat_complete = space
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
fs_fcat-fieldname = 'W_CHECK'.
fs_fcat-coltext = 'Select'.
fs_fcat-checkbox = 'X'.
* fs_fcat-col_pos = 6.
fs_fcat-edit = 'X'. " This field is editable
*fs_fcat-emphasize = 7.
APPEND fs_fcat TO t_fcat.
CLEAR fs_fcat.
*fs_fcat-row_pos = '1'.
* fs_fcat-col_pos = '2'.
fs_fcat-edit = 'X'. " This field is editable
fs_fcat-fieldname = 'CARRID'.
fs_fcat-coltext = 'ID'.
APPEND fs_fcat TO t_fcat.
clear fs_fcat.
*fs_fcat-row_pos = '2'.
* fs_fcat-col_pos = '3'.
fs_fcat-fieldname = 'CONNID'.
fs_fcat-coltext = 'Connection ID'.
APPEND fs_fcat TO t_fcat.
*fs_fcat-row_pos = '3'.
* fs_fcat-col_pos = '4'.
fs_fcat-fieldname = 'FLDATE'.
fs_fcat-coltext = 'Flight Date'.
APPEND fs_fcat TO t_fcat.
*fs_fcat-row_pos = '4'.
* fs_fcat-col_pos = '5'.
fs_fcat-fieldname = 'PRICE'.
fs_fcat-coltext = 'PRICE'.
APPEND fs_fcat TO t_fcat.
CLEAR fs_fcat.
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = 'FS_SFLIGHT'
* is_variant =
* i_save =
* i_default = 'X'
is_layout = fs_layo
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = t_sflight
it_fieldcatalog = t_fcat
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0 .
WHEN 'PICK'.
WRITE 'Testing through pick'.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUTThanks and regards
Pinaki
2009 Feb 16 9:51 AM
start-of-selection .
perform get_data_from_db .
fill the fieldcat
This fieldcat also disables some columns (without any criteria)
perform fill_fieldcat_a(ZREPORT1) tables go_fieldcat .
Manipulate the layout gs_layout ??
Create objects
IF go_custom_container IS INITIAL.
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
ENDIF.
Load data into the grid and display them
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'ZTAB1'
is_layout = gs_layout
CHANGING
it_fieldcatalog = go_fieldcat
it_outtab = gi_ZTAB1.
set screen 100 .
Calls the screen which contains the container ALV_CONTAINER
regards
Gokul
2009 Feb 16 9:55 AM
Hi Ginni,
here is a sample code alv with oops where a particular field is in edit mode..
after a change is made u need to perform validation of the entry...
also create screen 444.(double click on 444 and proceed)
and set the 'pf-status'.
TABLES: vbak.
DATA:
fs_layout TYPE lvc_s_layo,
t_cat TYPE lvc_t_fcat,
fs_cat LIKE LINE OF t_cat.
DATA: r_container TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid.
* internal table t_tab
DATA: BEGIN OF t_tab OCCURS 0.
INCLUDE STRUCTURE vbak.
DATA: celltab TYPE lvc_t_styl,
END OF t_tab.
START-OF-SELECTION.
SELECT * FROM vbak UP TO 100 ROWS INTO CORRESPONDING FIELDS OF TABLE t_tab.
END-OF-SELECTION.
CALL SCREEN 444.
*&---------------------------------------------------------------------*
*& Module DISPLAY OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display OUTPUT.
SET PF-STATUS 'STAT'.
SET TITLEBAR 'Sales Document Header Data'.
IF r_container IS INITIAL.
CREATE OBJECT r_container
EXPORTING
* parent =
container_name = 'CONTAINER'
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
* EXCEPTIONS
* cntl_error = 1
* cntl_system_error = 2
* create_error = 3
* lifetime_error = 4
* lifetime_dynpro_dynpro_link = 5
* others = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT r_grid
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = r_container
* i_appl_events = space
* i_parentdbg =
* i_applogparent =
* i_graphicsparent =
* i_name =
* i_fcat_complete = space
* EXCEPTIONS
* error_cntl_create = 1
* error_cntl_init = 2
* error_cntl_link = 3
* error_dp_create = 4
* others = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = t_cat
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
fs_layout-smalltitle = 'X'.
fs_layout-zebra = 'X'.
fs_layout-grid_title = 'FLIGHT details'.
fs_layout-cwidth_opt = 'X'.
fs_cat-edit = 'X'.
fs_cat-CHECKTABLE = '!'.
MODIFY t_cat FROM fs_cat
TRANSPORTING edit checktable
where fieldname eq 'NETWR'.
CALL METHOD r_grid->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name = 'VBAK'
* is_variant =
* i_save =
* i_default = 'X'
is_layout = fs_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = t_tab[]
it_fieldcatalog = t_cat
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* CALL METHOD r_grid->set_ready_for_input
* EXPORTING
* i_ready_for_input = 1.
*
ENDIF.
ENDMODULE. " DISPLAY OUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0444 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0444 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
SET SCREEN '0'.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
ENDCASE.
ENDMODULE. " USER_COMMAND_0444 INPU
*&---------------------------------------------------------------------*
*& Form SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM switch_edit_mode.
IF r_grid->is_ready_for_input( ) EQ 1.
CALL METHOD r_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ELSE.
CALL METHOD r_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDIF.
ENDFORM. " SWITCH_EDIT_MOD
Regards,
Mdi.Deeba.
2009 Feb 16 9:56 AM
2009 Feb 16 9:57 AM
Hi Ginni,
->First declare a field catalog of type like:
DATA : it_field TYPE slis_t_fieldcat_alv,
wa_field TYPE slis_fieldcat_alv.
->Then maintain field catalog for the table fields to be displayed in the output like this:
wa_field-fieldname = 'EBELN'.
wa_field-tabname = 'IT_TAB'.
wa_field-outputlen = 20.
wa_field-col_pos = '1'.
wa_field-seltext_l ='P.O NUMBER'.
wa_field-input = 'X'.
wa_field-edit = 'X'. "for making the field editable by the user
*WA_FIELD-HOTSPOT = 'X'.
APPEND wa_field TO it_field.
CLEAR wa_field.
->And then pass this internal table it_field into the function module
Reuse_ALV_grid_display 's parameter:
IT_FIELDCAT = it_field
Hope it helps
Regrds
Mansi
2009 Feb 16 9:58 AM
Hi Ginni,
Class CL_SALV_TABLE does not support editable cells, nor does it support editable columns or rows. You must use the class CL_GUI_ALV_GRID in order to have this functionallity.
Regards,
Nitin.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |