Skip to Content
avatar image
Former Member

Refresh ALV Grid Output in OOPs

Hi all..

To refresh the ALV Grid, i have used REFRESH_TABLE_DISPLAY. The Grid is alone refreshed but not the actual output.

I have searched all the threads, but dint find any methods to refresh the output.

I am refreshing the container, FieldCatalog and actual internal table before

grid->set_table_for_first_display.

Could anyone suggest, How to refresh the ALV Grid Output?

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

10 Answers

  • avatar image
    Former Member
    Feb 20, 2009 at 05:01 AM

    Hi,

    How to refresh ALV- Grid in OO

    Check with this link.

    Thanks,

    Neelima.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 05:03 AM

    HI

    Just try this code.

    Here on double click ,the grid will be refreshed and the correspondung data will be displayed on

    the same grid.

    REPORT  zalv.
    
    TYPES : BEGIN OF stu,
    carrid TYPE sflight-carrid,
    connid TYPE sflight-connid,
    fldate TYPE sflight-fldate,
    w_check,
    END OF stu.
    DATA:
    fs_itab TYPE stu,
    t_itab LIKE TABLE OF fs_itab.
    DATA:
    es_row_no TYPE lvc_s_roid,
     r_grid TYPE REF TO cl_gui_alv_grid,
     r_container TYPE REF TO cl_gui_custom_container.
    DATA:
    t_fcat TYPE lvc_t_fcat,
    wa_fcat TYPE lvc_s_fcat.
    DATA:
     w_check.
    DATA:
     stbl TYPE lvc_s_stbl,
     soft TYPE char01.
    
    SELECT carrid connid fldate FROM
     sflight INTO CORRESPONDING FIELDS OF TABLE t_itab.
    
    CALL SCREEN 100.
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_event_handler DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_event_handler  DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS on_double_click FOR EVENT double_click
        OF cl_gui_alv_grid
        IMPORTING es_row_no.
    ENDCLASS.                    "lcl_event_handler DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_event_handler IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD on_double_click.
        w_check = 'X'.
    
        READ TABLE t_itab INTO fs_itab INDEX es_row_no-row_id.
        SELECT carrid connid fldate FROM sflight INTO CORRESPONDING FIELDS OF
        TABLE t_itab WHERE carrid EQ fs_itab-carrid AND connid EQ fs_itab-connid.
        CALL SCREEN 100.
    
      ENDMETHOD.                    " on_double_click
    ENDCLASS.                       " lcl_event_handler IMPLEMENTATION
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'TEST'.
      SET TITLEBAR 'TEST1'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
      CASE sy-ucomm.
        WHEN 'BACK'.
          LEAVE  TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  SET_HANDLER  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE set_handler OUTPUT.
      IF w_check = 'X'.
        CALL METHOD r_grid->refresh_table_display
          EXPORTING
            is_stable = stbl.
    *      i_soft_refresh = soft.
      ENDIF.
      CREATE OBJECT r_container
        EXPORTING
          container_name = 'CONTAINER'.
      CREATE OBJECT r_grid
        EXPORTING
          i_parent = r_container.
    
      wa_fcat-fieldname = 'W_CHECK'.
      wa_fcat-coltext = 'CHECK'.
      wa_fcat-checkbox = 'X'.
      wa_fcat-edit = 'X'.
      wa_fcat-col_pos = 1.
      APPEND wa_fcat TO t_fcat.
      CLEAR wa_fcat.
    
      wa_fcat-fieldname = 'CARRID'.
      wa_fcat-ref_table = 'SFLIGHT'.
      wa_fcat-ref_field = 'CARRID'.
      wa_fcat-col_pos = 2.
      APPEND wa_fcat TO t_fcat.
      CLEAR wa_fcat.
    
      wa_fcat-fieldname = 'CONNID'.
      wa_fcat-ref_table = 'SFLIGHT'.
      wa_fcat-ref_field = 'CONNID'.
      wa_fcat-col_pos = 3.
      APPEND wa_fcat TO t_fcat.
      CLEAR wa_fcat.
    
      CALL METHOD r_grid->set_table_for_first_display
    
    *  EXPORTING
    *    i_structure_name = 'SFLIGHT'
    *
    *   is_layout        = wa
        CHANGING
          it_fieldcatalog  = t_fcat
          it_outtab        = t_itab.
    
    
      SET HANDLER lcl_event_handler=>on_double_click FOR r_grid.
    ENDMODULE.                 " SET_HANDLER  OUTPUT

    Regards

    Hareesh.

    Edited by: Hareesh Menon on Feb 20, 2009 6:03 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 05:04 AM

    Hi Tharani,

    while u set the table for display check whether the grid' is initial' ..if true thn display orelse refresh the grid..this way..it works.....

    in pbo..

    if  container is initial.
    
        create object container
          exporting
            container_name = 'CCONTAINER'.
    
        create object grid
          exporting
            i_parent = container.
    
        call method grid->set_table_for_first_display
         exporting
    *     i_buffer_active               =
    *     i_bypassing_buffer            =
    *     i_consistency_check           =
            i_structure_name              = '     '
    *     is_variant                    =
    *     i_save                        =
    *     i_default                     = 'X'
    *     is_layout                     =
    *     is_print                      =
    *     it_special_groups             =
    *     it_toolbar_excluding          =
    *     it_hyperlink                  =
    *     it_alv_graphics               =
    *     it_except_qinfo               =
    *     ir_salv_adapter               =
          changing
            it_outtab                     = <output table>
    *     it_fieldcatalog               =
    *     it_sort                       =
    *     it_filter                     =
          exceptions
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            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.
    
    
      else.
        call method grid->refresh_table_display
    *    EXPORTING
    *      is_stable      = 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.
    endif.
    
    
    
    
    

    Regards,

    Mdi.Deeba

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 05:05 AM

    Hi,

      IF gv_grid IS INITIAL.
        CREATE OBJECT gv_custom_container
          EXPORTING
            container_name = gc_container.
        CREATE OBJECT gv_grid
          EXPORTING
            i_parent = gv_custom_container.
    
    * Creating ALV field catalog
        PERFORM prepare_field_catalog.
    * Define the layout
        PERFORM prepare_layout.
    
    * For refreshing ALV display
      ELSE.
        gv_set = gc_x.
      ENDIF.
    
      IF gv_set IS INITIAL.
      CALL METHOD gv_grid->set_table_for_first_display
      ELSE.
        CALL METHOD gv_grid->refresh_table_display
          EXCEPTIONS
            finished = 1
            others   = 2.
      ENDIF.
    

    Refer the above code for refreshing alv grid.Hope it will be helpful to you.

    Thanks,

    Srilakshmi.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20, 2009 at 05:07 AM

    Hi,

    Try using:-

    * to reflect the data changed into internal table
          DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
    
          IF ref_grid IS INITIAL.
            CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
              IMPORTING
                e_grid = ref_grid.
          ENDIF.
    
          IF NOT ref_grid IS INITIAL.
            CALL METHOD ref_grid->check_changed_data.
          ENDIF.
    

    Hope this helps you.

    Thanks & Regards,

    Tarun Gambhir

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 05:07 AM

    Hi,

    Modify your final internal table which you are displaying in your output first then call method:

    modify i_alv_data from wa_alv_data index e_row-index.

    wa_stable-row = e_row-index.

    call method grid1->refresh_table_display

    exporting

    is_stable = wa_stable.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 06:38 AM

    Hi,

    Thanks a lot for your replies.

    I have used all the methos you all specified, but it refreshing only the grid not the output.

    In debugging, I am getting a new data into the internal table before grid display

    Anyother suggestions??

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 11:03 AM

    Hi,

    Check the below Link

    alv-oo-and-refreshing-the-alv-grid

    Hope this helps you.

    Regards,

    Anki Reddy

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20, 2009 at 11:04 AM

    Also Check the below code

    TYPE-POOLS : SLIS.

    ----


    • Tables *

    ----


    TABLES:

    VBRK,

    VBRP.

    ----


    • Parameters and select options OR SELECTION SCREEN

    ----


    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

    SELECT-OPTIONS:

    S_VBELN FOR VBRK-VBELN.

    SELECTION-SCREEN END OF BLOCK B1.

    ----


    • Internal Tables *

    ----


    • work areas

    DATA: BEGIN OF IT_VBRP OCCURS 0,

    VBELN LIKE VBRK-VBELN,

    POSNR LIKE VBRP-POSNR,

    UEPOS LIKE VBRP-UEPOS,

    FKIMG LIKE VBRP-FKIMG,

    NETWR LIKE VBRP-NETWR,

    MEINS LIKE VBRP-MEINS.

    DATA : END OF IT_VBRP.

    ----


    • Variables *

    ----


    DATA : GR_ALVGRID TYPE REF TO CL_GUI_ALV_GRID,

    GC_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'CC_ALV',

    GR_CCONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

    GT_FIELDCAT TYPE LVC_T_FCAT,

    GS_LAYOUT TYPE LVC_S_LAYO,

    V_FLAG VALUE 'X'.

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

    • Start of Program *

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

    ----


    • INITIALIZATION. *

    ----


    INITIALIZATION.

    ----


    S_VBELN-LOW = 1.

    S_VBELN-HIGH = 1000000000.

    S_VBELN-OPTION = 'EQ'.

    S_VBELN-SIGN = 'I'.

    APPEND S_VBELN.

    ----


    • SELECTION-SCREEN *

    ----


    AT SELECTION-SCREEN.

    ----


    PERFORM VALIDATION.

    ----


    • START-OF-SELECTION *

    ----


    START-OF-SELECTION.

    ----


    PERFORM GET_DATA.

    CALL SCREEN 0100.

    ----


    • END-OF-SELECTION *

    ----


    END-OF-SELECTION.

    ----


    ----


    • TOP-OF-PAGE *

    ----


    TOP-OF-PAGE.

    ----


    ----


    • END-OF-PAGE *

    ----


    END-OF-PAGE.

    ----


    ----


    • AT USER-COMMAND *

    &----


    *& Form VALIDATION

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM VALIDATION .

    SELECT SINGLE VBELN

    FROM VBRK

    INTO VBRK-VBELN

    WHERE VBELN IN S_VBELN.

    IF SY-SUBRC <> 0.

    MESSAGE E000 WITH 'no billing documents found'.

    ENDIF.

    ENDFORM. " VALIDATION

    &----


    *& Form GET_DATA

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_DATA .

    SELECT VBELN

    POSNR

    UEPOS

    FKIMG

    NETWR

    MEINS

    FROM VBRP

    INTO TABLE IT_VBRP

    WHERE VBELN IN S_VBELN.

    ENDFORM. " GET_DATA

    &----


    *& Module DISPLAY_ALV OUTPUT

    &----


    • text

    ----


    MODULE DISPLAY_ALV OUTPUT.

    IF V_FLAG = 'X'.

    PERFORM DISPLAY_ALV.

    PERFORM PREPARE_FIELD_CATALOG CHANGING GT_FIELDCAT.

    PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.

    CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY

    EXPORTING

    • I_BUFFER_ACTIVE =

    • I_BYPASSING_BUFFER =

    • I_CONSISTENCY_CHECK =

    • I_STRUCTURE_NAME = 'VBRP'

    • IS_VARIANT =

    • I_SAVE =

    • I_DEFAULT = 'X'

    IS_LAYOUT = GS_LAYOUT

    • IS_PRINT =

    • IT_SPECIAL_GROUPS =

    • IT_TOOLBAR_EXCLUDING =

    • IT_HYPERLINK =

    • IT_ALV_GRAPHICS =

    • IT_EXCEPT_QINFO =

    CHANGING

    IT_OUTTAB = IT_VBRP[]

    IT_FIELDCATALOG = GT_FIELDCAT

    • IT_SORT =

    • IT_FILTER =

    EXCEPTIONS

    INVALID_PARAMETER_COMBINATION = 1

    PROGRAM_ERROR = 2

    TOO_MANY_LINES = 3

    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.

    CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

    EXPORTING

    I_READY_FOR_INPUT = 1.

    ELSE.

    <b>CALL METHOD GR_ALVGRID->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.</b>

    ENDIF.

    CLEAR V_FLAG.

    ENDIF.

    ENDMODULE. " DISPLAY_ALV OUTPUT

    &----


    *& Form DISPLAY_ALV

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM DISPLAY_ALV .

    IF GR_ALVGRID IS INITIAL.

    CREATE OBJECT GR_ALVGRID

    EXPORTING

    • I_SHELLSTYLE = 0

    • I_LIFETIME =

    I_PARENT = GR_CCONTAINER

    • I_APPL_EVENTS = space

    • I_PARENTDBG =

    • I_APPLOGPARENT =

    • I_GRAPHICSPARENT =

    • I_NAME =

    EXCEPTIONS

    ERROR_CNTL_CREATE = 1

    ERROR_CNTL_INIT = 2

    ERROR_CNTL_LINK = 3

    ERROR_DP_CREATE = 4

    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.

    ENDIF.

    ENDFORM. " DISPLAY_ALV

    &----


    *& Form PREPARE_FIELD_CATALOG

    &----


    • text

    ----


    • <--P_GT_FIELDCAT text

    ----


    FORM PREPARE_FIELD_CATALOG CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.

    DATA : LS_FCAT TYPE LVC_S_FCAT,

    L_POS TYPE I.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'VBELN'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Billing Document'.

    LS_FCAT-OUTPUTLEN = '10'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'POSNR'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Billing Item'.

    LS_FCAT-OUTPUTLEN = '6'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'UEPOS'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Higher Level Item'.

    LS_FCAT-OUTPUTLEN = '6'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'FKIMG'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Invoice Quantity'.

    LS_FCAT-OUTPUTLEN = '13'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'NETWR'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Net Value'.

    LS_FCAT-OUTPUTLEN = '15'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    LS_FCAT-FIELDNAME = 'MEINS'.

    LS_FCAT-TABNAME = 'IT_VBRP'.

    LS_FCAT-COL_POS = L_POS.

    LS_FCAT-SCRTEXT_M = 'Unit of Measure'.

    LS_FCAT-OUTPUTLEN = '3'.

    APPEND LS_FCAT TO P_GT_FIELDCAT.

    CLEAR LS_FCAT.

    L_POS = L_POS + 1.

    ENDFORM. " PREPARE_FIELD_CATALOG

    &----


    *& Form PREPARE_LAYOUT

    &----


    • text

    ----


    • <--P_GS_LAYOUT text

    ----


    FORM PREPARE_LAYOUT CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.

    P_GS_LAYOUT-ZEBRA = 'X'.

    P_GS_LAYOUT-GRID_TITLE = 'INVOICE DETAILS'.

    P_GS_LAYOUT-SMALLTITLE = 'X'.

    P_GS_LAYOUT-EDIT = 'X'.

    ENDFORM. " PREPARE_LAYOUT

    &----


    *& Module STATUS_0100 OUTPUT

    &----


    • text

    ----


    MODULE STATUS_0100 OUTPUT.

    SET PF-STATUS 'CANCEL'.

    • SET TITLEBAR 'xxx'.

    ENDMODULE. " STATUS_0100 OUTPUT

    &----


    *& Module USER_COMMAND_0100 INPUT

    &----


    • text

    ----


    MODULE USER_COMMAND_0100 INPUT.

    CASE SY-UCOMM.

    WHEN 'BACK'.

    LEAVE TO SCREEN 0.

    WHEN 'CANCEL'.

    LEAVE TO SCREEN 0.

    WHEN 'EXIT'.

    CALL TRANSACTION 'SE38'.

    WHEN 'CHANGE'.

    IF GR_ALVGRID->IS_READY_FOR_INPUT( ) = 0.

    CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

    EXPORTING

    I_READY_FOR_INPUT = 1.

    ELSE.

    CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

    EXPORTING

    I_READY_FOR_INPUT = 0.

    ENDIF.

    ENDCASE.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 30, 2009 at 10:24 AM

    HI,

    It got solved. The Refresh Table Display is checked only if the Grid as value.

    Where else i have called Refresh Table Display even before the grid is filled.

    Add comment
    10|10000 characters needed characters exceeded