The following program creates and displays ALV using CL_SALV_TABLE class.
*&---------------------------------------------------------------------* *& Report ZDEMO11 *& *&---------------------------------------------------------------------* *& *& ALV Using CL_SALV_TABLE *&---------------------------------------------------------------------* REPORT zdemo11. TYPES:BEGIN OF gty_emp, id TYPE char10, name TYPE char10, END OF gty_emp. DATA: gt_emp TYPE TABLE OF gty_emp, gv_data TYPE REF TO data . FIELD-SYMBOLS: <fs_emp> LIKE LINE OF gt_emp. START-OF-SELECTION. REFRESH: gt_emp. CLEAR: gv_data. PERFORM populate_record. PERFORM create_display_alv. *&---------------------------------------------------------------------* *& Form POPULATE_RECORD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM populate_record . CREATE DATA gv_data LIKE LINE OF gt_emp. ASSIGN gv_data->* TO <fs_emp>. <fs_emp>-id = '1'. <fs_emp>-name = 'A'. APPEND <fs_emp> TO gt_emp. <fs_emp>-id = '2'. <fs_emp>-name = 'B'. APPEND <fs_emp> TO gt_emp. ENDFORM. *----------------------------------------------------------------------* * CLASS cl_event_handler DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS on_added_function " ADDED_FUNCTION FOR USER_COMMAND FOR EVENT if_salv_events_functions~added_function OF cl_salv_events_table IMPORTING e_salv_function. ENDCLASS. "cl_event_handler DEFINITION *----------------------------------------------------------------------* * CLASS cl_event_handler IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cl_event_handler IMPLEMENTATION. METHOD on_added_function. * ADD USER COMMAND HERE: FOR EXAMPLE IF THERE IS AN EXPORT BUTTON FOR XLS * YOU CAN WRITE THE CODE LIKE THIS: * IF e_salv_function EQ '&XLS'. "&XLS IS THE BUTTON FUNCTION CODE * PERFORM export_xls. "WRITE ALL THE FUNCTIONALITY IN THE PERFORM * ENDIF. ENDMETHOD. "on_added_function ENDCLASS. "cl_event_handler IMPLEMENTATION *&---------------------------------------------------------------------* *& Form CREATE_DISPLAY_ALV *&---------------------------------------------------------------------* * CREATING AND DISPLAYING ALV (NON-EDITABLE) *----------------------------------------------------------------------* FORM create_display_alv . DATA: lv_col_msg TYPE REF TO cx_salv_not_found, lv_alv_msg TYPE REF TO cx_salv_msg, lo_alv TYPE REF TO cl_salv_table, lo_columns TYPE REF TO cl_salv_columns_table, lo_column TYPE REF TO cl_salv_column, lo_events TYPE REF TO cl_salv_events_table . TRY . CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = lo_alv CHANGING t_table = gt_emp. ********************************************************************** lo_events = lo_alv->get_event( ). SET HANDLER cl_event_handler=>on_added_function FOR lo_events. ********************************************************************** *********************** SETTING THE FIELDCATALOG *********************** TRY . lo_columns = lo_alv->get_columns( ). lo_columns->set_optimize( ). lo_column = lo_columns->get_column( 'ID' ). "COLUMN NAME lo_column->set_short_text( 'ID' ). "SHORT TEXT lo_column->set_medium_text( 'EMP. ID' ). "MEDIUM TEXT lo_column->set_long_text( 'Employee ID' ). "LONG TEXT lo_column = lo_columns->get_column( 'NAME' ). "COLUMN NAME lo_column->set_short_text( 'Name' ). "SHORT TEXT lo_column->set_medium_text( 'EMP. Name' ). "MEDIUM TEXT lo_column->set_long_text( 'Employee Name' ). "LONG TEXT CATCH cx_salv_not_found INTO lv_col_msg. * IMPLEMENT ERROR HANDLING MECHANISM ENDTRY. ********************** #SETTING THE FIELDCATALOG *********************** ************************* SETTING PF_STATUS *************************** TRY. CALL METHOD lo_alv->set_screen_status EXPORTING report = sy-repid pfstatus = 'PF_STATUS' set_functions = lo_alv->c_functions_all. ENDTRY. ************************* #SETTING PF_STATUS ************************** lo_alv->display( ). CATCH cx_salv_msg INTO lv_alv_msg. * IMPLEMENT ERROR HANDLING MECHANISM ENDTRY. ENDFORM. " DISPLAY_ALV
For a detail understanding, you can visit the following links:
http://www.kerum.pl/infodepot/00007
http://abapmentor.expertise-team.com/post/display-alv-list-easily-in-abap-using-cl-salv-table-part-ii-enable-layout-settings.aspx
http://abapmentor.expertise-team.com/post/display-alv-list-easily-in-abap-using-cl-salv-table-part-v-set-toolbar.aspx
Hi, excellent!! thanks!
ReplyDeletecasino online【WG】online slot game
ReplyDelete【WG98.vip】⚡,casino 우리카지노 마틴 online,casino 코인카지노 online,casino online,casino online,casino 카지노사이트 online,casino online,casino online,casino online,casino online,casino online,casino online,casino online,casino online,casino