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

ALV Grid for User input

Former Member
0 Likes
1,083

Hi there,

Can anyone tell me how to display a ALV grid that will allow the user to change the values in any cell? For example, lets say, we have a matrix of checkboxes, and the user should be able to check or uncheck in any of the cells.

Rgds,

Deb.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
986

Hi,

In the field catalog of the ALV Grid, just set the EDIT field to X for which ever field to be editable.

WA_FIELDCAT-EDIT - 'X'.

Regards,

Ravi

Note : Please mark the helpful answers

Hi,

In the field catalog of the ALV Grid, just set the EDIT field to X for which ever field to be editable.

WA_FIELDCAT-EDIT - 'X'.

Regards,

Ravi

Note : Please mark the helpful answers

6 REPLIES 6
Read only

Former Member
0 Likes
986

HI

GOOD

BCALV_TEST_LIST_LAYOUT shows checkboxes on its output

display. The documentation of the various ALV function modules is also a

very good source of information

GO THROUGH THIS LINK

http://sap.ittoolbox.com/code/archives.asp?i=10&d=3619&a=s

http://www.the-blue-orb.com/link/sap-db2/disk3/doc/79/11269b0edf11d4b595006094192fe3/content.htm

THANKS

MRUTYUN

Read only

Former Member
0 Likes
987

Hi,

In the field catalog of the ALV Grid, just set the EDIT field to X for which ever field to be editable.

WA_FIELDCAT-EDIT - 'X'.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

Former Member
0 Likes
986

Hi,

Write this code in the callback subroutine (eg: in USER_COMMAND subroutine),

Data ref1 type ref to cl_gui_alv_grid.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

E_GRID = ref1.

call method ref1->check_changed_data

Thanks,

Pramod

Read only

venkat_o
Active Contributor
0 Likes
986

Hi DebKumar Ghoshal,

<b>1</b>.

U have to define Checkbox field in the final table which u want to transfer through REUSE_ALV_GRID_DISPLAY.

<b>2</b>.

Set these fields while fieldcatalog building .

w_field-checkbox = 'X'.

w_field-input = 'X'.

<b>3</b>.

Have a look at this sample program.

This program shows Checkboxes and selecting those.Once u select and save .Automatically that value 'X is stored i the table .

&----


*& Report ZORAY1234 *

*& *

&----


REPORT zoray1234 .

TABLES :mard .

TYPE-POOLS :slis.

DATA: BEGIN OF i_mard OCCURS 0,

checkbox TYPE c ,

matnr TYPE mard-matnr,

werks TYPE mard-werks,

lgort TYPE mard-lgort,

labst TYPE mard-labst,

END OF i_mard.

DATA :i_field TYPE slis_t_fieldcat_alv,

w_field LIKE LINE OF i_field,

i_events TYPE slis_t_event,

w_events LIKE LINE OF i_events.

START-OF-SELECTION.

PERFORM get_data.

PERFORM build_field.

PERFORM build_events.

PERFORM display_data.

&----


*& Form get_data

&----


FORM get_data .

SELECT matnr werks lgort labst

FROM mard

INTO CORRESPONDING FIELDS OF TABLE i_mard

WHERE werks = 'NB4'.

ENDFORM. " get_data

&----


*& Form build_field

&----


FORM build_field .

CLEAR w_field.

CLEAR i_field.

w_field-fieldname = 'CHECKBOX'.

w_field-tabname = 'I_MARD'.

w_field-checkbox = 'X'.

w_field-input = 'X'.

w_field-seltext_m = 'Checkbox'.

APPEND w_field TO i_field.

CLEAR w_field.

w_field-fieldname = 'MATNR'.

w_field-tabname = 'I_MARD'.

w_field-seltext_m = 'Matnr'.

APPEND w_field TO i_field.

CLEAR w_field.

w_field-fieldname = 'WERKS'.

w_field-tabname = 'I_MARD'.

w_field-seltext_m = 'Werks'.

APPEND w_field TO i_field.

CLEAR w_field.

w_field-fieldname = 'LGORT'.

w_field-tabname = 'I_MARD'.

w_field-seltext_m = 'Lgort'.

APPEND w_field TO i_field.

CLEAR w_field.

w_field-fieldname = 'LABST'.

w_field-tabname = 'I_MARD'.

w_field-seltext_m = 'Labst'.

APPEND w_field TO i_field.

CLEAR w_field.

ENDFORM. " build_field

&----


*& Form display_data

&----


FORM display_data .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = 'ZORAY1234'

    • i_callback_pf_status_set = 'SET_PF_STATUS'

  • i_callback_user_command = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

it_fieldcat = i_field

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

it_events = i_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

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = i_mard

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

&----


*& Form set_pf_status

&----


FORM PF_STATUS_SET USING extab TYPE slis_t_extab.

SET PF-STATUS 'VENKAT' EXCLUDING extab.

ENDFORM. "set_pf_status

&----


*& Form user_command

&----


  • text

----


FORM user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield .

CASE ucomm.

WHEN 'BUTTON' .

LOOP AT i_mard WHERE checkbox = 'X'.

WRITE 😕 i_mard-matnr,

i_mard-werks,

i_mard-lgort,

i_mard-labst.

ENDLOOP.

WHEN 'BUTTON1'.

LOOP AT i_mard WHERE checkbox = 'X'.

WRITE 😕 i_mard-matnr,

i_mard-werks,

i_mard-lgort,

i_mard-labst.

ENDLOOP.

ENDCASE.

ENDFORM. "user_command

&----


*& Form build_events

&----


FORM build_events .

CLEAR i_events.

CLEAR i_events.

w_events-form = 'PF_STATUS_SET'.

w_events-name = 'PF_STATUS_SET'.

APPEND w_events TO i_events.

CLEAR w_events.

w_events-form = 'USER_COMMAND'.

w_events-name = 'USER_COMMAND'.

APPEND w_events TO i_events.

CLEAR w_events.

ENDFORM. " build_events

I think that it helps u.

<b>Thanks,

Venkat.O</b>

Read only

Former Member
0 Likes
986

Hi Deb,

Check the following code.


Report zooalv.
 
CLASS Lcl_application  DEFINITION DEFERRED.
 
data : g_alv   type ref to cl_gui_alv_grid,
       gref_container TYPE REF TO cl_gui_custom_container,
       gs_layout TYPE lvc_s_layo.
 
data :event_receiver TYPE REF TO lcl_application,
      gt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat.
 
 
DATA:gt_outtab type table of <table>. " change the table name here
 
data : gs_outtab like line of gt_outtab.
 
call screen 100.
 
 
************************************************************************
CLASS lcl_application 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.                              "lcl_application DEFINITION
 
 
CLASS lcl_application IMPLEMENTATION.
 
  METHOD handle_toolbar.
 
    DATA: ls_toolbar  TYPE stb_button.
 
* append a separator to normal toolbar
    CLEAR ls_toolbar.
    MOVE 3 TO ls_toolbar-butn_type.
    APPEND ls_toolbar TO e_object->mt_toolbar.
 
* append an icon to show booking table
    CLEAR ls_toolbar.
    MOVE 'ADD' TO ls_toolbar-function.
*   MOVE icon_insert_row TO ls_toolbar-icon.
    MOVE 'test add button'(111) TO ls_toolbar-quickinfo.
    MOVE  space TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.
 
  ENDMETHOD.
 
METHOD handle_user_command.
    DATA: lt_rows TYPE lvc_t_row.
    CASE e_ucomm.
      WHEN 'ADD'.
        clear gs_outtab.
        append  gs_outtab to gt_outtab.
 
            CALL METHOD g_alv->refresh_table_display
                    .
    ENDCASE.
 ENDMETHOD.                           "handle_user_command
endclass.
************************************************************************
 
 
 
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
 
  SET PF-STATUS 'STAT'.
*  SET TITLEBAR 'xxx'.
  create object gref_container
       exporting
         container_name = 'CCAREA_ALV'. " create screen with control area CCAREA_ALV
 
  create object g_alv
     exporting i_parent = GREF_DOCKING_CONTAINER.
 
  select * from <table> into table GT_OUTTAB.
 
  gs_fieldcat-fieldname = 'F1'.
  gs_fieldcat-ref_table = 'table'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.
 
  gs_fieldcat-fieldname = 'f2'.
  gs_fieldcat-ref_table = 'table'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.
 
  gs_fieldcat-fieldname = 'F3'.
  gs_fieldcat-ref_table = 'table'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.
 
  gs_layout-grid_title = 'TEST'.
 
 call method g_ALV->set_table_for_first_display
        exporting
         is_layout  = gs_layout
        changing 
         it_fieldcatalog = gt_fieldcat
*        it_sort = gt_sort
         it_outtab        = gt_outtab[].
 
*** addition button on alv
    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->handle_user_command FOR g_alv.
    SET HANDLER event_receiver->handle_toolbar FOR g_alv.
 
call method g_alv->register_edit_event exporting
   i_event_id = cl_gui_alv_grid=>mc_evt_modified.
 
*  Call method 'set_toolbar_interactive' to raise event TOOLBAR.
    CALL METHOD g_alv->set_toolbar_interactive.
 
ENDMODULE.                 " STATUS_0100  OUTPUT


I hope it will help you.

Regards,

Kinshuk

Read only

hymavathi_oruganti
Active Contributor
0 Likes
986

steps:

1. define method data_changed

2. implement method data_changed, write a perform /directly write logic.

3.define set handlers for data_changed in pbo and also register.

4. write the form of step 2 if perform is there.

----


  • CLASS LCL_EVENT_RECEIVER DEFINITION

----


*

----


CLASS LCL_EVENT_RECEIVER DEFINITION.

PUBLIC SECTION.

METHODS HANDLE_DATA_CHANGED

FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID

IMPORTING ER_DATA_CHANGED E_ONF4 E_UCOMM.

********************************************************

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


*

----


CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.

METHOD HANDLE_DATA_CHANGED.

PERFORM DATA_CHANGED USING ER_DATA_CHANGED E_UCOMM.

ENDMETHOD . "handle_data_changed

*************************************************

SET HANDLER EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR GO_GRID.

CALL METHOD GO_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = cl_gui_alv_grid=>mc_evt_modified.

CALL METHOD GO_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter.

***********************************************************

FORM DATA_CHANGED USING P_ER_DATA_CHANGED TYPE REF TO

CL_ALV_CHANGED_DATA_PROTOCOL E_UCOMM TYPE SY-UCOMM.

DATA: L_VALUE TYPE LVC_VALUE,

ls_mod_cell type lvc_s_modi.

LOOP AT P_ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELL.

CALL METHOD P_ER_DATA_CHANGED->GET_CELL_VALUE

EXPORTING

I_ROW_ID = LS_MOD_CELL-row_id

I_FIELDNAME = LS_MOD_CELL-fieldname

IMPORTING

E_VALUE = L_VALUE.

endform.