Top Banner
Hi, Guest Log On Join Us Getting Started Newsletters Store Search for: Products Services & Support !out S"N #ownloads $ndustries %raining & ducation Partnership #eveloper "enter Lines of 'usiness Universit( lliances vents & )e!inars $nnovation ctivit(
29

ALV Editable

Oct 04, 2015

Download

Documents

Abbu Sandeep

alv
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Hi, Guest Log On Join Us Getting Started Newsletters StoreTop of FormSearch for:Bottom of Form Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation Activity Communications Actions BrowseMoreMore discussions in ABAP DevelopmentWhere is this place located?11 Replies Latest reply: 08-Jul-2013 15:59 by Viswanathan s inShare Editting a cell in ALV Grid Control This question is Assumed Answered.

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.RegardsKalyan 15325Views Topics: abap Average User Rating(0 ratings) Re: Editting a cell in ALV Grid Control

Guest 21-Jun-2005 12:14 (in response to T Aswani Kalyan) Hi kalyan,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 exampleform build_fieldcat changing pt_fieldcat type lvc_t_fcat. data ls_fcat type lvc_s_fcat. loop at pt_fieldcat into ls_fcat.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'.ls_fcat-edit = 'X'. modify pt_fieldcat from ls_fcat. endif.endloop.in this way you can give editable option to that particular column only.Regards,venu. Like (0) Re: Editting a cell in ALV Grid Control

T Aswani Kalyan 21-Jun-2005 12:21 (in response to Guest ) Hello Venu,Thanks for you answer. But as I specified earlier, I want to make a single cell editable not the complete column editable.RegardsKalyan Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

Sandeep Jha 21-Jun-2005 12:36 (in response to T Aswani Kalyan) This is taken from a reference doc which was here on SDN few months back.1. In the fieldcatalogue - don't set the edit property for the field.2. add a table to your list data table. data begin of gt_grid occurs 0. . . data cellstyles type lvc_t_styl. data end of gt_grid.3. Then now the logic .. form make_field_edit using pt_grid like gt_grid[]. data: ls_grid like line of pt_grid, ls_style type lvc_s_styl, lt_style type lvc_t_styl. loop at pt_grid into ls_grid. if ls_grid-curr = xyz. 'your condition for the row ls_style-fieldname = 'CURR'. ls_style-style = cl_gui_alv_grid=>mc_style_enabled. append ls_style to lt_style. endif. insert lines of lt_style into ls_grid-celltyles. modify pt_grid from ls_grid. endloop. endform. Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

Guest 29-Feb-2012 08:49 (in response to T Aswani Kalyan) hi kalyan,here is the right example for your requirement.PROGRAM BCALV_EDIT_02.*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Purpose: ~~~~~~~~ This report illustrates how to set chosen cells of an ALV Grid Control editable. (See BCALV_EDIT_01 for an overview of possible states). Remark: You may set the states for chosen columns using field EDIT of the fieldcatalog, see BCALV_EDIT_03.*-----

To check program behavior ~~~~~~~~~~~~~~~~~~~~~~~~~ Switch to the state editable activated. You may then change the price of flights where the capacity of a plane is greater or equal than 300 seats.*-----

Essential steps (search for '') ~~~~~~~~~~~~~~~ 1.Extend your output table for a field, e.g., CELLTAB, that holds information about the edit status of each cell for the corresponding row (the table type is SORTED!). 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". 2c.Copy your celltab to the celltab of the current row of gt_outtab. 3.Provide the fieldname of the celltab field by using field STYLEFNAME of the layout structure.*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DATA: ok_code LIKE sy-ucomm, save_ok like sy-ucomm, g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1', grid1 TYPE REF TO cl_gui_alv_grid, g_custom_container TYPE REF TO cl_gui_custom_container, gs_layout TYPE lvc_s_layo, g_max type i value 100.*1.Extend your output table for a field, e.g., CELLTAB, that holds information about the edit status of each cell for the corresponding row (the table type is SORTED!).DATA: BEGIN OF gt_outtab occurs 0. "with header line include structure sflight.DATA: celltab type LVC_T_STYL.DATA: END OF gt_outtab.*----

* MAIN **----

*CALL SCREEN 100.*----

* MODULE PBO OUTPUT **----

*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.*3.Provide the fieldname of the celltab field by using field STYLEFNAME of the layout structure. gs_layout-stylefname = 'CELLTAB'. set substate of editable cells to deactivated CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = 0. CALL METHOD grid1->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' is_layout = gs_layout CHANGING it_outtab = gt_outtab[]. ENDIF.ENDMODULE.*----

* MODULE PAI INPUT **----

*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 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 is_ready_for_input( ) eq 0. set edit enabled cells ready for input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = 1. ELSE. lock edit enabled cells against input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = 0. ENDIF.ENDFORM. " SWITCH_EDIT_MODEYou can make use of the tutorial "An Easy eference for ALV Grid Control".Regards*--Serdar [ BC ] Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

FS CHU 28-Jul-2006 04:21 (in response to T Aswani Kalyan) Hi Guys,On the example show by the others here before, it is just only apply 1 style for a cell, like below:ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.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-style2 = cl_gui_alv_grid=>mc_style_hotspot.But system will NOT have any effects on the value assigned in ls_celltab-style2. Meaning system will only recognize value from ls_celltab-style but NOT for ls_celltab-style2/style3/style4Pls comment if i missed out any steps... Thanks in advance. Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

Andr Fogagnoli 07-Dec-2007 16:38 (in response to T Aswani Kalyan) Can I use this in ALV Function (REUSE_ALV_GRID_DISPLAY)??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.thank you all.... Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

Vijayaraghavan Narayanan 05-Jul-2013 17:10 (in response to T Aswani Kalyan) Hi Priya,In this am doing coloring the filed and edit the field.without header line.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, "Used to store row color attributes END OF t_ekko.DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0, wa_ekko TYPE t_ekko.*ALV data declarationsDATA: fieldcatalog TYPE LINE OF slis_t_fieldcat_alv, t_fieldcatalog TYPE slis_t_fieldcat_alv, gd_tab_group TYPE slis_t_sp_group_alv, gd_layout 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*&---------------------------------------------------------------------** Build Fieldcatalog for ALV Report*----------------------------------------------------------------------*FORM build_fieldcatalog ."CHANGING fieldcatalog TYPE slis_t_fieldcat_alv.CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_program_name = sy-repid* I_INTERNAL_TABNAME = i_structure_name = 'ZALV_VIJAY'* I_CLIENT_NEVER_DISPLAY = 'X'* I_INCLNAME =* I_BYPASSING_BUFFER =* I_BUFFER_ACTIVE = CHANGING ct_fieldcat = t_fieldcatalogLOOP AT t_fieldcatalog INTO fieldcatalog WHERE fieldname = 'EBELN'. fieldcatalog-edit = 'X'. MODIFY t_fieldcatalog FROM fieldcatalog.ENDLOOP.ENDFORM. FORM build_layout. gd_layout-no_input = 'X'. gd_layout-colwidth_optimize = 'X'. gd_layout-totals_text = 'Totals'(201).* Set layout field for row attributes(i.e. color) gd_layout-info_fieldname = 'LINE_COLOR'.ENDFORM.

FORM display_alv_report. gd_repid = sy-repid. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = gd_repid is_layout = gd_layout it_fieldcat = t_fieldcatalog 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. FORM data_retrieval. DATA: ld_color(1) TYPE c. 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) Re: Editting a cell in ALV Grid Control

Clemens Li 05-Jul-2013 14:05 (in response to T Aswani Kalyan) ask google. Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

sivajyothi yellamelli 08-Jul-2013 13:40 (in response to T Aswani Kalyan) Hai priya,I also faced the same Pbm.by using the following code we can edit single row.

*&---------------------------------------------------------------------*

*& Form set_specific_field_attributes

*&---------------------------------------------------------------------*

* populate FIELD_STYLE table with s pecific 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)

PERFORM field_attributes USING 'INDCAT' 'X'.

PERFORM field_attributes USING 'ZMRDAT' 'X'.

PERFORM field_attributes USING 'MINO' 'X'.

PERFORM field_attributes USING 'ERDAT' 'X'.

PERFORM field_attributes USING 'EMPID' 'X'.

PERFORM field_attributes USING 'ERNAM' 'X'.

PERFORM field_attributes USING 'MATNR' 'X'.

PERFORM field_attributes USING 'KZECH' 'X'.

PERFORM field_attributes USING 'RAUBE' 'X'.

PERFORM field_attributes USING 'BEHVO' 'X'.

PERFORM field_attributes USING 'LGPBE' 'X'.

PERFORM field_attributes USING 'EKGRP' 'X'.

PERFORM field_attributes USING 'DISPR' 'X'.

PERFORM field_attributes USING 'PRCTR' 'X'.

PERFORM field_attributes USING 'STPRS' 'X'.

PERFORM field_attributes USING 'VERPR' 'X'.

PERFORM field_attributes USING 'VPRSV' 'X'.

PERFORM field_attributes USING 'PRFRQ' 'X'.

PERFORM field_attributes USING 'MVGR2' 'X'.

PERFORM field_attributes USING 'EXTWG' 'X'.

PERFORM field_attributes USING 'VTWEG' 'X'.

PERFORM field_attributes USING 'VKORG' 'X'.

PERFORM field_attributes USING 'SPART' 'X'.

PERFORM field_attributes USING 'BKLAS' 'X'.

PERFORM field_attributes USING 'MATKL' 'X'.

PERFORM field_attributes USING 'MSEHI' 'X'.

PERFORM field_attributes USING 'MTART' 'X'.

PERFORM field_attributes USING 'LGORT' 'X'.

PERFORM field_attributes USING 'WERKS' 'X'.

PERFORM field_attributes USING 'LONGTX' 'X'.

PERFORM field_attributes USING 'MAKTX' 'X'.

PERFORM field_attributes USING 'ZMCDAT' 'X'.

MODIFY it_makt FROM wa_makt.

ENDIF.

ENDLOOP.

ENDFORM. " 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. Alert Moderator Like (0) Re: Editting a cell in ALV Grid Control

Viswanathan s 08-Jul-2013 15:59 (in response to T Aswani Kalyan) Hi priya,when build a field catlog assign "X" to particular one column gs_fieldcat-input = 'X'.gs_fieldcat-edit = 'X'.my code assign three filed catlog in 2 filed is editable filed: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' '' '' '' '' '' '' '' ''.Am using Form and perform easy to assign a filedcatlogFORM fieldcat USING value(col_pos) value(tabname) value(fieldname) value(reptext) value(len) value(no_out) value(sum) value(nozero) value(edit) value(no_chk) value(dtype) value(tdropdown) value(tfieldname). 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. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.ENDFORM.