Application Development 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: 

editable alv

Former Member
0 Kudos

Hi all,

how can i make a field editable in alv reports...

plz provide the example code for doing so...

Tnahks & Regrads

Ashu Singh.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Go through the link given below:

With Regards

Nikunj Shah

11 REPLIES 11

former_member705122
Active Contributor
0 Kudos

Hi,

Check this link you will find example for individual fields of an ALV grid editable.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_editable.htm

Regards

Adil

naveen_inuganti2
Active Contributor
0 Kudos

Hi

while creating field cat just do like below

>l_fieldcat-input = 'X'. "Making the field editable

>l_fieldcat-edit = 'X'.

this field will become editable

and

Check the following link:

http://sapdev.co.uk/reporting/alv/alvgrid_editable.htm

Thanks,

Naveen.I

Former Member
0 Kudos

Hi

Go through the link given below:

With Regards

Nikunj Shah

former_member598013
Active Contributor
0 Kudos

Hi,

Check out the below threads...

Former Member
0 Kudos

Former Member
0 Kudos

HERE IS SAMPLE CODE.

&----


*& Report ZALV_TEST *

*& *

&----


*& *

*& *

&----


REPORT zalv_test .

TYPE-POOLS:slis.

TABLES:ekko,

ekpo.

DATA : fieldcat_tab TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE,

grid1 type ref to cl_gui_alv_grid,

alv_layout TYPE slis_layout_alv.

DATA:BEGIN OF itab OCCURS 0,

ebeln LIKE ekko-ebeln,

ebeln1 like ekpo-ebeln,

ebelp LIKE ekpo-ebelp,

bsart LIKE ekko-bsart,

bukrs LIKE ekko-bukrs,

lgort LIKE ekpo-lgort,

END OF itab.

alv_layout-edit = 'X'.

alv_layout-zebra = 'X'. " this attr will not work for editable alv

*

PARAMETERS: v_bsart LIKE ekko-bsart.

START-OF-SELECTION.

select hebeln hbsart hbukrs iebeln iebelp ilgort

from ekko as h inner join ekpo as i

on hebeln = iebeln

into corresponding fields of table itab.

PERFORM build_fieldcat.

PERFORM alv_display.

&----


*& Form build_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_fieldcat.

fieldcat_tab-fieldname = 'BSART'.

fieldcat_tab-col_pos = '1'.

fieldcat_tab-seltext_l = 'DOC TY'.

APPEND fieldcat_tab.

fieldcat_tab-fieldname = 'EBELN'.

fieldcat_tab-col_pos = '5'.

fieldcat_tab-seltext_l = 'Po No.'.

APPEND fieldcat_tab.

fieldcat_tab-fieldname = 'EBELP'.

fieldcat_tab-col_pos = '16'.

fieldcat_tab-seltext_l = 'item no'.

APPEND fieldcat_tab.

fieldcat_tab-fieldname = 'BUKRS'.

fieldcat_tab-col_pos = '27'.

fieldcat_tab-seltext_l = 'COMP CD'.

APPEND fieldcat_tab.

fieldcat_tab-fieldname = 'LGORT'.

fieldcat_tab-col_pos = '22'.

fieldcat_tab-seltext_l = 'St loc'.

APPEND fieldcat_tab.

ENDFORM. " build_fieldcat

&----


*& Form ALV_DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM alv_display .

DATA:g_repid LIKE sy-repid.

g_repid = sy-repid. " sy-repid gives prgm name

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = g_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = alv_layout

it_fieldcat = fieldcat_tab[] "internal column attributes table

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = itab. "internal table containin data to b printed

  • 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. " ALV_DISPLAY

Former Member
0 Kudos

Hi

d_fieldcat_wa-fieldname = 'MATNR'.
d_fieldcat_wa-seltext_l = 'material number'.
d_fieldcat_wa-edit = 'X'.
d_fieldcat_wa-col_pos = 1.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.

data : gd_repid like sy-repid.
gd_repid = sy-repid.

call function module reuse_alv_grid_display.
exporting.
program name = gd_repid.
t_fieldcatalog = d_fieldcat.


importing.
t_outtab = itab.
exceptions.

With Regards

Brijesh

Former Member
0 Kudos

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 1

Applies To:

ABAP

Summary

This sample code can be used to edit ALV Grid contents without setting the grid in edit mode and some

additional features.

By: Subathra Radhakrishnan

Company: Wipro Technologies

Date: 27 Jan. 2005

Operations

􀁸 Set title of grid

􀁸 Save and reuse grid layout

􀁸 Customize ALV grid toolbar

􀁸 Set traffic lights field

􀁸 Color a line

􀁸 Get selected line and read its contents

􀁸 Edit contents

􀁸 Refresh grid

Code Sample

REPORT zwsalvgrid.

TYPE-POOLS: icon.

TABLES: zc6_employee.

CLASS lcl_event_receiver DEFINITION DEFERRED.

----


DATA: BEGIN OF i_employee OCCURS 0.

INCLUDE STRUCTURE zc6_employee.

DATA: traffic_light TYPE c.

DATA: line_color(4) TYPE c.

DATA: END OF i_employee.

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 2

----


DATA: ok_code LIKE sy-ucomm,

wa_employee LIKE LINE OF i_employee,

gs_layout TYPE lvc_s_layo.

DATA: grid1 TYPE REF TO cl_gui_alv_grid,

i_custom_container TYPE REF TO cl_gui_custom_container,

o_event_receiver TYPE REF TO lcl_event_receiver.

DATA: wa_change LIKE zc6_employee.

DATA:

  • Data for storing information about selected rows in the grid

gi_index_rows TYPE lvc_t_row, " Internal table

g_selected_row LIKE lvc_s_row. " Information about 1 row

----


  • C L A S S E S

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object e_interactive,

handle_user_command FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

ENDCLASS.

----


  • CLASS lcl_event_receiver IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 3

METHOD handle_toolbar. " Event handler method for event toolbar.

CONSTANTS: " Constants for button type.

c_button_normal TYPE i VALUE 0,

c_separator TYPE i VALUE 3.

DATA:

ls_toolbar TYPE stb_button.

MOVE c_separator TO ls_toolbar-butn_type.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Append a new button that to the toolbar. Use E_OBJECT of

  • event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.

  • This class has one attribute MT_TOOLBAR which is of table type

  • TTB_BUTTON. The structure is STB_BUTTON

CLEAR ls_toolbar.

MOVE 'CHANGE' TO ls_toolbar-function.

MOVE icon_change TO ls_toolbar-icon.

MOVE 'Change Details' TO ls_toolbar-quickinfo.

MOVE 'Change' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

METHOD handle_user_command." Handleown functions defined in thetoolbar

CASE e_ucomm.

WHEN 'CHANGE'.

PERFORM change_details.

ENDCASE.

ENDMETHOD.

ENDCLASS.

----


ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 4

  • S T A R T - O F - S E L E C T I O N.

----


START-OF-SELECTION.

SELECT-OPTIONS: s_empid FOR zc6_employee-s1empid.

SELECT * FROM zc6_employee INTO CORRESPONDING FIELDS OF TABLE

i_employee WHERE s1empid IN s_empid.

CALL SCREEN '100'.

&----


*& Module USER_COMMAND_0100 INPUT

&----


MODULE user_command_0100 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module STATUS_0100 OUTPUT

&----


MODULE status_0100 OUTPUT.

DATA:

v_layout TYPE disvariant.

IF i_custom_container IS INITIAL.

  • Create objects for container and ALV grid

CREATE OBJECT i_custom_container

EXPORTING container_name ='ALV_CONTAINER'.

CREATE OBJECT grid1

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 5

EXPORTING

i_parent = i_custom_container.

  • Create object for event_receiver class

  • and set handlers

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_user_command FOR grid1.

SET HANDLER o_event_receiver->handle_toolbar FOR grid1.

  • Layout (Variant) for ALV grid

v_layout-report = sy-repid. "Layout fo report

----


  • Setup the grid layout using a variable of structure lvc_s_layo

----


  • Set grid title

gs_layout-grid_title = 'ALV Grid Display-Employee Details'.

  • Selection mode B- Single row without buttons.

  • This is the default mode

gs_layout-sel_mode = 'B'.

gs_layout-excp_fname = 'TRAFFIC_LIGHT'.

gs_layout-info_fname = 'LINE_COLOR'.

LOOP AT i_employee INTO wa_employee.

wa_employee-traffic_light = '3'.

  • Value of color field:

  • C = Color, 6=Color 1=Intesified on, 0: Inverse display off

MODIFY i_employee FROM wa_employee.

ENDLOOP.

  • Grid setup for first display

CALL METHOD grid1->set_table_for_first_display

EXPORTING i_structure_name = 'ZC6_EMPLOYEE'

is_variant = v_layout

i_save = 'A'

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 6

is_layout = gs_layout

CHANGING it_outtab = i_employee[].

  • End of grid setup

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


MODULE user_command_0200 INPUT.

CASE ok_code.

WHEN'SAVE'.

PERFORM save_changes.

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

&----


*& Form change_details

&----


  • Reads the contents of the selected row in the grid, and transfers

  • the data to screen 200, where it can be changed and saved.

----


FORM change_details.

REFRESH gi_index_rows.

CLEAR g_selected_row.

DATA:

l_lines TYPE i.

DESCRIBE TABLE gi_index_rows LINES l_lines.

IF l_lines > 0.

CALL METHOD grid1->set_selected_rows

EXPORTING

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 7

it_index_rows = gi_index_rows.

ENDIF.

  • Read index of selected rows

CALL METHOD grid1->get_selected_rows

IMPORTING

et_index_rows = gi_index_rows.

  • Check if any row are selected at all. If not

  • table gi_index_rows will be empty

DESCRIBE TABLE gi_index_rows LINES l_lines.

IF l_lines = 0.

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

textline1 = 'You must choose a line'.

EXIT.

ENDIF.

  • Read indexes of selected rows. In this example only one

  • row can be selected as we are using gs_layout-sel_mode = 'B',

  • so it is only ncessary to read the first entry in

  • table gi_index_rows

LOOP AT gi_index_rows INTO g_selected_row.

IF sy-tabix = 1.

READ TABLE i_employee INDEX g_selected_row-index INTO wa_employee.

ENDIF.

ENDLOOP.

  • Transfer data from the selected row to screen 200 and show

  • screen 200

CLEAR wa_change.

MOVE wa_employee TO wa_change.

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 8

CALL SCREEN 200 STARTING AT 5 5.

ENDFORM.

&----


*& Form save_changes

----


FORM save_changes.

MOVE wa_change TO wa_employee.

  • Update database table

MODIFY zc6_employee FROM wa_change.

MOVE wa_change TO wa_employee.

  • Update grid table , traffic light field and color field.

wa_employee-traffic_light = '1'.

  • C = Color, 6=Color 1=Intesified on, 0=Inverse display off

wa_employee-line_color = 'C610'.

MODIFY i_employee INDEX g_selected_row-index FROM wa_employee.

  • Refresh grid

CALL METHOD grid1->refresh_table_display.

CALL METHOD cl_gui_cfw=>flush.

LEAVE TO SCREEN 0.

ENDFORM. " save_changes

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 9

Output:Grid Display

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 10

Change Screen

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 11

Grid display after the change is performed

Disclaimer & Liability Notice

This document may discuss sample coding, which does not include official interfaces and therefore is not

supported. Changes made based on this information are not supported and can be overwritten during an

upgrade.

SAP will not be held liable for any damages caused by using or misusing of the code and methods suggested

here, and anyone using these methods, is doing it under his/her own responsibility.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of

the technical article, including any liability resulting from incompatibility between the content of the technical

article and the materials and services offered by SAP. You agree that you will not hold SAP responsible or

liable with respect to the content of the Technical Article or seek to do so.

ABAP Code Sample to Edit ALV Grid

u00A9 2005 SAP AG 12

Copyright u00A9 2005 SAP AG, Inc. All Rights Reserved. SAP, mySAP, mySAP.com, xApps, xApp, and other SAP products and services

mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other

countries all over the world. All other product, service names, trademarks and registered trademarks mentioned are the trademarks of

their respective owners.

Former Member
0 Kudos

Hi,

Set the property u201CEDITu201D of the field catalog for the column to make it editable.

Regards,

Aparna Gaikwad

former_member188685
Active Contributor
0 Kudos

You need use the Function moduel in the user command.

GET_GLOBALS_FROM_SLVC_FULLSCR

follow the sample code.

REPORT ZTEST_ALV_CHECK MESSAGE-ID ZZ .
 
TYPE-POOLS: SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
L_LAYOUT TYPE SLIS_LAYOUT_ALV,
X_EVENTS TYPE SLIS_ALV_EVENT,
IT_EVENTS TYPE SLIS_T_EVENT.
 
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
CHK(1),
color(4),
END OF ITAB.
 
SELECT VBELN
POSNR
FROM VBAP
UP TO 20 ROWS
INTO TABLE ITAB.
 
X_FIELDCAT-FIELDNAME = 'CHK'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 1.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-CHECKBOX = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
 
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-SELTEXT_L = 'VBELN'.
X_FIELDCAT-HOTSPOT = 'X'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 2.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
 
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-SELTEXT_L = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
 
L_LAYOUT-info_fieldname = 'COLOR'.
*L_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = L_LAYOUT
I_CALLBACK_PF_STATUS_SET = 'STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = ITAB
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.
 
 
&---------------------------------------------------------------------
*& Form STATUS
&---------------------------------------------------------------------
 
 
text 
----------------------------------------------------------------------
 
-->P_EXTAB text 
----------------------------------------------------------------------
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
 
 
Pf status 
SET PF-STATUS 'STATUS'.
ENDFORM. " STATUS
 
&---------------------------------------------------------------------
*& Form USER_COMMAND
&---------------------------------------------------------------------
 
text 
----------------------------------------------------------------------
 
-->R_UCOMM text 
-->RS_SELFIELD text 
----------------------------------------------------------------------
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
 
DATA: GD_REPID LIKE SY-REPID, "Exists
REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
ENDIF.
 
loop at itab where chk = 'X'.
itab-color = 'C300'.
modify itab index sy-tabix transporting color.
endloop.
RS_SELFIELD-refresh = 'X'.
break-point.
 
ENDFORM. "USER_COMMAND

Regards

Vijay Babu Dudla

ankurgodre
Active Contributor
0 Kudos

Hi Ashu,

U need to make sure that ur filed catalogue which contains the field to behave as editable fileds on the alv list should include the follwing in the catalogue:

g_fieldcat-input = 'X'.

g_fieldcat-edit = 'X'.

The above two additions in the fields catalogue for that specific field will meke it editable in the output list. Hopw it helps..!!

Cheers

Ankur