2008 Jan 15 5:10 AM
Hello everyone,
Is there a way for an ALV grid/OOP ALV to set certain fields as editable?
I have tried setting specific columns as editable through field catalog setup, but I don't need all records of that column to be editable. I just need specific records to be editable. Is this possible with ALV or I have no other choice but to use Table Control?
Please help.
Sincerely,
Ice
Hello everyone,
Is there a way for an ALV grid/OOP ALV to set certain fields as editable?
I have tried setting specific columns as editable through field catalog setup, but I don't need all records of that column to be editable. I just need specific records to be editable. Is this possible with ALV or I have no other choice but to use Table Control?
Please help.
Sincerely,
Ice
2008 Jan 15 5:32 AM
Hi Ice,
I don't know if this can be done using layout...you can do it logically.. Taking copy of internal table in PBO and comparing those fields in PAI, If undesired fields are edited, give message to user... (Better option is of course table control)..
Regards,
Mohaiyuddin
2008 Jan 15 6:48 AM
Hello Ice
The required steps are documented in sample report BCALV_EDIT_02.
For more details please refer to the excellent tuorial: [An Easy Reference For ALV Grid Control|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907]
Regards,
Uwe
2008 Jan 16 8:55 AM
Hi Ice,
this code will work 4 u.
&----
*& Report ZDEMO_ALVGRID_EDIT *
*& *
&----
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic ALV grid, Enhanced to display specific fields as *
*& editable depending on field value *
&----
REPORT ZDEMO_ALVGRID_EDIT .
TABLES: ekko.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
field_style TYPE lvc_t_styl, "FOR DISABLE
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
wa_fieldcat TYPE lvc_s_fcat,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE lvc_s_layo, "slis_layout_alv,
gd_repid LIKE sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM set_specific_field_attributes.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
FORM build_fieldcatalog.
wa_fieldcat-fieldname = 'EBELN'.
wa_fieldcat-scrtext_m = 'Purchase Order'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_m = 'Material Number'.
wa_fieldcat-col_pos = 4.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
wa_fieldcat-edit = 'X'. "sets whole column to be editable
wa_fieldcat-col_pos = 7.
wa_fieldcat-outputlen = 15.
wa_fieldcat-datatype = 'CURR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos = 8.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
FORM build_layout.
Set layout field for field attributes(i.e. input/output)
gd_layout-stylefname = 'FIELD_STYLE'.
gd_layout-zebra = 'X'.
ENDFORM. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
FORM display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gd_repid
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout
it_fieldcat_lvc = it_fieldcat
i_save = 'X'
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
ENDFORM. " DATA_RETRIEVAL
&----
*& Form set_specific_field_attributes
&----
populate FIELD_STYLE table with specific field attributes
----
form set_specific_field_attributes .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
Populate style variable (FIELD_STYLE) with style properties
*
The NETPR field/column has been set to editable in the fieldcatalog...
The following code sets it to be disabled(display only) if 'NETPR'
is gt than 10.
LOOP AT it_ekko INTO wa_ekko.
IF wa_ekko-netpr GT 10.
ls_stylerow-fieldname = 'NETPR' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
APPEND ls_stylerow TO wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ENDIF.
ENDLOOP.
endform. " set_specific_field_attributes
kindly reward if found helpful.
cheers,
Hema.
2008 Jan 16 11:30 AM
Hi,
while filling ur fieldcatalog
try this code.
FORM build_fcat USING tabname TYPE lvc_tname
fieldname TYPE lvc_fname
coltext TYPE lvc_txtcol
colpos TYPE lvc_colpos .
CLEAR fs_fcat.
fs_fcat-tabname = tabname.
fs_fcat-fieldname = fieldname.
fs_fcat-coltext = coltext.
fs_fcat-col_pos = colpos.
fs_fcat-edit = 'x'.
fs_fcat-lowercase = 'x'.
fs_fcat-dd_outlen = 60.
APPEND fs_fcat TO t_fcat.
plzz reward points if it helps.
Edited by: manjari kotta on Jan 16, 2008 2:31 PM
2008 Jan 16 11:50 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,
> field1(10), " editable field
> ...
> 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 Field1
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 "some condition" = false.(1)
>ls_style-fieldname = 'FIELD1'.
>ls_style-style = cl_gui_alv_grid=>mc_style_disabled. " Single cell become not editable
>append ls_style to outtab-style.
>clear ls_style.
>else.
>clear outtab-style.
>endif.
>modify outtab.
>endloop.
(1) Here set your conditions to determine if the field is editable or not editable
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