Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Editable cells or Fields in ALV tree

Former Member
0 Likes
3,117

Hi Friends,

Does any body know how to make some fields or cells Editable in ALV Tree display,

I am using CL_GUI_ALV_TREE class and i have tried by setting Edit option in Layout in the method ADD_NODE(While adding a new node, I want some fields to be editable).

If anybody knows about this, please give your valuable answers.

Thanks:

RK

Hi Friends,

Does any body know how to make some fields or cells Editable in ALV Tree display,

I am using CL_GUI_ALV_TREE class and i have tried by setting Edit option in Layout in the method ADD_NODE(While adding a new node, I want some fields to be editable).

If anybody knows about this, please give your valuable answers.

Thanks:

RK

5 REPLIES 5
Read only

Former Member
0 Likes
1,425

check this:

&----


*& 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

Read only

0 Likes
1,425

Hi Ytamar Fondeur & Naveed...

I am talking about ALV Tree not about ALV GRID

Thanks:

RK

Read only

Former Member
Read only

Former Member
0 Likes
1,425

Hiiii

REPORT zalv_fcat.

  • Output table T006 structure declaration

TYPES : BEGIN OF ty_t006.

INCLUDE STRUCTURE t006.

TYPES : END OF ty_t006.

*Internal table and wa declaration for T006

DATA : it_t006 TYPE STANDARD TABLE OF ty_t006,

wa_t006 TYPE ty_t006.

*declarations for ALV

DATA: ok_code TYPE sy-ucomm,

  • fieldcatalog for T006

it_fielcat TYPE lvc_t_fcat,

  • fieldcatalog for fieldcatalog itself:

it_fielcatalogue TYPE lvc_t_fcat,

it_layout TYPE lvc_s_layo.

*declaration for toolbar function

DATA: it_excl_func TYPE ui_functions.

  • Controls to display it_t006 and corresponding fieldcatalog

DATA: cont_dock TYPE REF TO cl_gui_docking_container,

cont_alvgd TYPE REF TO cl_gui_alv_grid.

*controls to display the fieldcatalog as editable alv grid and container

DATA: cont_cust TYPE REF TO cl_gui_custom_container,

cont_editalvgd TYPE REF TO cl_gui_alv_grid.

*intialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

**************************************************************

  • LOCAL CLASS Definition for data changed in fieldcatalog ALV

**************************************************************

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

ENDCLASS. "lcl_event_receiver DEFINITION

**************************************************************

  • LOCAL CLASS implementation for data changed in fieldcatalog ALV

**************************************************************

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

*data declaration for event receiver

DATA: event_receiver TYPE REF TO lcl_event_receiver.

*end of selection event

END-OF-SELECTION.

*setting the screen for alv output for table display and

*changed fieldcatalalogue display

SET SCREEN 600.

*On this statement double click it takes you to the screen painter SE51.

  • Enter the attributes

*Create a Custom container and name it CCONT and OK code as OK_CODE.

*Save check and Activate the screen painter.

*Now a normal screen with number 600 is created which holds the ALV grid.

  • PBO of the actual screen , Here we can give a title and customized menus

*Go to SE41 and create status 'STATUS600' and create THE function code 'SUBMIT'

*and 'EXIT' with icons and icon texts

*Also create a TitleBar 'TITLE600' and give the relevant title.

&----


*& Module STATUS_0600 OUTPUT

&----


MODULE status_0600 OUTPUT.

SET PF-STATUS 'STATUS600'.

SET TITLEBAR 'TITLE600'.

  • CREATE ALV GRID CONTROL IF DOES NOT EXISTS INITIALLY

IF cont_dock IS INITIAL.

PERFORM create_alv.

ENDIF.

ENDMODULE. " STATUS_0600 OUTPUT

  • PAI module of the screen created. In case we use an interactive ALV or

*for additional functionalities we can create OK codes and based on the

*user command we can do the coding as shown below

&----


*& Module USER_COMMAND_0600 INPUT

&----


MODULE user_command_0600 INPUT.

CASE ok_code.

WHEN 'SUBMIT'.

*TO GET THE CURRENT FIELDCATALOGUE FROM THE FRONTEND

CALL METHOD cont_alvgd->set_frontend_fieldcatalog

EXPORTING

it_fieldcatalog = it_fielcat.

*refresh the alv

CALL METHOD cont_alvgd->refresh_table_display.

*to Send Buffered Automation Queue to Frontend

CALL METHOD cl_gui_cfw=>flush.

*Exit button clicked to leave the program

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0600 INPUT

&----


*& Form CREATE_ALV

&----


FORM create_alv.

*create a docking container and dock the control at the botton

CREATE OBJECT cont_dock

EXPORTING

dynnr = '600'

extension = 100

side = cl_gui_docking_container=>dock_at_bottom.

*create the alv grid for display the table

CREATE OBJECT cont_alvgd

EXPORTING

i_parent = cont_dock.

*create custome container for alv

CREATE OBJECT cont_cust

EXPORTING

container_name = 'CCONT'.

*create alv editable grid

CREATE OBJECT cont_editalvgd

EXPORTING

i_parent = cont_cust.

  • register events for the editable alv

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_data_changed FOR cont_editalvgd.

CALL METHOD cont_editalvgd->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

*building the fieldcatalogue for the initial display

PERFORM build_fieldcat CHANGING it_fielcat it_fielcatalogue.

*building the fieldcatalogue after the user has changed it

PERFORM change_fieldcat CHANGING it_fielcatalogue.

*fetch data from the table

PERFORM fetch_data.

  • Get excluding functions for the alv editable tool bar

APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_loc_cut TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_sort TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_sort_asc TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_sort_dsc TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_subtot TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_sum TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_graph TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_info TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_print TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_filter TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_views TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_mb_export TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_mb_paste TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_find TO it_excl_func.

APPEND cl_gui_alv_grid=>mc_fc_loc_copy TO it_excl_func.

*Alv display for the T006 table at the bottom

CALL METHOD cont_alvgd->set_table_for_first_display

CHANGING

it_outtab = it_t006[]

it_fieldcatalog = it_fielcat[].

  • optimize column width of grid displaying fieldcatalog

it_layout-cwidth_opt = 'X'.

  • Get fieldcatalog of table T006 - alv might have

  • modified it after passing.

CALL METHOD cont_alvgd->get_frontend_fieldcatalog

IMPORTING

et_fieldcatalog = it_fielcat[].

*to Send Buffered Automation Queue to Frontend

CALL METHOD cl_gui_cfw=>flush.

  • Display fieldcatalog of table T006 in editable alv grid

CALL METHOD cont_editalvgd->set_table_for_first_display

EXPORTING

is_layout = it_layout

it_toolbar_excluding = it_excl_func

CHANGING

it_outtab = it_fielcat[]

it_fieldcatalog = it_fielcatalogue[].

ENDFORM. " CREATE_alv

&----


*& Form fetch_data

&----


FORM fetch_data.

  • select data of T006

SELECT * FROM t006 INTO TABLE it_t006 UP TO 50 ROWS.

ENDFORM. " fetch_data

&----


*& Form BUILD_FIELDCAT

&----


FORM build_fieldcat CHANGING it_fldcat TYPE lvc_t_fcat

it_fcat TYPE lvc_t_fcat.

  • Fieldcatalog for table T006: it_fldcat

  • to generate the fields automatically

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'T006'

CHANGING

ct_fieldcat = it_fldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*----


  • Fieldcatalog for table LVC_T_FCAT:it_fcat

*----


  • Generate fieldcatalog of fieldcatalog structure.

  • This fieldcatalog is used to display fieldcatalog 'it_fldcat'

  • on the top of the screen.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'LVC_S_FCAT'

CHANGING

ct_fieldcat = it_fcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

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. " BUILD_FIELDCAT

&----


*& Form CHANGE_FIELDCAT

&----


*after the user has modified the fieldcatalogue we build another fieldcat

*for the modified alv display

FORM change_fieldcat CHANGING it_fcat TYPE lvc_t_fcat.

DATA ls_fcat TYPE lvc_s_fcat.

LOOP AT it_fcat INTO ls_fcat.

ls_fcat-coltext = ls_fcat-fieldname.

ls_fcat-edit = 'X'.

IF ls_fcat-fieldname = 'COL_POS' OR ls_fcat-fieldname = 'FIELDNAME'.

ls_fcat-key = 'X'.

ENDIF.

MODIFY it_fcat FROM ls_fcat.

ENDLOOP.

ENDFORM. " CHANGE_FIELDCAT

regards

chandu reddy

Read only

Former Member
0 Likes
1,425

It is not possible to make cells editable in ALV tree

Thanks:

Rk