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 OO ALV

Former Member
12,957

Hi,

I'm creating an OO ALV where I have a Modify Button that when triggered has to make editable all the cells of the selected row. Is it possible? I haven't found anything similar in the sdn...

Thanks in advance!!!

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
4,276

Hi,

- Add table field of type LVC_T_STYL to your output table.


data: begin of output_table occurs  0,
         ...
        cellstyles TYPE lvc_t_styl,     "table holds cells attributes for each row
       end of output_table.

- get selected row with GET_SELECTED_ROWS

- in your layout structure set which field is hold cell styles


layout-stylefname = u2018CELLSTYLESu2019.

- In PAI read the output table row (selected one) and change style of each cell


DATA lt_stylerow TYPE lvc_s_styl .

READ TABLE output_table INDEX idx.  "idx returned with *get_selected_rows*
if sy-subrc = 0.
   "change attributes of field to be editable
   ls_stylerow-fieldname = 'YOUR_FIELD_NAME' .
   ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.   "enable for edit (only for this cell)
   APPEND ls_stylerow TO cellstyles.

   ls_stylerow-fieldname = 'YOUR_NEXT_FIELD_NAME' .
   ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.   "enable for edit (only for this cell)
   APPEND ls_stylerow TO cellstyles.

MODIFY output_table.

- last thing I would forgot about is to instruct the ALV to be editable according to cellstyles with this method


r_alv->set_ready_for_input( i_ready_for_input = 1 ).

You do this for each your field in output_table structure. Of course you can use field symbols here to avoid typing each field name.

Regards

Marcin

Edited by: Marcin Pciak on Mar 6, 2009 12:57 PM

5 REPLIES 5
Read only

Former Member
0 Likes
4,276

Hi Carles,

This can be done through the ABAP oops, where you have reference BCALV_EDIT_02

Call the method Get_selected_rows from CL_GUI_ALV_GRID to get the selected rows from the

GRid and create a button(CHANGE) on the application toolbar for event to check.

write the code in the method created in the class to get the selected records editable.

Regards,

Madhavi

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
4,276

Hi,

Refer thread:-

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
4,276

Hi carles

Please find the example report for your exact requirement .

as this i developed for my project..

&----


*& Report ZUS_SDN_ALVGRID_EDITABLE_2

*&

&----


*& Thread: Edit the records in the GRID in change mode

*&

&----


REPORT zus_sdn_alvgrid_editable_2.

TYPES: BEGIN OF ty_s_outtab.

INCLUDE TYPE knb1 AS knb1.

TYPES: celltab TYPE lvc_t_styl.

TYPES: END OF ty_s_outtab.

TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab

WITH DEFAULT KEY.

DATA:

gd_okcode TYPE ui_func,

*

gt_fcat TYPE lvc_t_fcat,

gs_layout TYPE lvc_s_layo,

go_docking TYPE REF TO cl_gui_docking_container,

go_grid1 TYPE REF TO cl_gui_alv_grid.

DATA:

gt_outtab TYPE ty_t_outtab.

START-OF-SELECTION.

SELECT * FROM knb1 UP TO 100 ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_outtab

WHERE bukrs = '1000'.

PERFORM modify_outtab.

  • Create docking container

CREATE OBJECT go_docking

EXPORTING

parent = cl_gui_container=>screen0

ratio = 90

EXCEPTIONS

OTHERS = 6.

IF sy-subrc 0.

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

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

ENDIF.

  • Create ALV grid

CREATE OBJECT go_grid1

EXPORTING

i_parent = go_docking

EXCEPTIONS

OTHERS = 5.

IF sy-subrc 0.

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

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

ENDIF.

  • Build fieldcatalog and set hotspot for field KUNNR

PERFORM build_fieldcatalog_knb1.

PERFORM set_layout_and_variant.

  • Display data

CALL METHOD go_grid1->set_table_for_first_display

EXPORTING

is_layout = gs_layout

CHANGING

it_outtab = gt_outtab

it_fieldcatalog = gt_fcat

EXCEPTIONS

OTHERS = 4.

IF sy-subrc 0.

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

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

ENDIF.

  • Link the docking container to the target dynpro

CALL METHOD go_docking->link

EXPORTING

repid = syst-repid

dynnr = '0100'

  • CONTAINER =

EXCEPTIONS

OTHERS = 4.

IF sy-subrc 0.

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

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

ENDIF.

  • ok-code field = GD_OKCODE

CALL SCREEN '0100'.

END-OF-SELECTION.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS_0100'.

  • SET TITLEBAR 'xxx'.

    • CALL METHOD go_grid1->refresh_table_display

      • EXPORTING

      • IS_STABLE =

      • I_SOFT_REFRESH =

    • EXCEPTIONS

    • FINISHED = 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.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

TRANSLATE gd_okcode TO UPPER CASE.

CASE gd_okcode.

WHEN 'BACK' OR

'EXIT' OR

'CANC'.

SET SCREEN 0. LEAVE SCREEN.

WHEN 'CHANGE'.

PERFORM set_rows_editable.

WHEN OTHERS.

CALL METHOD go_grid1->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

finished = 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.

ENDCASE.

CLEAR: gd_okcode.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form BUILD_FIELDCATALOG_KNB1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_fieldcatalog_knb1 .

  • define local data

DATA:

ls_fcat TYPE lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

i_structure_name = 'KNB1'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

  • I_INTERNAL_TABNAME =

CHANGING

ct_fieldcat = gt_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.

      • Only non-key fields are editable

    • ls_fcat-edit = 'X'.

    • MODIFY gt_fcat FROM ls_fcat

    • TRANSPORTING edit

    • WHERE ( key NE 'X' ).

ENDFORM. " BUILD_FIELDCATALOG_KNB1

&----


*& Form SET_LAYOUT_AND_VARIANT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM set_layout_and_variant .

CLEAR: gs_layout.

gs_layout-cwidth_opt = abap_true.

gs_layout-zebra = abap_true.

gs_layout-sel_mode = 'D'.

    • gs_layout-edit = abap_true. " entire grid editable

gs_layout-stylefname = 'CELLTAB'.

ENDFORM. " SET_LAYOUT_AND_VARIANT

&----


*& Form SET_ROWS_EDITABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM set_rows_editable .

  • define local data

DATA: ls_outtab TYPE ty_s_outtab,

ls_fcat TYPE lvc_s_fcat,

ls_cell TYPE lvc_s_styl,

lt_celltab TYPE lvc_t_styl,

ls_row TYPE lvc_s_row,

lt_rows TYPE lvc_t_row.

CALL METHOD go_grid1->get_selected_rows

IMPORTING

et_index_rows = lt_rows

  • et_row_no =

.

CHECK ( lt_rows IS NOT INITIAL ).

LOOP AT gt_fcat INTO ls_fcat.

ls_cell-fieldname = ls_fcat-fieldname.

IF ( ls_fcat-key = abap_true ).

ls_cell-style = cl_gui_alv_grid=>mc_style_disabled.

ELSE.

ls_cell-style = cl_gui_alv_grid=>mc_style_enabled.

ENDIF.

INSERT ls_cell INTO TABLE lt_celltab. " sorted itab !!!

ENDLOOP.

LOOP AT lt_rows INTO ls_row.

READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.

ls_outtab-celltab = lt_celltab.

MODIFY gt_outtab FROM ls_outtab INDEX ls_row-index.

ENDLOOP.

  • set edit enabled cells ready for input

CALL METHOD go_grid1->set_ready_for_input

EXPORTING i_ready_for_input = 1.

ENDFORM. " SET_ROWS_EDITABLE

&----


*& Form MODIFY_OUTTAB

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM modify_outtab .

  • define local data

DATA: ls_outtab TYPE ty_s_outtab,

ls_fcat TYPE lvc_s_fcat,

ls_cell TYPE lvc_s_styl.

" Set all cells of grid non-editable

LOOP AT gt_fcat INTO ls_fcat.

ls_cell-fieldname = ls_fcat-fieldname.

ls_cell-style = cl_gui_alv_grid=>mc_style_disabled.

INSERT ls_cell INTO TABLE ls_outtab-celltab. " sorted itab !!!

ENDLOOP.

MODIFY gt_outtab FROM ls_outtab

TRANSPORTING celltab

WHERE ( bukrs IS NOT INITIAL ).

ENDFORM. " MODIFY_OUTTAB

regards,

Madhavi

Read only

MarcinPciak
Active Contributor
0 Likes
4,277

Hi,

- Add table field of type LVC_T_STYL to your output table.


data: begin of output_table occurs  0,
         ...
        cellstyles TYPE lvc_t_styl,     "table holds cells attributes for each row
       end of output_table.

- get selected row with GET_SELECTED_ROWS

- in your layout structure set which field is hold cell styles


layout-stylefname = u2018CELLSTYLESu2019.

- In PAI read the output table row (selected one) and change style of each cell


DATA lt_stylerow TYPE lvc_s_styl .

READ TABLE output_table INDEX idx.  "idx returned with *get_selected_rows*
if sy-subrc = 0.
   "change attributes of field to be editable
   ls_stylerow-fieldname = 'YOUR_FIELD_NAME' .
   ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.   "enable for edit (only for this cell)
   APPEND ls_stylerow TO cellstyles.

   ls_stylerow-fieldname = 'YOUR_NEXT_FIELD_NAME' .
   ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.   "enable for edit (only for this cell)
   APPEND ls_stylerow TO cellstyles.

MODIFY output_table.

- last thing I would forgot about is to instruct the ALV to be editable according to cellstyles with this method


r_alv->set_ready_for_input( i_ready_for_input = 1 ).

You do this for each your field in output_table structure. Of course you can use field symbols here to avoid typing each field name.

Regards

Marcin

Edited by: Marcin Pciak on Mar 6, 2009 12:57 PM

Read only

0 Likes
4,276

Hi,

I am agreeing with Mr.Marcin only in case of selected fields needs to be editable. Since i dont have sap access for me i could not able to confirm but i remember there should be EDIT option in LAYOUT, since we need to enable all the fields in the Layout. I am sorry if i am wrong.

Just Check:

BCALV_GRID_EDIT

BCALV_TEST_GRID_EDITABLE

Regards,

~Satya