14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Editing Data 10.4

it_user_commands = lt_user_commands

CHANGING

ct_data_table = gt_monsters ).

Listing 10.31 Creating a SALV Report Using a Container

10.4.5 Coding User Command Handling

Next, you need to change the user command handling to make the grid editable.

In this case, you want the user command handling to be in the controller part of

the program, reacting to a user command that the view (SALV grid) has sent it.

In Listing 10.32, the user has clicked a button to make the grid editable, so the

parameter ED_USER_COMMAND has the value ZEDIT. First, a method of ZCL_BC_VIEW_

SALV_TABLE is called (GET_ALV_GRID). This method returns an instance of CL_GUI_

ALV_GRID, which hides inside the SALV report object. Then, the program gets the

field catalog (list of columns in the re port) and controls which ones are to be

made editable. The important point is that the internal table that stores the display

data has to have a column called CELLTAB, defined as celltab TYPE lvc_t_styl.

You need this in each row of your table to define what cells in that row can be

made editable, because this setting is made on a cell-by-cell basis.

METHOD on_user_command.

*---------------------------------------------------------------*

* FOR EVENT added_function OF cl_salv_events

* IMPORTING ed_user_command

* ed_row

* ed_column.

*---------------------------------------------------------------*

* Local Variables

DATA: lo_alv TYPE REF TO cl_gui_alv_grid,

ls_layout TYPE lvc_s_layo,

ls_celltab TYPE lvc_s_styl,

lf_valid TYPE abap_bool ##needed,

lt_fcat TYPE lvc_t_fcat,

ld_answer TYPE char01.

FIELD-SYMBOLS: <ls_output> TYPE g_typ_over_ride,

<ls_celltab> TYPE lvc_s_styl.

CASE ed_user_command.

WHEN 'ZEDIT'. "A command to make the grid editable

lo_alv = mo_view->get_alv_grid( ).

IF lo_alv IS NOT BOUND.

451

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!