Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to add an editable checkbox to an alv grid

Hi..

I need to add an editable checkbox to a alv grid.

I wouls appreciatet it if anyone could provide some sample code.

The standard example BCALV_EDIT_05 is an oops example... I need a simple example

Please help

thanks

Karen

Tags:
Former Member
replied

hi

after you pass a field as checkbox in fieldcat

then in layout populate edit

ex wa_layout-edit = 'X'.

try the following code

REPORT ZALV5.

TYPE-POOLS: slis.

tables: mara.

DATA: begin of it_mara OCCURS 0,

matnr like mara-matnr,

mbrsh like mara-mbrsh,

matkl like mara-matkl,

meins like mara-meins,

ersda like mara-ersda,

ernam like mara-ernam,

W_CHK type c ,

END OF it_mara.

*data: it_mara like mara occurs 0 with header line.

data:it_feildtab type slis_t_fieldcat_alv,

wa_fieldcat type slis_fieldcat_alv.

*DATA: i_private TYPE slis_data_caller_exit,

data: i_selfield TYPE slis_selfield,

W_exit(1) TYPE c.

PARAMETERS: p_title TYPE sy-title default 'ALV'.

*

START-OF-SELECTION.

SELECT matnr mbrsh matkl meins ersda ernam FROM mara

INTO corresponding fields of table it_mara.

wa_fieldcat-col_pos = '1'.

wa_fieldcat-fieldname = 'W_CHK'.

*wa_FIELDCAT-KEY = 'X'.

*wa_fieldcat-tabname = 'IT_MARA'.

*wa_fieldcat-seltext_s = 'units of measure'.

wa_fieldcat-checkbox = 'X'.

APPEND wa_fieldcat TO it_feildtab.

CLEAR wa_fieldcat .

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '2'.

wa_fieldcat-tabname = 'IT_MARA'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-key = 'X'.

wa_fieldcat-hotspot = 'X'.

wa_fieldcat-seltext_s = 'no'.

APPEND wa_fieldcat TO it_feildtab.

CLEAR wa_fieldcat .

wa_fieldcat-col_pos = '3'.

wa_fieldcat-fieldname = 'MBRSH'.

*wa_FIELDCAT-KEY = 'X'.

wa_fieldcat-tabname = 'IT_MARA'.

wa_fieldcat-seltext_s = 'Ind.sec'.

APPEND wa_fieldcat TO it_feildtab.

CLEAR wa_fieldcat .

wa_fieldcat-col_pos = '4'.

wa_fieldcat-fieldname = 'MATKL'.

*wa_FIELDCAT-KEY = 'X'.

wa_fieldcat-tabname = 'IT_MARA'.

wa_fieldcat-seltext_s = 'Description'.

APPEND wa_fieldcat TO it_feildtab.

CLEAR wa_fieldcat .

wa_fieldcat-col_pos = '5'.

wa_fieldcat-fieldname = 'MEINS'.

*wa_FIELDCAT-KEY = 'X'.

wa_fieldcat-tabname = 'IT_MARA'.

wa_fieldcat-edit = 'X'.

wa_fieldcat-seltext_s = 'units of measure'.

APPEND wa_fieldcat TO it_feildtab.

CLEAR wa_fieldcat .

CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

EXPORTING

i_title = p_title

i_selection = 'X'

i_zebra = 'X'

I_SCREEN_START_COLUMN = 0

I_SCREEN_START_LINE = 0

I_SCREEN_END_COLUMN = 0

I_SCREEN_END_LINE = 0

i_checkbox_fieldname = 'W_CHK'

  • I_LINEMARK_FIELDNAME =

  • I_SCROLL_TO_SEL_LINE = 'X'

i_tabname = 'IT_MARA'

  • i_structure_name = 'IT_MARA'

IT_FIELDCAT = it_feildtab

  • IT_EXCLUDING =

  • I_CALLBACK_PROGRAM =

  • I_CALLBACK_USER_COMMAND =

  • IS_PRIVATE = I_PRIVATE

IMPORTING

es_selfield = i_selfield

e_exit = w_exit

TABLES

t_outtab = it_mara

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE i000(0k) WITH sy-subrc.

ENDIF.

LOOP AT it_mara WHERE W_CHK = 'X'.

WRITE: / it_mara-ersda, it_mara-ernam.

ENDLOOP.

reward if helpful

prasanth

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question