ALV Editable
ALV Editable
Log On
Join Us
Getting Started
Newsletters
Store
Search for:
Products
About SCN
Downloads
Industries
Partnership
Developer Center
Lines of Business
University Alliances
Innovation
Activity
Communications
Actions
BrowseMore
T Aswani Kalyan
21-Jun-2005 12:03
Hello,
Can anybody please tell me how to make a cell "EDITABLE" in alv grid control. When i use
the EDIT option of field catalog, complete column gets editable. But I want only one column
to get editable.
Regards
Kalyan
15325 Views
Topics: abap
When u want to do edit only for particular column and not for the entire grid then you
need to perform fieldcat in that particular column only.
for example
if ls_fcat-fieldname EQ 'Curr'.
ls_fcat-scrtext_s = 'CURRENCY'.
ls_fcat-scrtext_m = 'CURRENCY'.
ls_fcat-scrtext_l = 'CURRENCY'.
ls_fcat-reptext = 'CURRENCY'.
Ls_fcat-seltext = 'CURRENCY'.
<b>ls_fcat-edit = 'X'.</b>
modify pt_fieldcat from ls_fcat.
endif.
endloop.
in this way you can give editable option to that particular column only.
Regards,
venu.
o
Like (0)
Thanks for you answer. But as I specified earlier, I want to make a single cell
editable not the complete column editable.
Regards
Kalyan
Alert Moderator
Like (0)
1. In the fieldcatalogue - don't set the edit property for the field.
endloop.
endform.
Alert Moderator
Like (0)
PROGRAM BCALV_EDIT_02.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
Purpose:
~~~~~~~~
of possible states).
Remark: You may set the states for chosen columns using field
*----
~~~~~~~~~~~~~~~~~~~~~~~~~
Switch to the state editable activated. You may then change the
*----
~~~~~~~~~~~~~~~
1.Extend your output table for a field, e.g., CELLTAB, that holds
2.After selecting data, set edit status for each row in a loop
according to field SEATSMAX.
2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to
set a cell
to status "editable".
2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to
set a cell
to status "non-editable".
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&
*1.Extend your output table for a field, e.g., CELLTAB, that holds
*----
*----
MAIN
*
CALL SCREEN 100.
*----
*----
*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid1
EXPORTING i_parent = g_custom_container.
PERFORM select_data_and_init_style.
gs_layout-stylefname = 'CELLTAB'.
= gs_layout
CHANGING it_outtab
= gt_outtab[].
ENDIF.
ENDMODULE.
*----
*----
*
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.
*----
*
FORM EXIT_PROGRAM
*----
*
FORM exit_program.
LEAVE PROGRAM.
ENDFORM.
*&----
*
*&
Form SELECT_DATA_AND_INIT_STYLE
*&----
*----
text
--> p1
text
<-- p2
text
*----
*
FORM select_data_and_init_style.
DATA: lt_sflight TYPE TABLE OF sflight WITH HEADER LINE,
lt_celltab TYPE lvc_t_styl,
l_index TYPE i.
LOOP AT lt_sflight.
MOVE-CORRESPONDING lt_sflight TO gt_outtab.
APPEND gt_outtab.
ENDLOOP.
*2.After selecting data, set edit status for each row in a loop
LOOP AT gt_outtab.
l_index = sy-tabix.
refresh lt_celltab.
if gt_outtab-seatsmax ge 300.
" SELECT_DATA_AND_INIT_STYLE
*&----
*
*&
Form FILL_CELLTAB
*&----
text
*----
*----
<--P_PT_CELLTAB text
*
FORM fill_celltab using value(p_mode)
CHANGING pt_celltab TYPE lvc_t_styl.
DATA: ls_celltab TYPE lvc_s_styl,
l_mode type raw4.
IF p_mode EQ 'RW'.
*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'
*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.
ls_celltab-fieldname = 'CARRID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'CONNID'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'FLDATE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'PRICE'.
ls_celltab-style = l_mode.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'CURRENCY'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'PLANETYPE'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'SEATSMAX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'SEATSOCC'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ls_celltab-fieldname = 'PAYMENTSUM'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE pt_celltab.
ENDFORM.
*&----
" FILL_CELLTAB
*
*&
Form SWITCH_EDIT_MODE
*&----
text
*----
--> p1
text
<-- p2
text
*----
*
FORM switch_edit_mode.
IF grid1->is_ready_for_input( ) eq 0.
ELSE.
ENDIF.
ENDFORM.
" SWITCH_EDIT_MODE
Regards
*--Serdar <a
href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/i
rj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk
%2bsag%2bjiw%3d">[ BC ]</a>
Alert Moderator
Like (0)
On the example show by the others here before, it is just only apply 1 style for a cell,
like below:
<b>ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.</b>
But im having a requirement to have more than 1 style need to apply to a cell. For
my case, i need to apply the hotspot for the same cell in addition. where i put in the
code like this:
ls_celltab-style<b>2</b> = cl_gui_alv_grid=>mc_style_hotspot.
But system will <b>NOT</b> have any effects on the value assigned in ls_celltabstyle<b>2</b>. Meaning system will only recognize value from ls_celltab-style but
<b>NOT</b> for ls_celltab-style2/style3/style4
Thanks in advance.
Alert Moderator
Like (0)
I have a program that was done a long time ago for another person, and I don't
wanna to change all the program to use control... The author put the all the collum
editable (using fieldcat) and if the value can be change, he show a message. But now
the user want to change this, and only enable to edit what can be edited.
Alert Moderator
Like (0)
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,
line_color(4) TYPE c,
END OF t_ekko.
TYPE slis_layout_alv,
gd_repid
LIKE sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog ."CHANGING fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM build_fieldcatalog ."CHANGING fieldcatalog TYPE slis_t_fieldcat_alv.
= sy-repid
I_INTERNAL_TABNAME
i_structure_name
=
= 'ZALV_VIJAY'
I_CLIENT_NEVER_DISPLAY
I_INCLNAME
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
= 'X'
=
=
=
CHANGING
ct_fieldcat
= t_fieldcatalog
= 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text
= 'Totals'(201).
'LINE_COLOR'.
ENDFORM.
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
is_layout
= gd_repid
= gd_layout
it_fieldcat
= t_fieldcatalog
i_save
= 'X'
TABLES
t_outtab
= it_ekko
EXCEPTIONS
program_error
OTHERS
=1
= 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.
FORM data_retrieval.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekko.
LOOP AT it_ekko INTO wa_ekko.
ld_color = ld_color + 1.
IF ld_color = 8.
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
MODIFY it_ekko FROM wa_ekko.
ENDLOOP.
ENDFORM.
Alert Moderator
Like (0)
Alert Moderator
Like (0)
I also faced the same Pbm.by using the following code we can edit single row.
*&---------------------------------------------------------------------*
*&
Form set_specific_field_attributes
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM set_specific_field_attributes.
LOOP AT it_makt INTO wa_makt.
IF wa_makt-indcat NE 'H'.(By using the condition iam editing single row)
" DISPLAY_ALV
*&---------------------------------------------------------------------*
*&
Form FIELD_ATTRIBUTES
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_0952 text
-->P_0953 text
*----------------------------------------------------------------------*
FORM field_attributes USING
p_field
p_name.
DATA ls_stylerow TYPE lvc_s_styl.
DATA lt_styletab TYPE lvc_t_styl.
ls_stylerow-fieldname = p_field.
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_stylerow INTO TABLE wa_makt-field_style.
CLEAR: ls_stylerow.
* *******
ENDFORM.
o
Alert Moderator
Like (0)
i1 = i1 + 1.
PERFORM fieldcat USING i1 'GT_SMY_ALV' 'DEVELOPED_BY' text-006 '25' '' '' '' '' ''
'' '' ''.
i1 = i1 + 1.
PERFORM fieldcat USING i1 'GT_SMY_ALV' 'PROJECT' text-008 '30' '' '' 'X' 'X' '' '' ''
''.
i1 = i1 + 1.
PERFORM fieldcat USING i1 'GT_SMY_ALV' 'PROJECT_MANAGER' text-009 '30' '' '' ''
'' '' '' '' ''.
gs_fieldcat-col_pos = col_pos.
gs_fieldcat-fieldname = fieldname.
gs_fieldcat-tabname = tabname.
gs_fieldcat-reptext_ddic = reptext.
gs_fieldcat-outputlen = len.
gs_fieldcat-no_out = no_out.
gs_fieldcat-do_sum = sum.
gs_fieldcat-input = nozero.
gs_fieldcat-edit = edit.
gs_fieldcat-checkbox = no_chk.
gs_fieldcat-datatype = dtype.
gs_fieldcat-ref_tabname = tdropdown.
gs_fieldcat-ref_fieldname = tfieldname.
ENDFORM.