0

I am trying to display updated records in ALV but old records are being displayed.

Here is the code written in the screen exit of work order.

  TRY.
      cl_salv_table=>factory(
        EXPORTING
          r_container    = lo_cust_container
        IMPORTING
          r_salv_table   = lo_alv_table
        CHANGING
          t_table        = gt_wflog ).

**// Functions
      DATA(lo_alv_functions) = lo_alv_table->get_functions( ).
      lo_alv_functions->set_all( abap_true ).

**// Display Settings
      DATA(lo_alv_display) = lo_alv_table->get_display_settings( ).
      lo_alv_display->set_striped_pattern( abap_true ).

**// Layout Settings
      DATA: ls_layout_key TYPE salv_s_layout_key.
      DATA(lo_alv_layout) = lo_alv_table->get_layout( ).
      ls_layout_key-report = sy-repid.
      lo_alv_layout->set_key( ls_layout_key ).
      lo_alv_layout->set_save_restriction( cl_salv_layout=>restrict_user_independant ).

      lo_alv_columns->set_optimize( abap_true ).
      lo_alv_table->set_data( CHANGING t_table = gt_wflog[] ).
      lo_alv_table->display( ).

    CATCH cx_salv_msg cx_salv_error INTO DATA(lx_salv_msg).
      MESSAGE lx_salv_msg->get_text( ) TYPE 'I'.
  ENDTRY.

I tried to used method refresh lo_alv_table->refresh( ). with option soft or full refresh but nothing happened. First time call data is ok when subscreen is called again and there is change in data then updated records are not displayed. I can see updated records in the table during debug.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Umar Abdullah
  • 1,282
  • 1
  • 19
  • 37

3 Answers3

2

More than likely you have CX_SALV_NO_NEW_DATA_ALLOWED exception which is caught by TRY clause during the second call of your instantiation. That's why display() method is not executed.

There is a note in SET_DATA method documentation:

You are not able to call these methods in an event handler. If you
do you will get an error.

...

Exceptions
CX_SALV_NO_NEW_DATA_ALLOWED
You have called SET_DATA in an event handler.

In your context screen exit is the same as event handler as it is called by the same event.

Solution is confirmed by OP: "It works perfectly"

Added to declarations in the top include.

DATA go_alv_table TYPE REF TO cl_salv_table.

Added in the code

IF go_alv_table IS NOT BOUND.
  cl_salv_table=>factory( )
  ...
ENDIF.

Added after set_data method call

go_alv_table->refresh( refresh_mode = if_salv_c_refresh=>soft ).
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
1

That's a well-known issue with controls. If you instantiate any GUI control (in your case, it's the ALV grid) inside a container in which there was already a control which has not been freed up (in your case, the ALV grid first instantiated using cl_salv_table=>factory), then the old control still shows up, the new one is not shown.

Two solutions :

  • Either you keep instantiating the control, but then you must free the previous control. For this, you must call control->FREE( ) followed by the statement FREE control. This method is available for all controls (even the container itself can be freed, all its inner controls are then freed up).

  • Or you change the logic by instantiating the control only once, and you refresh its contents.

Special case: some controls may be wrapped by some wrapper classes which don't give access to the control (SALV classes for instance), so the easy way is to free the container to which the control is attached.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
0

Just an addition to @suncatcher's answer. Firstly checks whether a reference variable contains a valid reference: 'IF go_alv_grid IS BOUND'.

Example:

SELECT * FROM zemployees BYPASSING BUFFER INTO TABLE it_zemployees.

IF go_alv_grid IS BOUND. 
  go_alv_grid->refresh( ).

ELSE.
  cl_salv_table=>factory(
EXPORTING
  r_container    = NEW cl_gui_custom_container( 'CONTAINER_NAME' ) 
  container_name = 'CONTAINER_NAME'
IMPORTING
  r_salv_table   = go_alv_grid
CHANGING
  t_table        = it_zemployees
  ).

  "Style the table
  go_alv_grid->get_functions( )->set_all( ).
  go_alv_grid->get_columns( )->set_optimize( ).
  go_alv_grid->get_display_settings( )->set_striped_pattern( abap_true ).


  go_alv_grid->display( ).
ENDIF.
Shreyder
  • 29
  • 4