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.
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 ).