on 03-25-2024 12:37 PM
Hello,
My requrement is when i go and change the data in my table and hit refresh button my data should be refreshed.
Below is my code, Can some one help me fix this peice of code?
Thank You!
*&---------------------------------------------------------------------*
*& Report ZMMR001_SALV_DEMO
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmmr001_salv_demo.
"Top Of Page for Global Declaration.
INCLUDE zmmr001_salv_top.
"Selection Screen.
INCLUDE zmmr001_salv_sel.
"Program Logic.
INCLUDE zmmr001_salv_F01.
START-OF-SELECTION.
DATA(lt_data) = lcl_data=>get_data( ).
IF lt_data IS NOT INITIAL.
lcl_data=>process_data( EXPORTING it_data = lt_data ).
ELSE.
MESSAGE s117(lr).
ENDIF.
DATA(lo_obj) = NEW lcl_data( ).
lo_obj->display( ).
*&---------------------------------------------------------------------*
*& Include ZMMR001_SALV_TOP
*&---------------------------------------------------------------------*
"Table Declaration.
TABLES: z01m_empmst.
"Constants.
"Report Title
DATA: gv_text TYPE char50
VALUE 'SALV DEMO REPORT'.
"Table Type and Structures.
DATA : gt_emp TYPE TABLE OF z01m_empmst,
gs_emp TYPE z01m_empmst.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_layout TYPE slis_layout_alv,
gv_pos TYPE i.
TYPES: tt_outtb TYPE TABLE OF z01m_empmst WITH DEFAULT KEY.
DATA: gr_events TYPE REF TO cl_salv_events.
DATA: lo_gr_alv TYPE REF TO cl_salv_table,
lo_gr_functions TYPE REF TO cl_salv_functions_list.
DATA: lo_columns TYPE REF TO cl_salv_columns,
lo_column TYPE REF TO cl_salv_column_table.
DATA: lo_header TYPE REF TO cl_salv_form_layout_grid,
lo_h_label TYPE REF TO cl_salv_form_label,
lv_text TYPE char100.
CLASS lcl_handel_events DEFINITION.
PUBLIC SECTION.
METHODS: user_command FOR EVENT added_function OF
cl_salv_events IMPORTING e_salv_function.
ENDCLASS.
DATA: event_handler TYPE REF TO lcl_handel_events.
"Lcal Class To Process Data.
CLASS lcl_data DEFINITION CREATE PUBLIC FINAL.
PUBLIC SECTION.
CLASS-METHODS:
get_data RETURNING VALUE(rt_data) TYPE tt_outtb,
process_data IMPORTING it_data TYPE tt_outtb,
display.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Include ZMMR001_SALV_SEL
*&---------------------------------------------------------------------*
"Selection Screen.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS so_empno FOR z01m_empmst-empno NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN : END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& Include ZMMR001_SALV_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Class (Implementation) lc_data
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
CLASS lcl_data IMPLEMENTATION.
METHOD get_data.
SELECT *
FROM z01m_empmst
INTO TABLE @RT_data
WHERE empno IN @SO_empno.
IF sy-subrc = 0.
SORT rt_data BY empno empnm.
DELETE ADJACENT DUPLICATES FROM rt_data COMPARING empno.
DELETE rt_data WHERE empno IS INITIAL.
ENDIF.
ENDMETHOD.
METHOD process_data.
gt_emp = it_data.
ENDMETHOD.
METHOD display.
*Create alv object.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_gr_alv
CHANGING
t_table = gt_emp.
CATCH cx_salv_msg.
ENDTRY.
lo_gr_alv->set_screen_status( pfstatus = 'ZTEST_PF'
report = sy-repid
set_functions = lo_gr_alv->c_functions_all
).
* Show all alv functions.
lo_gr_functions = lo_gr_alv->get_functions( ).
lo_gr_functions->set_all( abap_true ).
* lo_gr_functions->set_aggregation_average( abap_true ).
* lo_gr_functions->set_abc_analysis( abap_true ).
lo_gr_functions->set_export_wordprocessor( abap_true ).
* Fit the columns
lo_columns = lo_gr_alv->get_columns( ).
lo_columns->set_optimize( abap_true ).
** Code to remove coloumn or change text for reference
* try.
* Lo_column ?= lo_columns->get_column( 'mandt' ).
* Lo_column->set_visible( if_salv_c_bool_sap=>false ).
** Lo_column->set_long_text( 'mytitle' ).
** Lo_column->set_medium_text( 'mytitle' ).
** Lo_column->set_short_text( 'mytitle' ).
* Catch cx_salv_not_found.
* Catch cx_salv_existing.
* Catch cx_salv_data_error.
* Endtry.
* header object
CREATE OBJECT lo_header.
* Information in bold
lo_h_label = lo_header->create_label( row = 1 column = 1 ).
lo_h_label->set_text( gv_text ).
* Set the top of list using the header.
lo_gr_alv->set_top_of_list( lo_header ).
* Set the top of list using the header for print.
lo_gr_alv->set_top_of_list_print( lo_header ).
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key.
lr_layout = lo_gr_alv->get_layout( ).
ls_key-report = sy-repid.
* If uv_change_mode = abap_true.
ls_key-handle = 'h0ch'.
lr_layout->set_key( ls_key ).
lr_layout->set_default( abap_true ).
lr_layout->set_save_restriction( '3' ).
"Events
gr_events = lo_gr_alv->get_event( ).
CREATE OBJECT event_handler.
SET HANDLER event_handler->user_command FOR gr_events.
* Display alv
lo_gr_alv->display( ).
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class (Implementation) lcl_handel_events
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
CLASS lcl_handel_events IMPLEMENTATION.
METHOD user_command.
CASE e_salv_function.
WHEN 'ZREFRESH'.
lo_gr_alv->refresh( refresh_mode = if_salv_c_refresh=>full ).
lo_gr_alv->get_selections( ).
lo_gr_alv->refresh( ).
ENDCASE.
ENDMETHOD.
ENDCLASS.
The content of the internal table rows are not being modified in your program. As far as I know, the ALV refresh works when the internal table data has changed.
I don't know if what you want is a refresh at database level. In that case, you have to execute your SELECT query again to retrieve changes at DDBB level.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.