Warning: Undefined variable $saptab in /customers/b/9/9/trailsap.com/httpd.www/page/php/abapcoding.php on line 137 Warning: Undefined array key "raw" in /customers/b/9/9/trailsap.com/httpd.www/page/php/abapcoding.php on line 138 Warning: Undefined variable $val in /customers/b/9/9/trailsap.com/httpd.www/page/php/abapcoding.php on line 68 salv report logo

SAP SALV REPORT LOGO

Warning: Undefined variable $intro in /customers/b/9/9/trailsap.com/httpd.www/page/php/abapcoding.php on line 73
*& Report ZSAP_SALV_REPORT_LOGO
 *&---------------------------------------------------------------------*
 
 *---------------------------------------------------------------------------------*
 * SAP SALV Report with header logo image footer events and default variant
 *---------------------------------------------------------------------------------*
 * Description:
 *---------------------------------------------------------------------------------*
 * This further builds on the basic SAP SALV and implements additional
 * functionality to the ALV report:
 * Display header
 * Display footer
 * Add images to header on left
 * Add logo to header on right without effecting the header text
 * Save and retrieve variant
 * Set default variant
 * Implement events double click, hotspot click
 *---------------------------------------------------------------------------------*
 REPORT zsap_salv_report_logo.
 
 PARAMETERS: p_param TYPE ekko-ebeln. "Example report parameter
 SELECTION-SCREEN SKIP.
 SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-f03.
 PARAMETERS:     p_layout TYPE disvariant-variant.           "ALV Variant
 SELECTION-SCREEN END OF BLOCK b3.
 
 
 *Data Declaration
 *---------------------------------------------------------------------------------*
 TYPES: BEGIN OF t_report_cust,
   ebeln TYPE ekpo-ebeln,
   ebelp TYPE ekpo-ebelp,
   statu TYPE ekpo-statu,
   aedat TYPE ekpo-aedat,
   matnr TYPE ekpo-matnr,
   menge TYPE ekpo-menge,
   meins TYPE ekpo-meins,
   netpr TYPE ekpo-netpr,
   peinh TYPE ekpo-peinh,
   line_color  TYPE lvc_t_scol,
  END OF t_report_cust.
 
 TYPES: BEGIN OF t_report.
         INCLUDE STRUCTURE ekpo.
 TYPES:        line_color TYPE lvc_t_scol,
 END OF t_report.
 DATA: gd_heading1 TYPE string VALUE 'SALV heading value1'.
 DATA: gd_heading2 TYPE string VALUE 'SALV heading value2'.
 DATA: lt_s_color TYPE lvc_t_scol.
 DATA: ls_s_color TYPE lvc_s_scol.
 DATA: it_report TYPE STANDARD TABLE OF t_report_cust INITIAL SIZE 0,
       wa_report LIKE LINE OF it_report.
 DATA alv_table    TYPE REF TO cl_salv_table.
 DATA alv_columns TYPE REF TO cl_salv_columns_table.
 DATA single_column  TYPE REF TO cl_salv_column.
 
 
 *---------------------------------------------------------------------------------*
 *       CLASS lcl_handle_events DEFINITION
 *---------------------------------------------------------------------------------*
 * Define a local class for handling events of cl_salv_table
 *---------------------------------------------------------------------------------*
 CLASS lcl_handle_events DEFINITION.
   PUBLIC SECTION.
     METHODS:
       on_user_command FOR EVENT added_function OF cl_salv_events
         IMPORTING e_salv_function,
 
       on_before_salv_function FOR EVENT before_salv_function OF cl_salv_events
         IMPORTING e_salv_function,
 
       on_after_salv_function FOR EVENT after_salv_function OF cl_salv_events
         IMPORTING e_salv_function,
 
       on_double_click FOR EVENT double_click OF cl_salv_events_table
         IMPORTING row column,
 
       on_link_click FOR EVENT link_click OF cl_salv_events_table
         IMPORTING row column.
 ENDCLASS.                    "lcl_handle_events DEFINITION
 
 
 *---------------------------------------------------------------------------------*
 *       CLASS lcl_handle_events IMPLEMENTATION
 *---------------------------------------------------------------------------------*
 * Implement the events for handling the events of cl_salv_table
 *---------------------------------------------------------------------------------*
 CLASS lcl_handle_events IMPLEMENTATION.
   METHOD on_user_command.
 *    perform show_function_info using e_salv_function 'user command event'.
   ENDMETHOD.                    "on_user_command
 
   METHOD on_before_salv_function.
 *    perform show_function_info using e_salv_function 'before salv function event'.
   ENDMETHOD.                    "on_before_salv_function
 
   METHOD on_after_salv_function.
 *    perform show_function_info using e_salv_function 'after salv function event'.
   ENDMETHOD.                    "on_after_salv_function
 
   METHOD on_double_click.
     PERFORM show_cell_info USING row column 'double click event'.
   ENDMETHOD.                    "on_double_click
 
   METHOD on_link_click.
     PERFORM show_cell_info USING row column 'double click event'.
   ENDMETHOD.                    "on_single_click
 ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
 DATA: gr_events TYPE REF TO lcl_handle_events.
 
 
 *---------------------------------------------------------------------------------*
 * AT SELECTION-SCREEN ON VALUE-REQUEST                                 *
 *---------------------------------------------------------------------------------*
 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
   PERFORM f4_layouts USING if_salv_c_layout=>restrict_none
                      CHANGING p_layout.
 
 
 *---------------------------------------------------------------------------------*
 * INITIALIZATION                                                       *
 *---------------------------------------------------------------------------------*
 INITIALIZATION.
   PERFORM get_default_layout USING    if_salv_c_layout=>restrict_none
                              CHANGING p_layout.
 
 
 ************************************************************************
 * START-OF-SELECTION
 START-OF-SELECTION.
   PERFORM data_retrieval.
 
 
 ************************************************************************
 * END-OF-SELECTION
 END-OF-SELECTION.
 
   IF NOT it_report[] IS INITIAL.
     PERFORM display_settings.
     PERFORM display_salv_report.
   ELSE.
     MESSAGE i006(zzz) WITH 'Not data Found'.
   ENDIF.
 
 
 *&---------------------------------------------------------------------*

*& Form get default layout

*&---------------------------------------------------------------------* * Get Default Layout * cl_salv_layout provides a method for retieving the valid default * layout. It is also possible to use the static class * cl_salv_layout_service. The rules for determinig the valid * default Layout is as follows: * (1) Check if user-dependant default layout exists if yes then * this layout is loaded * (2) Check if user-independant standard layout exists if yes then * this layout is loaded * (3) Check if user-independant SAP standard layout exists if yes * then this layout is loaded *---------------------------------------------------------------------------------* FORM get_default_layout USING i_restrict TYPE salv_de_layout_restriction CHANGING c_layout TYPE disvariant-variant. DATA: ls_layout TYPE salv_s_layout_info, ls_key TYPE salv_s_layout_key. ls_key-report = sy-repid. ls_layout = cl_salv_layout_service=>get_default_layout( s_key = ls_key restrict = i_restrict ). c_layout = ls_layout-layout. ENDFORM. " get_default_layout *&---------------------------------------------------------------------*

*& FORM data retrieval.

*&---------------------------------------------------------------------* FORM data_retrieval. SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh UP TO 10 ROWS FROM ekpo INTO CORRESPONDING FIELDS OF TABLE it_report. LOOP AT it_report ASSIGNING FIELD-SYMBOL(). ls_s_color-fname = 'EBELN'. ls_s_color-color-col = 5. ls_s_color-color-int = 1. ls_s_color-color-inv = 0. APPEND ls_s_color TO -line_color. ENDLOOP. ENDFORM. " DATA_RETRIEVAL *&---------------------------------------------------------------------*

*& FORM display settings.

*&---------------------------------------------------------------------* FORM display_settings. DATA: err_message TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = alv_table CHANGING t_table = it_report ). alv_columns = alv_table->get_columns( ). alv_columns->set_optimize( 'X' ). "optimise colums of SALV grid alv_columns->set_color_column( 'LINE_COLOR' ). "set line colour of SALV report PERFORM build_salv_layout. PERFORM salv_sort_fields. PERFORM build_fieldcatalog. PERFORM build_toolbar. PERFORM hide_columns. PERFORM salv_display_settings. PERFORM salv_report_header. PERFORM salv_report_footer. PERFORM salv_report_events. PERFORM set_hotspot_fields. CATCH cx_salv_msg INTO err_message. * Add error processing ENDTRY. ENDFORM. *&---------------------------------------------------------------------*

*& FORM display alv report.

*&---------------------------------------------------------------------* FORM display_salv_report. alv_table->display( ). ENDFORM. *&---------------------------------------------------------------------*

*& FORM build layout.

*&---------------------------------------------------------------------* FORM build_salv_layout. DATA: layout TYPE REF TO cl_salv_layout. DATA: layout_key TYPE salv_s_layout_key. layout = alv_table->get_layout( ). layout_key-report = sy-repid. layout->set_key( layout_key ). layout->set_save_restriction( if_salv_c_layout=>restrict_none ). layout->set_initial_layout( p_layout ). layout->set_default( 'X' ). ENDFORM. "BUILD_LAYOUT *&---------------------------------------------------------------------*

*& FORM hide columns.

*&---------------------------------------------------------------------* * Code to hide any columns you do not wont to be shown by default, * these fields can be added manually by the user using the standard * SALV report functionality *&---------------------------------------------------------------------* FORM hide_columns. DATA: err_notfound TYPE REF TO cx_salv_not_found. TRY. single_column = alv_columns->get_column( 'KEY' ). single_column->set_visible( if_salv_c_bool_sap=>false ). CATCH cx_salv_not_found INTO err_notfound. * Add error processing ENDTRY. ENDFORM. *&---------------------------------------------------------------------*

*& FORM build fieldcatalog.

*&---------------------------------------------------------------------* * Your ALV report should get texts from the internal table used but you * can overwrite those values within here if you require. The code * below contains a few examples *&---------------------------------------------------------------------* FORM build_fieldcatalog. DATA: err_notfound TYPE REF TO cx_salv_not_found. TRY. single_column = alv_columns->get_column( 'EBELN' ). single_column->set_short_text( 'POrder' ). "Note: Will cause syntax error if text is too long single_column->set_medium_text( 'Purchase Order' ). single_column->set_long_text( 'Purchase Order' ). single_column->set_output_length( '15' ). "Force column to be wider to accomodate heading single_column = alv_columns->get_column( 'NETPR' ). single_column->set_short_text( 'Net Price' ). single_column->set_medium_text( 'Net Price' ). single_column->set_long_text( 'Net Price' ). CATCH cx_salv_not_found INTO err_notfound. * Add error processing ENDTRY. ENDFORM. *&---------------------------------------------------------------------*

*& FORM build toolbar.

*&---------------------------------------------------------------------* * The code below simply displays all available functions but you can * restrict this if you require *&---------------------------------------------------------------------* FORM build_toolbar. DATA: toolbar_functions TYPE REF TO cl_salv_functions_list. toolbar_functions = alv_table->get_functions( ). toolbar_functions->set_all( ). ENDFORM. *&---------------------------------------------------------------------*

*& FORM report settings.

*&---------------------------------------------------------------------* FORM salv_display_settings. DATA: report_settings TYPE REF TO cl_salv_display_settings. report_settings = alv_table->get_display_settings( ). report_settings->set_striped_pattern( if_salv_c_bool_sap=>true ). report_settings->set_list_header( 'SALV Report Title' ). ENDFORM. *&---------------------------------------------------------------------*

*& Form f4 layouts

*&---------------------------------------------------------------------* FORM f4_layouts USING i_restrict TYPE salv_de_layout_restriction CHANGING c_layout TYPE disvariant-variant. DATA: ls_layout TYPE salv_s_layout_info, ls_key TYPE salv_s_layout_key. ls_key-report = sy-repid. ls_layout = cl_salv_layout_service=>f4_layouts( s_key = ls_key restrict = i_restrict ). c_layout = ls_layout-layout. ENDFORM. *&---------------------------------------------------------------------*

*& Form REPORT HEADER

*&---------------------------------------------------------------------* * Add header to SAP SALV table report *---------------------------------------------------------------------------------* FORM salv_report_header . DATA: header TYPE REF TO cl_salv_form_layout_grid, label TYPE REF TO cl_salv_form_label, flow TYPE REF TO cl_salv_form_layout_flow, image TYPE REF TO cl_salv_form_picture, logo TYPE REF TO cl_salv_form_layout_logo. DATA: ld_txt TYPE string. DATA tz TYPE ttzz-tzone. CREATE OBJECT header. * Add text to SALAV report label = header->create_label( row = 1 column = 1 ). label->set_text( 'SALV Report heading' ). label = header->create_label( row = 1 column = 1 ). label->set_text( 'SALV fixed header text:' ). label = header->create_label( row = 1 column = 2 ). label->set_text( gd_heading1 ). ** Add Blank Line to SALV table report label = header->create_label( row = 2 column = 1 ). label->set_text( ' ' ). * Add date text to SALV_TABLE report label = header->create_label( row = 2 column = 1 ). label->set_text( 'Date:' ). label = header->create_label( row = 2 column = 2 ). label->set_text( sy-datum ). label = header->create_label( row = 5 column = 1 ). label->set_text( 'SALV Heading 2:' ). label = header->create_label( row = 5 column = 2 ). label->set_text( gd_heading2 ). * Add picture to SALV report CREATE OBJECT image EXPORTING picture_id = 'ENJOYSAP_LOGO'. CALL METHOD header->set_element EXPORTING row = 1 column = 6 r_element = image. ** Set header for display ** alv_table->set_top_of_list( header ). ** Or Add Logo to header and then display heaer and logo to SALV report CREATE OBJECT logo. logo->set_left_content( header ). logo->set_right_logo( 'ENJOYSAP_LOGO' ). * Set element top_of_list alv_table->set_top_of_list( logo ). * Set set header for Print alv_table->set_top_of_list_print( header ). ENDFORM. *&---------------------------------------------------------------------*

*& Form REPORT FOOTER

*&---------------------------------------------------------------------* * Create footer for SAP SALV table report *---------------------------------------------------------------------------------* FORM salv_report_footer . DATA: footer TYPE REF TO cl_salv_form_layout_grid, label TYPE REF TO cl_salv_form_label, flow TYPE REF TO cl_salv_form_layout_flow. DATA: ld_deploc(40) TYPE c, ld_txt TYPE string, ld_daycode TYPE scal-indicator, ld_day TYPE string. DATA tz TYPE ttzz-tzone. DATA: wa_t247 TYPE t247. CREATE OBJECT footer. * Add date as text to SALV report footer label = footer->create_label( row = 1 column = 1 ). SELECT SINGLE * FROM t247 INTO wa_t247 WHERE spras EQ sy-langu AND mnr EQ sy-datum+4(2). CALL FUNCTION 'DATE_COMPUTE_DAY' EXPORTING date = sy-datum IMPORTING day = ld_daycode. * Convert date into Day text i.e. Monday... CASE ld_daycode. WHEN 1. ld_day = 'Monday'. WHEN 2. ld_day = 'Tuesday'. WHEN 3. ld_day = 'Wednesday'. WHEN 4. ld_day = 'Thursday'. WHEN 5. ld_day = 'Friday'. WHEN 6. ld_day = 'Saturday'. WHEN 7. ld_day = 'Sunday'. ENDCASE. * Build custome date layout using inline string concatenate ld_txt = |{ ld_day }, { wa_t247-ltx(3) } { sy-datum+6(2) } { sy-datum(4) } { sy-uzeit(2) }:{ sy-uzeit+2(2) }|. label->set_text( ld_txt ). alv_table->set_end_of_list( footer ). ENDFORM. *&---------------------------------------------------------------------*

*& Form REPORT SORT

*&---------------------------------------------------------------------* * Add default sort fields to ALV report, this will also group * row togther if values are the same *---------------------------------------------------------------------------------* FORM salv_sort_fields. DATA: sort TYPE REF TO cl_salv_sorts. sort = alv_table->get_sorts( ). sort->add_sort( 'EBELN' ). ENDFORM. *&--------------------------------------------------------------------*

*& Form show cell info

*&--------------------------------------------------------------------* * Used to demonstrate event functionality to Show information * of the field that has been clicked on. also demonstrates how * to call sap tcode from ALV click *---------------------------------------------------------------------------------* FORM show_cell_info USING i_row TYPE i i_column TYPE lvc_fname i_text TYPE string. DATA: l_row_string TYPE string, l_col_string TYPE string, l_row TYPE char128. WRITE i_row TO l_row LEFT-JUSTIFIED. CONCATENATE text-i02 l_row INTO l_row_string SEPARATED BY space. CONCATENATE text-i03 i_column INTO l_col_string SEPARATED BY space. MESSAGE i000(0k) WITH i_text l_row_string l_col_string. * Set purchase order clicked and and call transaction code to display PO details IF i_column EQ 'EBELN'. READ TABLE it_report INDEX i_row ASSIGNING FIELD-SYMBOL(). SET PARAMETER ID 'BES' FIELD -ebeln. CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. ENDIF. ENDFORM. " show_cell_info " call_tcode *&---------------------------------------------------------------------*

*& Form REPORT EVENTS

*&---------------------------------------------------------------------* * Setup SALV report events so that they are triggered from ALV report *---------------------------------------------------------------------------------* FORM salv_report_events . *ยง6 register to the events of cl_salv_table DATA: lr_events TYPE REF TO cl_salv_events_table. lr_events = alv_table->get_event( ). CREATE OBJECT gr_events. *event USER_COMMAND SET HANDLER gr_events->on_user_command FOR lr_events. *event BEFORE_SALV_FUNCTION SET HANDLER gr_events->on_before_salv_function FOR lr_events. *event AFTER_SALV_FUNCTION SET HANDLER gr_events->on_after_salv_function FOR lr_events. *event DOUBLE_CLICK SET HANDLER gr_events->on_double_click FOR lr_events. *event LINK_CLICK SET HANDLER gr_events->on_link_click FOR lr_events. ENDFORM. *&---------------------------------------------------------------------*

*& Form REPORT HOTSPOT

*&---------------------------------------------------------------------* * text *---------------------------------------------------------------------------------* FORM set_hotspot_fields . *...HotSpot DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table, lo_col_tab TYPE REF TO cl_salv_column_table. * get Columns object lo_cols_tab = alv_table->get_columns( ). * TRY. lo_col_tab ?= lo_cols_tab->get_column( 'EBELN' ). CATCH cx_salv_not_found. ENDTRY. * Set the HotSpot for VBELN Column TRY. CALL METHOD lo_col_tab->set_cell_type EXPORTING value = if_salv_c_cell_type=>hotspot. . CATCH cx_salv_data_error . ENDTRY. ENDFORM.
Warning: Undefined variable $saptab in /customers/b/9/9/trailsap.com/httpd.www/page/php/abapcoding.php on line 209

Related Articles