10-15-2008 9:33 AM
Hi,
I have a requirement where when the user clicks on an insert button a blank row should get appended to the ALV and only 1 of the cells in this row should be in editable mode. (Also the other rows of the ALV should be in display mode) I tried coding using the LVC_T_STYL properties but I come up with a screen of all non-editable rows. Please help suggest where I am going wrong. My coding is as below:
My internal table is defined as:
DATA: BEGIN OF it_mara OCCURS 1.
INCLUDE STRUCTURE mara.
DATA: cellstyles TYPE lvc_t_styl,
END OF it_mara.
My other important attribute definitions:
data: ls_cellstyles TYPE lvc_s_styl,
ls_layout TYPE lvc_s_layo,
In the PAI event for handling the INSERT button I have coded as:
WHEN 'INSERT'.
APPEND wa_mara TO it_mara. " Appending a blank row to ALV
DESCRIBE TABLE it_mara LINES lv_count.
read table it_mara index lv_count.
ls_cellstyles-fieldname = 'MATNR'.
ls_cellstyles-style = cl_gui_alv_grid=>mc_style_enabled. " Setting only MATNR field of the appended row as enabled
insert ls_cellstyles into table it_mara-cellstyles.
MODIFY it_mara INDEX lv_count transporting cellstyles.
o_grid->refresh_table_display( ).
Am also assigning cellstyles to the stylefname attribute of the layout & passing it to the SET_TABLE_FOR_FIRST_DISPLAY.
Regards,
Uday
10-15-2008 10:36 AM
I was wondering whether I might be going wrong somewhere so I tried setting the style property to cl_gui_alv_grid=>mc_style_button instead of the cl_gui_alv_grid=>mc_style_enabled. The program then comes up with the pushbutton being displayed in the lone specified cell. This confuses me as to why it doesnt work for making the cell editable.
Regards,
Uday
10-15-2008 10:58 AM
Hi People,
Sorry for my mistake. I had forgot to call the set_ready_for_input method. I just had to call it & the codes working fine now.
Regards,
Uday
o_grid->set_ready_for_input( exporting I_READY_FOR_INPUT = '1' ).
10-18-2008 8:14 AM
Hi Uday,
I was just going through your thread.
If you have the code working could you please post it if you don't mind
Regards,
Ranjith N
10-20-2008 6:26 AM
Hi Ranjith,
Please find the coding as below. You need to create a screen 100 and place a custom control with name O_CONT & a pushbutton with the function code as INSERT.
Regards,
Uday
*&---------------------------------------------------------------------*
*& Report Z187442_OOALV5
*&
*&---------------------------------------------------------------------*
REPORT z187442_ooalv5 NO STANDARD PAGE HEADING.
DATA: BEGIN OF it_mara OCCURS 1.
INCLUDE STRUCTURE mara.
DATA: cellstyles TYPE lvc_t_styl,
END OF it_mara.
DATA: it_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat,
wa_mara LIKE LINE OF it_mara,
o_cont TYPE REF TO cl_gui_custom_container,
o_grid TYPE REF TO cl_gui_alv_grid,
ls_cellstyles TYPE lvc_s_styl,
ls_layout TYPE lvc_s_layo,
okcode(20).
START-OF-SELECTION.
PERFORM build_fcat.
PERFORM build_layout.
PERFORM build_mara_data.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'Z187442_OOALV4'.
IF o_cont IS INITIAL.
CREATE OBJECT o_cont
EXPORTING
container_name = 'O_CONT'.
CREATE OBJECT o_grid
EXPORTING
i_parent = o_cont.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_layout = ls_layout
CHANGING
it_outtab = it_mara[]
it_fieldcatalog = it_fcat.
ELSE.
o_grid->refresh_table_display( ).
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
DATA lv_count TYPE i VALUE 0.
CASE okcode.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
WHEN 'INSERT'.
APPEND wa_mara TO it_mara.
DESCRIBE TABLE it_mara LINES lv_count.
READ TABLE it_mara INDEX lv_count.
ls_cellstyles-fieldname = 'MATNR'.
ls_cellstyles-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_cellstyles INTO TABLE it_mara-cellstyles.
MODIFY it_mara INDEX lv_count TRANSPORTING cellstyles.
o_grid->set_ready_for_input( exporting I_READY_FOR_INPUT = '1' ).
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FCAT
*&---------------------------------------------------------------------*
FORM build_fcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MARA'
CHANGING
ct_fieldcat = it_fcat.
ENDFORM. " BUILD_FCAT
*&---------------------------------------------------------------------*
*& Form BUILD_MARA_DATA
*&---------------------------------------------------------------------*
FORM build_mara_data .
SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE it_mara UP TO 10 ROWS.
ENDFORM. " BUILD_MARA_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
FORM build_layout .
ls_layout-stylefname = 'CELLSTYLES'.
ENDFORM. " BUILD_LAYOUT