‎2007 Apr 24 1:23 PM
hi folks,
i have a quite simple requirement but i do not find the right approach to it, so i would be very happy if anyone could get me started:
what i need is an enterable alvgrid where fieldnames along with checkboxes are displayed and where i can enter a value next to each row or add/delete lines, just as in SE 16.
Example:
KUNNR cb 20
ORT01 cb 50
Is there a simple and effective way to get this done ?
thanks - points will be surely awared generously
‎2007 Apr 24 1:26 PM
Example od editable ALV:
DATA: g_container TYPE scrfname VALUE 'CUSTOM CONTROL',
g_custom_container TYPE REF TO cl_gui_custom_container,
g_grid TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
.
DATA: gt_outtab TYPE TABLE OF sflight.
*---------------------------------------------------------------------*
* MAIN *
*---------------------------------------------------------------------*
CALL SCREEN 100 STARTING AT 1 1..
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module pbo OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container
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 g_grid
EXPORTING
i_parent = g_custom_container
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.
gs_layout-edit = 'X'.
SELECT * FROM sflight INTO TABLE gt_outtab UP TO 10 ROWS.
*§1.Set status of all cells to editable using the layout structure.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab
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.
*§2.Use SET_READY_FOR_INPUT to allow editing initially.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDIF.
ENDMODULE. " pbo OUTPUT
*&---------------------------------------------------------------------*
*& Module pai INPUT
*&---------------------------------------------------------------------*
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE. " pai INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
LEAVE PROGRAM.
ENDFORM. " exit_program
*&---------------------------------------------------------------------*
*& Form switch_edit_mode
*&---------------------------------------------------------------------*
FORM switch_edit_mode .
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
ENDFORM. " switch_edit_mode
‎2007 Apr 24 1:26 PM
Example od editable ALV:
DATA: g_container TYPE scrfname VALUE 'CUSTOM CONTROL',
g_custom_container TYPE REF TO cl_gui_custom_container,
g_grid TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
.
DATA: gt_outtab TYPE TABLE OF sflight.
*---------------------------------------------------------------------*
* MAIN *
*---------------------------------------------------------------------*
CALL SCREEN 100 STARTING AT 1 1..
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module pbo OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container
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 g_grid
EXPORTING
i_parent = g_custom_container
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.
gs_layout-edit = 'X'.
SELECT * FROM sflight INTO TABLE gt_outtab UP TO 10 ROWS.
*§1.Set status of all cells to editable using the layout structure.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab
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.
*§2.Use SET_READY_FOR_INPUT to allow editing initially.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDIF.
ENDMODULE. " pbo OUTPUT
*&---------------------------------------------------------------------*
*& Module pai INPUT
*&---------------------------------------------------------------------*
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE. " pai INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
LEAVE PROGRAM.
ENDFORM. " exit_program
*&---------------------------------------------------------------------*
*& Form switch_edit_mode
*&---------------------------------------------------------------------*
FORM switch_edit_mode .
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
ENDFORM. " switch_edit_mode
‎2007 Apr 24 1:27 PM
to make the fields editable , in the fieldcatalog
wa_fieldcatalog-edit = 'X'.
also chk BCALV_EDIT_05 program
Message was edited by:
Chandrasekhar Jagarlamudi
‎2007 Apr 24 1:38 PM
Hi,
thank you - but one problem persists...it gives me an error saying that data-object ls_fieldcat doesnt have a component "edit". I am on 4.6 and have ls_fieldcat defined as ls_fieldcat TYPE slis_fieldcat_alv,
‎2007 Apr 24 1:29 PM
Hi,
Yes u can do that,
in the field catalog for check box
fieldcatalog-field = vbeln.
fieldcatalog-edit = 'X'.
for check box take a field and set its property as
fieldcatalog-box = 'X'.
Hope it helps.
Regards,
Sonika