Hi,
Yes it is possible in ALV Grid by applying column styles.
I'd don't know yet if it would be possible in SALV model (without messing directly with the underlying ALV grid object) by "abusing" cell color settings feature to add on the alignment bits to the color value, but I doubt it will work.
To illustrate principle, copy program BCALV_EDIT_09 into Z namespace and replace subroutine FILL_CELLTAB with the following code:
FORM fill_celltab using value(p_mode) l_index
CHANGING pt_celltab TYPE lvc_t_styl.
include<cl_alv_control> .
* ALV_STYLE_ALIGN_LEFT_TOP(4) TYPE X VALUE '00000800',
* ALV_STYLE_ALIGN_CENTER_TOP(4) TYPE X VALUE '00001000',
* ALV_STYLE_ALIGN_RIGHT_TOP(4) TYPE X VALUE '00001800',
* ALV_STYLE_ALIGN_LEFT_CENTER(4) TYPE X VALUE '00002000',
* ALV_STYLE_ALIGN_CENTER_CENTER(4) TYPE X VALUE '00002800',
* ALV_STYLE_ALIGN_RIGHT_CENTER(4) TYPE X VALUE '00003000',
* ALV_STYLE_ALIGN_LEFT_BOTTOM(4) TYPE X VALUE '00003800',
* ALV_STYLE_ALIGN_CENTER_BOTTOM(4) TYPE X VALUE '00004000',
* ALV_STYLE_ALIGN_RIGHT_BOTTOM(4) TYPE X VALUE '00004800',
DATA: ls_celltab TYPE lvc_s_styl,
l_index1 type i,
l_mode type raw4, l_mod1 type raw4, l_mod2 type raw4 , l_rest type i,
l_rowstyle(1) type c.
* This forms sets the style of column 'PRICE' editable
* according to 'p_mode' and the rest to read only either way.
IF p_mode EQ'RW'. ">300
*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell
* to status "editable".
l_mode = cl_gui_alv_grid=>mc_style_enabled.
ELSE. "p_mode eq 'RO' "<300
*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell
* to status "non-editable".
l_mode = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
* is row style selected?
l_rowstyle = g_rstyle.
l_index1 = l_index.
* define rowstyle for single rows:
if l_rowstyle isnotinitial.
clear ls_celltab.
if l_index1 <='100'.
l_rest = l_index mod2 .
if l_rest =0 .
l_mod1 = ALV_STYLE_ALIGN_LEFT_CENTER .
l_mod2 = ALV_STYLE_ALIGN_right_CENTER .
else.
l_mod2 = ALV_STYLE_ALIGN_LEFT_CENTER .
l_mod1 = ALV_STYLE_ALIGN_right_CENTER .
endif .
ls_celltab-fieldname =' '.
ls_celltab-style = cl_gui_alv_grid=>mc_style_no_delete_row. " row not deleted
INSERT ls_celltab INTOTABLE pt_celltab.
* define editablility of single cells:
ls_celltab-fieldname ='CARRID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PRICE'.
ls_celltab-style = l_mode + l_mod1. "depending on value seatmax
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled + l_mod1 .
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSMAX'.
ls_celltab-style = l_mode + l_mod2.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname ='SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
else.
* rows can be deleted
if l_index1 >100and l_index1 <=200.
* do nothing for row style and cell style
* set cell style:
ls_celltab-fieldname ='CARRID'.
ls_celltab- style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PRICE'.
ls_celltab-style = l_mode. "depending on value seatmax
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSMAX'.
ls_celltab-style = l_mode.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTOTABLE pt_celltab.
else.
if l_index1 >200and l_index1 <=250.
* everything is editable: > 300, rows can not be deleted
ls_celltab-fieldname =' '.
ls_celltab-style = cl_gui_alv_grid=>mc_style_no_delete_row. " row not deleted
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CARRID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PRICE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSMAX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
else. "BT 250 and 600 rows can be deleted.
ls_celltab-fieldname ='CARRID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PRICE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSMAX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
endif.
endif.
endif.
else.
*without any row style: rows can be deleted
ls_celltab-fieldname ='CARRID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PRICE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled. "depending on value seatmax
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSMAX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
ls_celltab-fieldname ='PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_celltab INTOTABLE pt_celltab.
endif.
ENDFORM. " FILL_CELLTAB
Run the program and check 'styles for columns set' on selection screen.
The constants for alignment style values are defined in include <cl_alv_control>.
cheers
Jānis
