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

Refresh button - ALV

Former Member
0 Likes
1,025

Hello all,

I added a Refresh button in one of my custom ALV report. Whenever I hit a Refresh button, I do a fresh data retrieval and based on the data retrieved, I modify my field catalog. But I observed that the Refresh functionality is not taking into account the new field catalogs. It is using the same field catalog from the first run for all the refresh results.

My User Command is something like this


FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.


 case r_ucomm.

    when 'REFRESH'.


*  Clear and Refresh all the internal tables and variables

        perform get_data.   (get new data and build field new field catalog)
        rs_selfield-refresh = 'X'.

 endcase.


ENDFORM.                "USER_COMMAND

Please let me know if I am missing something. Thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
857

Since you are using the function module, I believe the only way is to re-call the function module REUSE_ALV_GRID_DISPLAY each time the user refreshes.

Regards,

Rich Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
858

Since you are using the function module, I believe the only way is to re-call the function module REUSE_ALV_GRID_DISPLAY each time the user refreshes.

Regards,

Rich Heilman

Read only

0 Likes
857

Alright man, check this out, this is not bad for a "Friday". Here I am calling the function module over and over again while the user is clicking the REFRESH button.



report zrich_0001.

* Global ALV Data Declarations
type-pools: slis.

* Internal Tables
data: begin of itab occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      field1 type c,
      field2 type c,
      field3 type c,
      field4 type c,
      field5 type c,
      field6 type c,
      field7 type c,
      field8 type c,
      field9 type c,
      field10 type c,
      end of itab.

data: global_ucomm type sy-ucomm.

start-of-selection.

  perform call_alv.

*********************************************************************
*      Form  GET_DATA
*********************************************************************
form get_data.

  select mara~matnr makt~maktx
          into corresponding fields of table itab
               from mara
                 inner join makt
                  on mara~matnr = makt~matnr
                             up to 20 rows.

endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

  data: ifc type slis_t_fieldcat_alv.
  data: xfc type slis_fieldcat_alv.
  data: repid type sy-repid.
  data: counter type i.

  repid = sy-repid.

  global_ucomm = 'INIT'.

  while global_ucomm = 'REFRESH'
     or global_ucomm = 'INIT'.

    clear global_ucomm.

* Get some new data.
    perform get_data.

* Rebuild the FC
    clear xfc. refresh ifc.

    clear xfc.
    xfc-reptext_ddic = 'Material Number'.
    xfc-fieldname    = 'MATNR'.
    xfc-tabname      = 'ITAB'.
    xfc-outputlen    = '18'.
    append xfc to ifc.

    clear xfc.
    xfc-reptext_ddic = 'Material Description'.
    xfc-fieldname    = 'MAKTX'.
    xfc-tabname      = 'ITAB'.
    xfc-outputlen    = '40'.
    append xfc to ifc.

* Add another field to the FC each time it is refreshed
* just for demo purposes
    do counter times.

* Prevent dump
      if sy-index > 10.
        exit.
      endif.

      clear xfc.
      xfc-reptext_ddic = 'Another Field'.
      xfc-fieldname = sy-index.
      shift  xfc-fieldname left deleting leading space.
      concatenate 'FIELD' xfc-fieldname into xfc-fieldname.
      xfc-tabname      = 'ITAB'.
      xfc-outputlen    = '10'.
      append xfc to ifc.

    enddo.

* Call ABAP List Viewer (ALV)
    call function 'REUSE_ALV_GRID_DISPLAY'
         exporting
              i_callback_program       = repid
              i_callback_user_command  = 'HANDLE_USER_COMMAND'
              i_callback_pf_status_set = 'SET_PF_STATUS'
              it_fieldcat              = ifc
         tables
              t_outtab                 = itab.

    global_ucomm = sy-ucomm.
    counter = counter + 1.

  endwhile.

endform.

***********************************************************************
*       FORM set_Pf_status                                            *
***********************************************************************
form set_pf_status  using rt_extab type slis_t_extab..

  types: begin of texcl,
          fcode like rsmpe-func,
         end of texcl.

  data: iexcl type table of texcl.
  data: xexcl type texcl.

  xexcl-fcode = '&ABC'.      append xexcl to iexcl.
  xexcl-fcode = '&EB9'.      append xexcl to iexcl.
  xexcl-fcode = '&XPA'.      append xexcl to iexcl.
  xexcl-fcode = '&OMP'.      append xexcl to iexcl.
  xexcl-fcode = '&OAD'.      append xexcl to iexcl.
  xexcl-fcode = '&AVE'.      append xexcl to iexcl.
  xexcl-fcode = '&LFO'.      append xexcl to iexcl.
  xexcl-fcode = '&NFO'.      append xexcl to iexcl.

  set pf-status 'ALV_STANDARD' excluding iexcl..

endform.

***********************************************************************
*       FORM handle_User_Command                                      *
***********************************************************************
form handle_user_command using r_ucomm     like sy-ucomm
                               rs_selfield type slis_selfield.

  case r_ucomm.
    when 'REFRESH'.
      rs_selfield-exit = 'X'.
  endcase.

endform.

Regards,

RIch Heilman

Read only

0 Likes
857

RICH You are the BEST !!!

Read only

Former Member
0 Likes
857

Hi

In perform get_data.

write

Clear ITAB

Refresh ITAB

then populate the ITAB with hew data with select statements

so that new data will be fetched in ITAB and displayed

Reward points for useful Answers

Regards

Anji

Read only

Former Member
0 Likes
857

see the example code for refersh

REPORT Z_GET_REFRESH no standard page heading.

type-pools : slis.

tables : makt,

mara.

data : i_fieldcat type slis_t_fieldcat_alv.

data : begin of i_makt occurs 0,

matnr like makt-matnr,

maktx like makt-maktx,

end of i_makt.

data : v_repid like sy-repid,

g_user_command type slis_formname value 'USER_COMMAND',

g_status_set type slis_formname value 'SET_PF_STATUS'.

DATA:LC_GLAY TYPE LVC_S_GLAY.

select-options s_matnr for mara-matnr .

start-of-selection.

select matnr maktx from makt into table i_makt

where matnr in s_matnr.

end-of-selection.

  • Fill the fieldcatlog

perform fill_field.

  • Call the FM

perform call_fm.

&----


*& Form fill_field

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_field.

data wa_fieldcat type slis_fieldcat_alv.

clear : wa_fieldcat.

wa_fieldcat-tabname = 'I_MAKT'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-outputlen = '18'.

wa_fieldcat-seltext_l = 'Material #'.

wa_fieldcat-col_pos = '1'.

append wa_fieldcat to i_fieldcat.

clear : wa_fieldcat.

wa_fieldcat-tabname = 'I_MAKT'.

wa_fieldcat-fieldname = 'MAKTX'.

wa_fieldcat-outputlen = '40'.

wa_fieldcat-seltext_l = 'Material Desc'.

wa_fieldcat-col_pos = '2'.

append wa_fieldcat to i_fieldcat.

ENDFORM. " fill_field

&----


*& Form call_fm

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_fm.

v_repid = sy-repid.

LC_GLAY-EDT_CLL_CB = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = v_repid

I_CALLBACK_PF_STATUS_SET = g_status_set

I_CALLBACK_USER_COMMAND = g_user_command

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

I_GRID_SETTINGS = LC_GLAY

  • IS_LAYOUT =

IT_FIELDCAT = i_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = i_makt

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. " call_fm

----


  • FORM USER_COMMAND *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield. "#EC CALLED

data i_RSPARAMS like RSPARAMS occurs 0.

CASE R_UCOMM.

WHEN '&IC1'.

read table i_makt index rs_selfield-tabindex.

SET PARAMETER ID 'MAT' FIELD i_makt-matnr.

if not i_makt-matnr is initial.

call transaction 'MM02' and skip first screen.

endif.

when 'REFRESH'.

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

EXPORTING

CURR_REPORT = v_repid

  • IMPORTING

  • SP =

TABLES

SELECTION_TABLE = i_RSPARAMS

EXCEPTIONS

NOT_FOUND = 1

NO_REPORT = 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.

submit z_get_refresh with selection-table i_RSPARAMS.

rs_selfield-refresh = 'X'.

*

ENDCASE.

MOVE 'REFRESH' TO r_ucomm.

ENDFORM.

----


  • FORM set_pf_status *

----


FORM SET_PF_STATUS USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'ZSTANDARD' EXCLUDING rt_extab.

SET TITLEBAR sy-tcode.

ENDFORM.