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

make alv editable using checkbox

Former Member
0 Likes
4,335

Below is the screenshot of my output.

My requirement is whenever I will click on a particular checkbox, the corresponding entry in the fields Branch and Percentage should become editable ( right now the whole field is showing as editable)

How can I write code for editing specific fields for multiple(or single) entries selected through checkbox?

Also the changes should be reflected in the custom table.

Here's my code:

report zalv25.
type-pools : slis.
types :begin of ty_final,
check(1),
zstudid1 type zstud1-zstudid1,
zstudname1 type zstud1-zstudname1,
zstudage type zstud1-zstudage,
zaddress type zstud1-zaddress,
zmobile type zstud1-zmobile,
zcompany type zstud1-zcompany,
zbranch type zstud1-zbranch,
zper type zstud1-zper,
end of ty_final.

data : wa_zstud1 type zstud1,
it_zstud1 type table of zstud1 with header line.

data : it_field type slis_t_fieldcat_alv,
wa_field type slis_fieldcat_alv,
wa_layout type slis_layout_alv,
w_repid like sy-repid.
w_repid = sy-repid.

selection-screen begin of block b1 with frame title text-001.
parameters : id type zstud1-zstudid1.
selection-screen end of block b1.

start-of-selection.

select * from zstud1 into table it_zstud1.

end-of-selection.

perform field_catalog.
perform alv_display.

form field_catalog.
wa_field-fieldname = 'CHECK'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-outputlen = 1.
wa_field-input = 'X'.
wa_field-checkbox = 'X'.
wa_field-edit = 'X'.
* wa_field-hotspot = 'X'.
wa_field-seltext_l = 'Check '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZSTUDID1'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-seltext_l = 'ID '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZSTUDNAME1'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-seltext_l = 'NAME '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZSTUDAGE'.
wa_field-tabname = 'IT_ZSTUD1'.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZADDRESS'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-seltext_l = 'ADDRESS '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZMOBILE'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-seltext_l = 'MOBILE '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZBRANCH'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-input = 'check'.
wa_field-edit = 'check'.
wa_field-seltext_l = 'BRANCH '.
append wa_field to it_field.
clear wa_field.

wa_field-fieldname = 'ZPER'.
wa_field-tabname = 'IT_ZSTUD1'.
wa_field-input = 'check'.
wa_field-edit = 'check'.
wa_field-seltext_l = 'PERCENTAGE '.
append wa_field to it_field.
clear wa_field.
endform.

form alv_display.

call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = ' w_repid'
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = '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 = wa_layout
it_fieldcat = it_field
* 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
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = it_zstud1
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.

endform.

10 REPLIES 10
Read only

Abinathsiva
Active Contributor
3,767

Hi, Bhavana

Try using REUSE_ALV_POPUP_TO_SELECT below eg., GR Quantity is editable...

Read only

Sandra_Rossi
Active Contributor
3,767

Weird initialization of those 1-character fields:

wa_field-input = 'check'.
wa_field-edit = 'check'.

Do you mean:

wa_field-input = 'X'.
wa_field-edit = 'X'.
Read only

Sandra_Rossi
Active Contributor
3,767

I think you can have such a control only by using the ALV grid control class CL_GUI_ALV_GRID. The questions "how to trigger code upon ticking a checkbox" (use HOTSPOT + event hotspot_click) and "how to make editable a given cell" (STYLEFNAME component/LVC_T_STYL) have already been asked in the forum.

Read only

0 Likes
3,767

Yes. My issue is solved now.

Thanks,

Regards.

Read only

Nawanandana
Active Contributor
3,767

Hi,

I found some program Edit One Cell In Alvs Based On Some Condition, plz check it will work for you. You have to modify this program any event instead of the condition .

Editable alv on click of button

Regards,

Nawa.

Read only

0 Likes
3,767

I am still not able to solve my issue. I tried everything but I am still not getting how I should do it.

Can someone at least tell me the syntax of how I should make the checkboxes functional by giving particular condition to make changes in selected records ?

Read only

0 Likes
3,767

Bhavana Rajput do you use CL_GUI_ALV_GRID now?

Read only

babu_gavi
Explorer
0 Likes
3,767

Hi Bhavana,

follow below steps

i. create 1 gui button for the report (tcode se41),whenever records are selected then user has to click edit button. then only usercommand will trigger.

ii.implement user command subroutine with following type of code(use your own internal tables).

loop selected records and use styles to enable/disable for particular fields.

  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.
Read only

3,767

Just to add more context to your answer, it's valid for CL_GUI_ALV_GRID, not for REUSE_ALV_GRID_DISPLAY.

Read only

Sandra_Rossi
Active Contributor
0 Likes
3,767

By the way, your checkbox column is redundant with the first "box column", which can be also used to select the lines.