ALV: Switch on and off the ready-for-input status of the entire grid

SAP Tech Pro

SAP Technical Blog
Magzter [CPS] IN

ALV: Switch on and off the ready-for-input status of the entire grid

ALV: Switch on and off the ready-for-input status of the entire grid


PROGRAM BCALV_EDIT_01.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This report illustrates the simplest case of using an
* editable ALV Grid Control.
* Background:
* ~~~~~~~~~~~
* As far as the edit feature is concerned
* a cell of the alv grid control can have the following states:
*    1.non-editable : edit feature not set for this cell
*    2.editable     : edit feature set for this cell
* The second state ("editable") has two substates:
*    2a.editable and not ready for input:edit feature set but not active
*    3b.editable and ready for input    :edit feature set and active
* In this example, all cells are set "editable".
* You switch between "editable and not ready for input" and
* "editable and ready for input" using method SET_READY_FOR_INPUT.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Switch the state using the "Display/Change" icon. Initially,
* the whole grid is in state "editable and deactivated".
* After switching the state you may change values and enter new
* lines. No semantic checks are made in this example.
*-----------------------------------------------------------------
* Essential steps (search for '�')
* ~~~~~~~~~~~~~~~
* 1.Set status of all cells to editable using the layout structure.
* 2.Use SET_READY_FOR_INPUT to activate the edit feature initially.
*   (state "editable activated").
* 3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
* 4.Use SET_READY_FOR_INPUT to switch between the substates.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


DATA: ok_code LIKE sy-ucomm,
      save_ok like sy-ucomm,
      g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
      g_grid  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout TYPE lvc_s_layo,
      g_max type i value 100.

DATA: gt_outtab type table of sflight.

*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
CALL SCREEN 100 starting at 1 1..

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  set TITLEBAR 'MAIN100'.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container.
    CREATE OBJECT g_grid
           EXPORTING i_parent = g_custom_container.
*�1.Set status of all cells to editable using the layout structure.
    gs_layout-edit = 'X'.

    select * from sflight into table gt_outtab up to g_max rows.

    CALL METHOD g_grid->set_table_for_first_display
         EXPORTING i_structure_name = 'SFLIGHT'
                   is_layout        = gs_layout
         CHANGING  it_outtab        = gt_outtab.
*�2.Use SET_READY_FOR_INPUT to allow editing initially.
*   (state "editable and ready for input").
    CALL METHOD g_grid->set_ready_for_input
          EXPORTING i_ready_for_input = 1.

  ENDIF.
ENDMODULE.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
  save_ok = ok_code.
  clear ok_code.
  CASE save_ok.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN 'SWITCH'.
      PERFORM switch_edit_mode.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
ENDMODULE.
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM switch_edit_mode.
*�3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
  IF g_grid->is_ready_for_input( ) EQ 0.
*�4.Use SET_READY_FOR_INPUT to switch between the substates.
    CALL METHOD g_grid->set_ready_for_input
                     EXPORTING i_ready_for_input = 1.
  ELSE.
    CALL METHOD g_grid->set_ready_for_input
                     EXPORTING i_ready_for_input = 0.
  ENDIF.
ENDFORM.                               " SWITCH_EDIT_MODE

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in