2 Replies Latest reply: Nov 15, 2007 9:37 PM by Uwe Schieferstein RSS

ALV: changing internal table in data_changed event.

Aleksandr Bavbel
Currently Being Moderated

Hi, ABAP-gurus.

 

I use OO ALV with editable columns, so I handle data_changes event to check the data, entered in ALV by user.

I need to change data in some other cells, connected with changed.

Chahging internal table directly doesn't work here.

With the cells in the same row method er_data_changed->modify_cell works fine, but now I need to change data in rows, that haven't been touched upon the changing.

 

  LOOP AT er_data_changed->mt_mod_cells INTO ls_cell.
    READ TABLE gt_bul ASSIGNING <fs_bul> INDEX ls_cell-row_id.
    CHECK sy-subrc = 0.
    CASE ls_cell-fieldname.
      WHEN 'EXTBULNR'.

        LOOP AT gt_bul ASSIGNING <fs_bul_tmp>
                           WHERE prknum = <fs_bul>-prknum AND
                                 wbillnr = <fs_bul>-wbillnr AND
                                 wbillgjahr = <fs_bul>-wbillgjahr AND
                                 shiftnum = <fs_bul>-shiftnum AND
                                 pernr = <fs_bul>-pernr.
          CALL METHOD er_data_changed->modify_cell
            EXPORTING
              i_fieldname = 'EXTBULNR'
              i_value        = ls_cell-value
              i_row_id     = sy-tabix.
        ENDLOOP.
    ENDCASE.
  ENDLOOP.

 

This peace of code cause dump ( there is no the proper row in the list of changed row in er_data_changed ).

Anybody can help me?

  • Re: ALV: changing internal table in data_changed event.
    Manish Joshi
    Currently Being Moderated

    Hello,

     

    In case you need to modify arbitrary no of rows and cells from that event handler you should use a different approach.....

     

    Assuming that your internal table is gt_bul and your alv grid variable is gr_alv_grid...You need to call...

    <b>  CALL METHOD gr_alv_grid->refresh_table_display

        EXPORTING

          i_soft_refresh = 'X'

        EXCEPTIONS

          finished       = 1

          OTHERS         = 2.</b>

     

    after you have finished updating internal table gt_bul directly, like...

    <b>LOOP AT gt_bul ASSIGNING <fs_bul_tmp>

                               WHERE prknum = <fs_bul>-prknum AND

                                     wbillnr = <fs_bul>-wbillnr AND

                                     wbillgjahr = <fs_bul>-wbillgjahr AND

                                     shiftnum = <fs_bul>-shiftnum AND

                                     pernr = <fs_bul>-pernr.

              <fs_bul_tmp> = ls_cell-value

    ENDLOOP.</b>

     

    Regards,

    Manish

  • Re: ALV: changing internal table in data_changed event.
    Uwe Schieferstein
    Currently Being Moderated

    Hello Aleksandr

     

    The most appropriate event for additional modifications of the output data AFTER having retrieved the changes from the editable ALV list is event <b>DATA_CHANGED_FINISHED</b>.

    <i>Why</i>?

    Because the output itab is already updated with the changes from the editable grid AND the changes are available (<b>ET_GOOD_CELLS</b>).

     

    For implementing the logic have a look at my sample report <b>ZUS_SDN_ALVGRID_EDITABLE_5.</b> Depending on the changed value for the delete flag the sort key is modified afterwards:

    - LOEVM = 'X' -> ZUAWA = ' ' (space)
    - LOEVM = ' '  -> ZUAWA = '002'

     

     

    *&---------------------------------------------------------------------*
    *& Report  ZUS_SDN_ALVGRID_EDITABLE_5
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  zus_sdn_alvgrid_editable_5.
    
    
    TYPE-POOLS: abap.
    
    DATA:
      gd_repid         TYPE syrepid,
      gd_okcode        TYPE ui_func,
    *
      gs_layout        TYPE lvc_s_layo,
      gt_fcat          TYPE lvc_t_fcat,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid          TYPE REF TO cl_gui_alv_grid.
    
    
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE knb1.
    TYPES: END OF ty_s_outtab.
    
    DATA:
      gs_outtab        TYPE ty_s_outtab,
      gt_outtab        TYPE STANDARD TABLE OF ty_s_outtab
                       WITH DEFAULT KEY.
    
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler DEFINITION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler DEFINITION.
    
      PUBLIC SECTION.
    
        CLASS-METHODS:
          handle_data_changed
            FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed
              e_onf4
              e_onf4_before
              e_onf4_after
              e_ucomm
              sender,
    
          handle_data_changed_finished
            FOR EVENT data_changed_finished OF cl_gui_alv_grid
            IMPORTING
              e_modified
              et_good_cells.
    
    
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler IMPLEMENTATION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler IMPLEMENTATION.
    
      METHOD handle_data_changed.
    *   define local data
    
    
      ENDMETHOD.                    "handle_data_changed
    
      METHOD handle_data_changed_finished.
    *   define local data
        DATA:
          ls_outtab      TYPE ty_s_outtab,
          ls_cell        TYPE lvc_s_modi.
    
        LOOP AT et_good_cells INTO ls_cell
                              WHERE ( fieldname = 'LOEVM' ).
    
          READ TABLE gt_outtab INTO ls_outtab INDEX ls_cell-row_id.
          "       Delete flag set
          IF ( ls_cell-value = abap_true ).
            ls_outtab-zuawa = space.
    
    
            "       Delete flag removed
          ELSE.
            ls_outtab-zuawa = '002'.
          ENDIF.
    
          MODIFY gt_outtab FROM ls_outtab INDEX ls_cell-row_id.
        ENDLOOP.
    
      ENDMETHOD.                    "handle_data_changed_finished
    
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    
    
    
    
    START-OF-SELECTION.
    
    
      SELECT * FROM knb1 INTO TABLE gt_outtab UP TO 20 ROWS
        WHERE bukrs = '1000'.
    
    
    
    
    
    * 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_grid
        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
      PERFORM build_fieldcatalog.
    
      PERFORM set_layout.
    
      SET HANDLER:
        lcl_eventhandler=>handle_data_changed          FOR go_grid,
        lcl_eventhandler=>handle_data_changed_finished FOR go_grid.
    
    
    * Display data
      CALL METHOD go_grid->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
      gd_repid = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_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'.
    * Flow logic (no elements on screen):
    *  PROCESS BEFORE OUTPUT.
    *    MODULE STATUS_0100.
    **
    *  PROCESS AFTER INPUT.
    *    MODULE USER_COMMAND_0100.
    
    
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    
      CALL METHOD go_grid->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.
    
    * Fetch changes on ALV grid
      go_grid->check_changed_data( ).
    
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
    
    
        WHEN OTHERS.
      ENDCASE.
    
    
    
    
    
      CLEAR: gd_okcode.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG_KNB1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM build_fieldcatalog .
    * 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.
    
    
    
    
    " Set all non-keyfields editable
      LOOP AT gt_fcat INTO ls_fcat
                      WHERE ( key = abap_false ).
        ls_fcat-edit    = abap_true.
    
        MODIFY gt_fcat FROM ls_fcat.
      ENDLOOP.
    
    
    ENDFORM.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_LAYOUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_layout .
    
      CLEAR: gs_layout.
    
      gs_layout-cwidth_opt = abap_true.
      gs_layout-zebra      = abap_true.
    
    **  gs_layout-stylefname = 'CELLTAB'.
    
    ENDFORM.                    " SET_LAYOUT

     

     

    Regards

      Uwe

Actions