‎2008 Jan 13 7:52 PM
Hello All,
I need the solutions for the following.
In the ALV output I am displaying a checkbox in edit mode, but I want this checkbox in edit mode for some records and disable mode for some other records depending on a condition.
Ex.
ITAB. Output fields.
Checkbox F1 F2
if the value of the field F1 = 'V' that checkbox should be in edit mode that means we can check or uncheck.
if the value of the field F1 = 'S' that checkbox should be in disable mode.
points assured.
Regards.
Krishna.
‎2008 Jan 13 9:43 PM
hi,
to make editable and not editable some cells you have to do the following modification to your code:
1 - extend the structure of your table with one more filed
>data: begin of outtab occurs 0,
> Checkbox type xfeld
> F1(1),
> ...
> style TYPE lvc_t_styl,
> end of outtab.
2 - set value 'STYLE' into the field stylefname of strucure typed lvc_s_layo.
>data: ls_layo type lvc_s_layo.
>lvc_s_layo-stylefname = 'STYLE'.
3 - in the fieldcatlog set editable the Checkbox
4 - loop to your internal table outtab and set the style of evry single cell
>data: ls_style type lvc_s_styl.
>loop at outtab.
>if outtab-F1 = 'S'.
>ls_style-fieldname = 'CHECKBOX'.
>ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
>append ls_style to outtab-style.
>clear ls_style.
>else.
>clear outtab-style.
>endif.
>modify outtab.
>endloop.
5 - disply ALV.
for more example see [https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-changing%2bcell%2bcharacteristics%2bin%2balv%2b(OOPS)]
bye
Marco
Edited by: nicolai marco on Jan 13, 2008 10:44 PM
‎2008 Jan 13 9:43 PM
hi,
to make editable and not editable some cells you have to do the following modification to your code:
1 - extend the structure of your table with one more filed
>data: begin of outtab occurs 0,
> Checkbox type xfeld
> F1(1),
> ...
> style TYPE lvc_t_styl,
> end of outtab.
2 - set value 'STYLE' into the field stylefname of strucure typed lvc_s_layo.
>data: ls_layo type lvc_s_layo.
>lvc_s_layo-stylefname = 'STYLE'.
3 - in the fieldcatlog set editable the Checkbox
4 - loop to your internal table outtab and set the style of evry single cell
>data: ls_style type lvc_s_styl.
>loop at outtab.
>if outtab-F1 = 'S'.
>ls_style-fieldname = 'CHECKBOX'.
>ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
>append ls_style to outtab-style.
>clear ls_style.
>else.
>clear outtab-style.
>endif.
>modify outtab.
>endloop.
5 - disply ALV.
for more example see [https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-changing%2bcell%2bcharacteristics%2bin%2balv%2b(OOPS)]
bye
Marco
Edited by: nicolai marco on Jan 13, 2008 10:44 PM
‎2008 Jan 14 9:19 AM
Hello Marco,
Thanks for your answer.
I did the all changes in my code as suggested by you still it is not working properly, can you see the below code and tell me still I am missing anything.
type-pools : slis.
DATA: l_f_repid LIKE sy-repid.
DATA: l_t_fieldcat TYPE slis_t_fieldcat_alv,
l_r_fieldcat LIKE LINE OF l_t_fieldcat.
class cl_gui_alv_grid definition load.
*output tab
data : begin of itab occurs 0,
cb,
f1,
f2(10),
style TYPE lvc_t_styl,
end of itab.
data: ls_style type lvc_s_styl.
data: ls_layo type lvc_s_layo.
ls_layo-stylefname = 'STYLE'.
itab-f1 = 'S'.
itab-f2 = 'Test'.
append itab.
clear itab.
itab-f1 = 'V'.
itab-f2 = 'Test1'.
append itab.
clear itab.
itab-f1 = 'S'.
itab-f2 = 'Test2'.
append itab.
clear itab.
l_r_fieldcat-col_pos = 1.
l_r_fieldcat-tabname = 'ITAB'.
l_r_fieldcat-fieldname = 'CB'.
l_r_fieldcat-checkbox = 'X'.
l_r_fieldcat-edit = 'X'.
append l_r_fieldcat to l_t_fieldcat .
clear l_r_fieldcat.
l_r_fieldcat-col_pos = 2.
l_r_fieldcat-tabname = 'ITAB'.
l_r_fieldcat-fieldname = 'F1'.
append l_r_fieldcat to l_t_fieldcat .
clear l_r_fieldcat.
l_r_fieldcat-col_pos = 3.
l_r_fieldcat-tabname = 'ITAB'.
l_r_fieldcat-fieldname = 'F2'.
append l_r_fieldcat to l_t_fieldcat .
clear l_r_fieldcat.
loop at itab.
if itab-f1 = 'S'.
ls_style-fieldname = 'CB'.
ls_style-style = cl_gui_alv_grid=>mc_style_button .
ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
append ls_style to itab-style.
clear ls_style.
else.
clear itab-style.
endif.
modify itab.
endloop.
l_f_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = l_f_repid
IT_FIELDCAT = l_t_fieldcat
TABLES
t_outtab = itab .
Regards.
Krishna.
‎2008 Jan 14 10:15 AM
hi Krishna,
I have corrected the code that you have posted and now it works
in bold my correction.
>DATA: l_f_repid LIKE sy-repid.
>DATA: l_t_fieldcat TYPE lvc_t_fcat,
> l_r_fieldcat TYPE lvc_s_fcat.
>
>CLASS cl_gui_alv_grid DEFINITION LOAD.
>DATA : BEGIN OF itab OCCURS 0,
> cb,
> f1,
> f2(10),
> style TYPE lvc_t_styl,
> END OF itab.
>DATA: ls_style TYPE lvc_s_styl.
>DATA: ls_layo TYPE lvc_s_layo.
>ls_layo-stylefname = 'STYLE'.
>
>itab-f1 = 'S'.
>itab-f2 = 'Test'.
>APPEND itab.
>CLEAR itab.
>
>itab-f1 = 'V'.
>itab-f2 = 'Test1'.
>APPEND itab.
>CLEAR itab.
>
>itab-f1 = 'S'.
>itab-f2 = 'Test2'.
>APPEND itab.
>CLEAR itab.
>
>l_r_fieldcat-col_pos = 1.
>l_r_fieldcat-tabname = 'ITAB'.
>l_r_fieldcat-fieldname = 'CB'.
>l_r_fieldcat-checkbox = 'X'.
>l_r_fieldcat-edit = 'X'.
>APPEND l_r_fieldcat TO l_t_fieldcat .
>CLEAR l_r_fieldcat.
>
>l_r_fieldcat-col_pos = 2.
>l_r_fieldcat-tabname = 'ITAB'.
>l_r_fieldcat-fieldname = 'F1'.
>APPEND l_r_fieldcat TO l_t_fieldcat .
>CLEAR l_r_fieldcat.
>
>l_r_fieldcat-col_pos = 3.
>l_r_fieldcat-tabname = 'ITAB'.
>l_r_fieldcat-fieldname = 'F2'.
>APPEND l_r_fieldcat TO l_t_fieldcat .
>CLEAR l_r_fieldcat.
>
>
>LOOP AT itab.
> IF itab-f1 = 'S'.
> ls_style-fieldname = 'CB'.
> ls_style-style = cl_gui_alv_grid=>mc_style_button .
> ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
> APPEND ls_style TO itab-style.
> CLEAR ls_style.
> ELSE.
> CLEAR itab-style.
> ENDIF.
> MODIFY itab.
>ENDLOOP.
>
>l_f_repid = sy-repid.
>CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
> EXPORTING
> i_callback_program = l_f_repid
> is_layout_lvc = ls_layo
> it_fieldcat_lvc = l_t_fieldcat
> TABLES
> t_outtab = itab.
you have forgotten to pass the structure layout to the function REUSE_ALV_GRID_DISPLAY.
bye
Marco
‎2008 Jan 14 9:52 AM
Hi,
check the program bcal_grid_edit , all the functionalites r present in that program.
Plzz reward points if it helps.