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 display

Former Member
0 Likes
1,125

Hi,

I have a requirement to display the out put in ALV Grid and in the display there should be a Change,Refresh Push buttons.

when click on change button it will call some transaction and we will make the chages.

when we click on Refresh button it has to display the screen with the changes what we made earlier if any.

so i coded everthing is working fine except iam getting new screen with all the modifications when i click on Refresh button and when i click back it will go to the previous screen.

So my requirement is i want only one screen to be displayed when i click on Refresh button.

Hope iam clear in the question so can any one help me out to resolve this issue thanks in advance.

Hi,

I have a requirement to display the out put in ALV Grid and in the display there should be a Change,Refresh Push buttons.

when click on change button it will call some transaction and we will make the chages.

when we click on Refresh button it has to display the screen with the changes what we made earlier if any.

so i coded everthing is working fine except iam getting new screen with all the modifications when i click on Refresh button and when i click back it will go to the previous screen.

So my requirement is i want only one screen to be displayed when i click on Refresh button.

Hope iam clear in the question so can any one help me out to resolve this issue thanks in advance.

10 REPLIES 10
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,096

Hi,

Can you show us the code for refresh's function code (ok_code).

Regards,

Sesh

Read only

0 Likes
1,096

Hi,

This is the code for the Refresh button

WHEN 'REFRESH'.

CLEAR ITAB_FINAL.

REFRESH ITAB_FINAL.

PERFORM GET_DATA.

PERFORM GRID_DISP.

Read only

0 Likes
1,096

Hi,

I think you are deleting the internal table, re creating it and then recreating the ALV grid, instead try getting the data and refresh the ALV display using the method REFRESH_TABLE_DISPLAY.

Regards,

Sesh

Read only

0 Likes
1,096

Hi Sesh,

Thanks for your reply, but iam not aware of methods, can you please send me some example code for this.

Read only

0 Likes
1,096
Read only

0 Likes
1,096

Hi,

Please check the report BCALV_GRID_EDIT_VERIFY. This has the sample code for ALV refresh.

Regards,

Sesh

Read only

0 Likes
1,096

Hi Madan,

Check the following code


REPORT  ZALVSAVEUPDATE                                              .
INCLUDE <icon>.

CLASS Lcl_application  DEFINITION DEFERRED.

data : g_alv           type ref to cl_gui_alv_grid,
        gref_docking_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 sflight.

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 'Add RFC info'(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'.
       gs_outtab-CARRID = SPACE.
       gs_outtab-connid = space.
       gs_outtab-fldate = space.
        append  gs_outtab to gt_outtab.

   <b>         CALL METHOD g_alv->refresh_table_display
                    .</b>
    ENDCASE.
  ENDMETHOD.                           "handle_user_command

endclass.
************************************************************************



*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.

data : lt_sflight type table of sflight,
       ls_sflight like line of lt_sflight.

  SET PF-STATUS 'STAT'.
*  SET TITLEBAR 'xxx'.
  create object gref_docking_container
       exporting
         container_name = 'CCAREA_ALV'.

  create object g_alv
     exporting i_parent = GREF_DOCKING_CONTAINER.



  select * from SFLIGHT into table GT_OUTTAB.

  gs_fieldcat-fieldname = 'CARRID'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.

  gs_fieldcat-fieldname = 'CONNID'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.

  gs_fieldcat-fieldname = 'FLDATE'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  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                     " i_buffer_active = 'X'
*                   i_save = 'A'
*                   is_variant = gs_variant
                   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
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
data : ok_code type sy-ucomm.

case ok_code.
  when 'BACK'.
     LEAVE TO SCREEN 0.
endcase.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Hope it helps.

Regards,

Kinshuk

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,096

Hi,

Check this good piece of coding which I got from SDN.

FORM display_alv .

IF gr_alvgrid IS INITIAL .

*----Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6 .

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

Code Part 5 – Form checking instance existence, creating instance, setting for first display and refreshing

*----Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

others = 5 .

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

*----Here will be additional preparations

*--e.g. initial sorting criteria, initial filtering criteria, excluding

*--functions

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

CHANGING

it_outtab = gt_list[]

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.

*--Exception handling

ENDIF.

ELSE .

CALL METHOD gr_alvgrid->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

finished = 1

OTHERS = 2 .

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ENDIF .

Read only

Former Member
0 Likes
1,096

Hello,

Try out the FM, 'REFRESH_TABLE_DISPLAY'

See the SAP Examples in the BCALV_GRID* series in se38.

Regards,

Shehryar Dahar

Read only

Former Member
0 Likes
1,096

i want to know about wathpoint in debuging also what is use of F7 and F6