Thursday, August 17, 2017

ALV Report Refresh Timely

Sometimes we need a report which will be updated timely and the output screen will reflect with the updated data. In production department we need this kind of approach which displays timely updated data for production control. In the following example we have developed a custom table and the table has been populated data in different time. The report fetches data from that custom table and displays output in ALV. Now whenever data is updated into the table the report will display the updated record after a particular time slab. This is very useful when we deal with transnational data.

Create a table as follows:


The table contains one line of data.


The program is as follows:

REPORT zsr_test NO STANDARD PAGE HEADING.

CLASS lcl_timer DEFINITION DEFERRED.
DATA: mesg     TYPE char50,
      lv_uzeit TYPE char8,
      wa_tab   TYPE zdbtablog,
      it_tab   TYPE TABLE OF zdbtablog.

DATA: ob_grid  TYPE REF TO cl_gui_alv_grid,
      ob_recev TYPE REF TO lcl_timer,
      ob_timer TYPE REF TO cl_gui_timer.

CLASS lcl_timer DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_finished FOR EVENT finished OF cl_gui_timer.
ENDCLASS.

CLASS lcl_timer IMPLEMENTATION.
  METHOD handle_finished.
    PERFORM refresh_data.
    CONCATENATE sy-uzeit+0(2) ':'
                sy-uzeit+2(2) ':'
                sy-uzeit+4(2)
                INTO lv_uzeit.
    CONCATENATE 'Last Update at' lv_uzeit
           INTO mesg SEPARATED BY space.
    MESSAGE mesg TYPE 'S'.
    CALL METHOD ob_timer->run.
  ENDMETHOD.                    "handle_finished
ENDCLASS.

START-OF-SELECTION.
  PERFORM select_data.

END-OF-SELECTION.
  CREATE OBJECT ob_timer.
  CREATE OBJECT ob_recev.
  SET HANDLER ob_recev->handle_finished FOR ob_timer.
  ob_timer->interval = 30.
  CALL METHOD ob_timer->run.
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_data .

  SELECT FROM zdbtablog INTO TABLE it_tab.
  IF sy-subrc = 0.
    SORT it_tab BY zmatnr.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REFRESH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM refresh_data .

  IF ob_grid IS INITIAL .
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ob_grid.
  ENDIF.

  IF ob_grid IS NOT INITIAL.
    PERFORM select_data.
    CALL METHOD ob_grid->refresh_table_display.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_data .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program = sy-repid
      i_structure_name   = 'ZDBTABLOG'
    TABLES
      t_outtab           = it_tab
    EXCEPTIONS
      program_error      = 1
      OTHERS             2.

ENDFORM.


Report Output timely:




Data is uploaded by TMG with SM30:

12 comments:

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap video.

admin said...

Thanks very much . This abap code .i was looking for. You can check abap tutorial

jabashree said...

Nice article..it contains great information..thanks for sharing.But one thing when data is destroyed how to recovered this?

SAP HR Training in Chennai
SAP SD Training in Chennai
BEST SAP BASIS Training in Chennai

ERP Training said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sapvideos.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap video.

Anonymous said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap workflow training videos.

Anonymous said...

Thankyou for Sharing Great Information. It is Very Helpful Information on s4 hana training videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for s4 hana training videos.

Anonymous said...

Thank you ,
Well it was nice post and very helpful information on sap fiori training videos.

Anonymous said...

Thank you ,
Well it was nice post and very helpful information on sap wm training videos.

logistic-solutions said...


Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
supply diversity services

Unknown said...

I have read your blog and I got very useful and knowledgeable information from your blog. It’s really a very nice articlesap-mm training