Skip to Content
avatar image
Former Member

Update Itab flag using ALV Grid

hi experts,

can you help me with this. i created a report that generates data from pa2006 using alv grid display then i added checkbox on the display. what i want is when i tick the checkbox it should modify the itab-flag field = 'X'. So that when i call the Delete command only data with flag='X' should be deleted in the itab and in pa2006.

here my source sode.

TYPE-POOLS: slis.

TABLES: pa0000, pa2006.

TYPES: BEGIN OF t_pa2006,
  pernr LIKE pa2006-pernr,
  begda LIKE pa2006-begda,
  endda LIKE pa2006-endda,
  subty LIKE pa2006-subty,
  anzhl LIKE pa2006-anzhl,
  flag(1) TYPE c,
  END OF t_pa2006.
DATA: it_pa2006 TYPE TABLE OF t_pa2006,
      gs_pa2006 TYPE t_pa2006.

DATA: gt_pa2006 TYPE TABLE OF pa2006.

* alv display
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
      l_fieldcat TYPE slis_fieldcat_alv,
      t_layout   TYPE slis_layout_alv.

DATA: answer(5).
DATA: lt_rows TYPE lvc_t_row.
DATA: lt_index LIKE LINE OF lt_rows.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.
SELECT-OPTIONS: pernr FOR pa2006-pernr NO INTERVALS,
                begda FOR pa2006-begda,
                endda FOR pa2006-endda,
                subty FOR pa2006-subty NO INTERVALS.

SELECTION-SCREEN END OF  BLOCK blk.
START-OF-SELECTION.
  SET PF-STATUS 'ZSTANDARD'.
  PERFORM get_pa2006.

END-OF-SELECTION.
  PERFORM display.
*----------------------------------------------------------------------*
* Form Set_pf_status
* Notes: Called by FM REUSE_ALV_GRID_DISPLAY
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "Set_pf_status
*&---------------------------------------------------------------------*
*&      Form  GET_PA2006
*&---------------------------------------------------------------------*
FORM get_pa2006 .
  DATA: wa_pa2006 TYPE pa2006.
  SELECT * FROM pa2006 INTO TABLE gt_pa2006 WHERE pernr IN pernr
                                        AND begda IN begda
                                        AND endda IN endda
                                        AND subty IN subty.
  IF gt_pa2006[] IS NOT INITIAL.
    LOOP AT gt_pa2006 INTO wa_pa2006.
      gs_pa2006-pernr = wa_pa2006-pernr.
      gs_pa2006-begda = wa_pa2006-begda.
      gs_pa2006-endda = wa_pa2006-endda.
      gs_pa2006-subty = wa_pa2006-subty.
      gs_pa2006-anzhl = wa_pa2006-anzhl.
      APPEND gs_pa2006 TO it_pa2006.
    ENDLOOP.
  ELSE.
    MESSAGE i001(00) WITH 'No data found!'.
    LEAVE LIST-PROCESSING.

  ENDIF.
ENDFORM.                    " GET_PA2006
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       ALV Grid display
*----------------------------------------------------------------------*
FORM display .
  PERFORM t_field_cat.
  PERFORM alv_grid.
ENDFORM.                    " DISPLAY
*&---------------------------------------------------------------------*
*&      Form  T_FIELD_CAT
*&---------------------------------------------------------------------*
FORM t_field_cat .
  PERFORM fill_field USING 'CHECK'  'Chk' 'X' 'X' 'X'.
  PERFORM fill_field USING 'PERNR'  'Employee #' '' '' ''.
  PERFORM fill_field USING 'BEGDA'  'Begin Date' '' '' ''.
  PERFORM fill_field USING 'ENDDA'  'End Date' '' '' ''.
  PERFORM fill_field USING 'SUBTY'  'Subtype' '' '' ''.
  PERFORM fill_field USING 'ANZHL'  'Quota ' '' '' ''.

ENDFORM.                    " T_FIELD_CAT
*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD
*&---------------------------------------------------------------------*
FORM fill_field  USING    p_fieldname
                          p_seltext
                          p_edit
                          p_chk
                          p_in.

  l_fieldcat-fieldname    = p_fieldname.
  l_fieldcat-tabname      = 'IT_PA2006'.
  l_fieldcat-seltext_l    = p_seltext.
  l_fieldcat-edit = p_edit.
  l_fieldcat-checkbox = p_chk.
  l_fieldcat-input = p_in.

  APPEND l_fieldcat TO t_fieldcat.
  CLEAR l_fieldcat.
ENDFORM.                    " FILL_FIELD

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Jun 09, 2011 at 04:31 PM

    Sorry, I overlooked that I also removed the following line of code, as it caused problems:

    l_fieldcat-checkbox = p_chk.
    

    l_fieldcat-checkbox should not be filled.

    Hope this helps.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 08, 2011 at 08:10 PM

    continuation:

    *&---------------------------------------------------------------------*
    *&      Form  ALV_GRID
    *&---------------------------------------------------------------------*
    FORM alv_grid .
      t_layout-zebra = 'X'.
      t_layout-colwidth_optimize = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program     = 'ZHR_PA2006_DEL'
    *      i_callback_top_of_page = 'TOP-OF-PAGE'
            i_callback_pf_status_set = 'SET_PF_STATUS'
            i_callback_user_command = 'USER_COMMAND'
            is_layout              = t_layout
            it_fieldcat            = t_fieldcat
          TABLES
            t_outtab               = it_pa2006
          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.                    " ALV_GRID
    *-----------------------------------------------------------------------*
    * Form User_command
    * Notes: Called by FM REUSE_ALV_GRID_DISPLAY
    *-----------------------------------------------------------------------*
    FORM user_command USING r_ucomm     LIKE sy-ucomm
                            rs_selfield TYPE slis_selfield.
      DATA: wa_pa2006 TYPE pa2006.
      DATA:lt_display LIKE it_pa2006.
    
      CONSTANTS: c_1 VALUE '1'.
      IF r_ucomm EQ 'DELETE'.
        LOOP AT it_pa2006 INTO gs_pa2006.
    *      IF gs_pa2006-flag EQ 'X'.
          CALL FUNCTION 'CO_ZP_POPUP_DEL'
            IMPORTING
              answer = answer.
          CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
            IMPORTING
              e_grid = g_grid.
    
    *      IF NOT g_grid IS INITIAL.
    *        CALL METHOD g_grid->check_changed_data.
    *      ENDIF.
    
          CALL METHOD g_grid->get_selected_rows
            IMPORTING
              et_index_rows = lt_rows.
    
    
          IF answer = c_1.
            LOOP AT lt_rows INTO lt_index.
              READ TABLE it_pa2006 INTO gs_pa2006 INDEX lt_index-index.
              IF sy-subrc = 0.
                DELETE it_pa2006 INDEX lt_index.
              ENDIF.
            ENDLOOP.
            DELETE FROM pa2006 WHERE pernr = gs_pa2006-pernr
                   AND begda = gs_pa2006-begda
                   AND endda = gs_pa2006-endda.
            COMMIT WORK.
    *        ENDIF.
    
          ENDIF.
          CALL METHOD g_grid->refresh_table_display.
        ENDLOOP.
    
      ENDIF.
    ENDFORM.  "User_command

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 09, 2011 at 07:08 AM

    Hi,

    I think you need to double click on row once you checked it to refresh values.

    Try this.

    Regards,

    Dhananjay

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 09, 2011 at 09:08 AM

    Add the following to t_layout before CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY':

    t_layout-box_fieldname = 'FLAG'.

    In Form User_command in your loop at it_pa2006 check the flag as follows:

    if gs_pa2006-flag = 'X'.

    .

    .

    The marked lines will have 'X' in FLAG.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi,

      after i apply this i'm still not getting "X" on my gs_pa2006-flag.

       t_layout-zebra = 'X'.
        t_layout-colwidth_optimize = 'X'.
        t_layout-box_fieldname = 'FLAG'.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program     = 'ZHR_PA2006_DEL'
      *      i_callback_top_of_page = 'TOP-OF-PAGE'
              i_callback_pf_status_set = 'SET_PF_STATUS'
              i_callback_user_command = 'USER_COMMAND'
              is_layout              = t_layout
              it_fieldcat            = t_fieldcat
            TABLES
              t_outtab               = it_pa2006
            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
      DATA: wa_pa2006 TYPE pa2006.
        DATA:lt_display LIKE it_pa2006.
      
        CONSTANTS: c_1 VALUE '1'.
        IF r_ucomm EQ 'DELETE'.
          LOOP AT it_pa2006 INTO gs_pa2006.
      *      IF gs_pa2006-flag = 'X'.
              CALL FUNCTION 'CO_ZP_POPUP_DEL'
                IMPORTING
                  answer = answer.
              CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
                IMPORTING
                  e_grid = g_grid.
      
      *      IF NOT g_grid IS INITIAL.
      *        CALL METHOD g_grid->check_changed_data.
      *      ENDIF.
      
              CALL METHOD g_grid->get_selected_rows
                IMPORTING
                  et_index_rows = lt_rows.
      
      
              IF answer = c_1.
                LOOP AT lt_rows INTO lt_index.
                  READ TABLE it_pa2006 INTO gs_pa2006 INDEX lt_index-index.
                  IF sy-subrc = 0.
                    DELETE it_pa2006 INDEX lt_index-index.
                  ENDIF.
                ENDLOOP.
                DELETE FROM pa2006 WHERE pernr = gs_pa2006-pernr
                       AND begda = gs_pa2006-begda
                       AND endda = gs_pa2006-endda.
                COMMIT WORK.
              ENDIF.
      *      ENDIF.
      *      CALL METHOD g_grid->refresh_table_display.
          ENDLOOP.
      
        ENDIF.

      please help

  • Jun 09, 2011 at 02:55 PM

    Try this:

    DATA gv_dis               TYPE disvariant.
    

      t_layout-zebra              = 'X'.
      t_layout-colwidth_optimize  = 'X'.
      t_layout-box_fieldname      = 'FLAG'.
      gv_dis-report               = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program          = gv_dis-report
            i_callback_pf_status_set = 'SET_PF_STATUS'
            i_callback_user_command  = 'USER_COMMAND'
            is_layout                = t_layout
            it_fieldcat              = t_fieldcat
            i_save                   = 'A'
            is_variant               = gv_dis
       IMPORTING
         es_exit_caused_by_user      = gv_str_exit_by_user
          TABLES
            t_outtab                 = it_pa2006
          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.
    
    * No delete?
      CASE 'X'.
        WHEN gv_str_exit_by_user-exit.
          LEAVE PROGRAM.
        WHEN gv_str_exit_by_user-back OR gv_str_exit_by_user-cancel.
          EXIT.
      ENDCASE.
    

    Your GUI_STATUS should be a copy of STANDARD_FULLSCREEN (FG SLVC_FULLSCREEN) and contain Pushbutton 'DELETE'.

    I copied your coding and modified it as detailed above - it worked okay. gs_pa2006-flag was filled for all the marked rows.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I did the below mentioned changes in your code and the flag variable got 'X' when checked.

      Commented the box fieldname assignment.

      *t_layout-box_fieldname = 'FLAG'.
      

      and added the grid settings and passed to ALV

        data lv_s_glay TYPE  LVC_S_GLAY.
        lv_s_glay-EDT_CLL_CB = 'X'.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
      ...
            I_GRID_SETTINGS        = lv_S_GLAY
      ....