Adding Explicit Enhancement To Custom Program
Adding Explicit Enhancement To Custom Program
Introduction:
Enhancement Framework is the new paradigm to bring all enhancement techniques under one roof. It
can also be switched using Switch Framework. The following are different enhancement technologies
available under this framework.
Source Code Enhancement
Function Group Enhancement
Class Enhancement
Kernel-BADI Enhancement
Source Code enhancement
Whenever enhancement needs to be incorporated directly into the ABAP source code, this technology
shall be provided. Implementing this technology is also called as Source Code Plug-In. There are two
types of Source Code enhancements possible.
Implicit enhancement option
Explicit enhancement option
Explicit enhancement option
As implicit enhancements are predefined enhancements provided by SAP in the source code, the explicit
enhancements can be implemented by the customers or partners.
There are two types of Explicit Enhancement options available. For this, we now have two new ABAP
statements, viz.
1.
Enhancement
point
(Syntax
ENHANCEMENT-POINT)
2. Enhancement section (Syntax - ENHANCEMENT-SECTION)
Enhancement section is used to replace a set of code or statements with the customer (custom code). In
this technique the original source code does not get executed but, the customer implementation (custom
code) gets executed.
Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere
except some areas where SAP would allow (program allows).
STEP 1: Create a package in transaction SE80 (Object navigator) Name YDEV
And save it into created package. Observe the enhancement spot created under the 'Enhancement
Spots' folder.
STEP 3: 'Right Click' the spot created and 'Implement' it (Create an Implementation).
STEP 4: Now, we need to 'Activate' the enhancement spot. In addition with the Enhancement spot the
'Enhancement Implementation' will get activated.
STEP 5: Here we are applying enhancements to a CUSTOM program not a standard program to
demonstrate the functionality. So we create a simple program 'YDEV_CODE' (say) it is retrieving records
from the database table 'VBAK' (Sales Document Header) and displaying a few records.
Now, if the customer wants to replace the set of logic with his own logic (say) like retrieving records from
database table 'VBAP' (Sales Document Item) and then display a few records, he/she will create an
enhancement section which goes like,
Create a program YDEV_CODE.
OUTPUT
STEP 6: Right click the area which is appropriate to apply the enhancement
Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere
except some areas where SAP would allow (program allows).
Now, in the 'Create Enhancement Option' fill in the details, here fill the name under 'Enhancementsection' only. Then fill in the Enhancement Spot Implementation Name which we created earlier.
Note - Make sure that the code which has to be replaced is within the 'ENHANCEMENT-SECTION...' and
'END-ENHANCEMENT-SECTION'.
STEP 7: Now to include the custom code in the program which will replace the original code, enable the
'Enhancement Mode' by clicking on the 'Spiral' button.
Place the cursor on the 'Enhancement-section' and navigate to 'Edit' 'Enhancement Operations'
'Create Implementation'.
Fill in the details for the 'Create Enhancement Implementation' dialog. Click on 'Create' button for the
'Select or Create Enhancement Implementation' dialog.
STEP 8: Now, write the code within the 'ENHANCEMENT' and 'ENDENHANCEMENT' statements as the
replacement code.
STEP 9: Don't forget to 'Activate' the enhancement Switch the 'Enhancement' mode OFF and
'Activate' the entire program.
After Enhancement:
Summary:
1. Here we deals with the enhancement of a 'Z' program it is possible to 'CREATE' an
'ENHANCEMENT-SECTION'. But, in case of a 'STANDARD SAP' program there are certain
places (provided by SAP) like 'ENHANCEMENT-POINT...' and 'ENHANCEMENT-SECTION...'
where we can create implementations based on customers business functionality.
2. There can be only one and only one 'ACTIVE' implementation for an 'ENHANCEMENTSECTION'.
Source Code:
*&---------------------------------------------------------------------*
*& Report YDEV_CODE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YDEV_CODE.
TABLES : VBAK, VBAP.
DATA : IT_VBAK TYPE STANDARD TABLE OF VBAK INITIAL SIZE 0,
WA_VBAK TYPE VBAK,
IT_VBAP TYPE STANDARD TABLE OF VBAP INITIAL SIZE 0,
WA_VBAP TYPE VBAP.
INITIALIZATION.
REFRESH : IT_VBAK,
IT_VBAP.
CLEAR : WA_VBAK,
WA_VBAP.
START-OF-SELECTION.
Features
Emphasis
Emphasis on tasks
Modularization
Data security
Extensibility
Any program
Stored In
Created By
Namespace
Local Classes
Every class will have two sections.
(1) Definition. (2) Implementation
Definition: This section is used to declare the components of the classes such as attributes, methods,
events .They are enclosed in the ABAP statements CLASS ... ENDCLASS.
CLASS
<class>
DEFINITION.
...
ENDCLASS.
Implementation: This section of a class contains the implementation of all methods of the class. The
implementation part of a local class is a processing block.
CLASS
<class>
IMPLEMENTATION.
...
ENDCLASS.
Structure of a Class
The following statements define the structure of a class:
1. A class contains components
2. Each component is assigned to a visibility section
3. Classes implement methods
1. Components of a Class are as follow:
Attributes:- Any data,constants,types declared within a class form the attribute of the class.
Methods:- Block of code, providing some functionality offered by the class. Can be compared to
function modules. They can access all of the attributes of a class.
Methods are defined in the definition part of a class and implement it in the implementation part using
the following processing block:
METHOD <meth>.
...
ENDMETHOD.
Methods are called using the CALL METHOD statement.
Events:- A mechanism set within a class which can help a class to trigger methods of other class.
Interfaces:- Interfaces are independent structures that you can implement in a class to extend the
scope of that class.
Instance and Static Components:
Instance components exist separately in each instance (object) of the class and are referred using
instance component selector using .
Static components only exist once per class and are valid for all instances of the class. They are
declared with the CLASS- keywords
Static components can be used without even creating an instance of the class and are referred to
using static component selector => .
2. Visibility of Components
Each class component has a visibility. In ABAP Objects the whole class definition is separated into three
visibility sections: PUBLIC, PROTECTED, and PRIVATE.
Data declared in public section can be accessed by the class itself, by its subclasses as well as by
other users outside the class.
Data declared in the protected section can be accessed by the class itself, and also by its subclasses
but not by external users outside the class.
Data declared in the private section can be accessed by the class only, but not by its subclasses and
by external users outside the class.
CLASS
<class>
PUBLIC
PROTECTED
PRIVATE
DEFINITION.
SECTION.
...
SECTION.
...
SECTION.
...
ENDCLASS.
We shall see an example on Visibility of Components once we become familiar with attributes of ABAP
Objects.
Polymorphism: Methods of same name behave differently in different classes. Identical (identicallynamed) methods behave differently in different classes. Object-oriented programming contains
constructions called interfaces. They enable you to address methods with the same name in different
objects. Although the form of address is always the same, the implementation of the method is specific to
a particular class.
***********************************************************************************
FUNCTION ZFM_SEND_MAIL_MULT_TABS.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
*" EXPORTING
*"
*"----------------------------------------------------------------------
*"----------------------------------------------------------------------
*"----------------------------------------------------------------------
DATA: l_ixml
l_renderer
l_document
DATA: l_element_root
ns_attribute
r_data
l_value
TYPE string,
l_type
TYPE string,
l_text(100)
TYPE c,
r_styles
r_style
r_style1
r_style2
r_style3
r_style4
r_format
r_border
num_rows
TYPE i.
DATA: l_xml_table
wa_xml
TYPE xml_line,
l_xml_size
TYPE i,
l_rc
TYPE i.
TYPE c,
d_number(20) type c.
lv_date = sy-datum - 1.
* Styles
***
* Style for tablename
r_style2 = l_document->create_simple_element( name = 'Style' parent =
r_styles ).
******************
* Worksheet(First tab)
r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent
= l_element_root ).
r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Commodity
Impact' ).
* Table
r_table = l_document->create_simple_element( name = 'Table' parent =
r_worksheet ).
r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ).
r_table->set_attribute_ns( name = 'FullRows'
* Column Formatting
r_column = l_document->create_simple_element( name = 'Column' parent =
r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).
* Blank Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).
*Title of table
* fy commodity
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'FY
Commodity Spend ($MM)' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* change vs jan
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
CONCATENATE 'Change vs' IW_FCYCL_P into l_value SEPARATED BY space.
* Data Table
LOOP AT T_tab2 INTO wa_tab2.
* commodity
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab2-/BIC/GPU_FDUOM1.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
WA_INPUT = wa_tab2-FY_COMM_SPND.
EXPORTING
INPUT
= WA_INPUT
IMPORTING
OUTPUT
= WA_OUTPUT.
* fy
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = WA_OUTPUT.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
WA_INPUT = wa_tab2-FIGCY_PREVMNTH.
EXPORTING
INPUT
= WA_INPUT
IMPORTING
OUTPUT
= WA_OUTPUT.
* changes vs jan
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_output.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
clear wa_tab2.
ENDLOOP.
**************
* Table
r_table = l_document->create_simple_element( name = 'Table' parent =
r_worksheet ).
r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ).
r_table->set_attribute_ns( name = 'FullRows'
* Column Formatting
r_column = l_document->create_simple_element( name = 'Column' parent =
r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).
* Blank Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).
***********
* 2 Blank rows
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).
*Supplier.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'SUPPLIER'
parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* SUBREGION
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'SUBREGION' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* MATERIAL VOLUME
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'MATERIAL
VOLUME' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* COMMODITY
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'COMMODITY' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* FY_EXPOSURE
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'FY_EXPOSURE' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* UOM
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'UOM'
parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* * CURRENCY
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'CURRENCY' parent = r_cell ).
* COMMODITY SPEND
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'COMMODITY SPEND' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* CHANGE VS PREVIOUS
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'CHANGE
VS PREVIOUS' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* CREATION DATE(MONTH/YEAR)
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'CREATION
DATE(MONTH/YEAR)' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* FIG CYCLE
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
* Data Table
LOOP AT T_tab1 INTO wa_tab1.
* supplier
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-/BIC/GPUCNTCT.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
* sub region
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-SUBREGTXTLG.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
* material volume
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-/BIC/GPUFSEJUL.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
* commodity
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
* Fy_exposure
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-FY_EXPOSURE.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
" Cell format
*UOM
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-/BIC/GPUUOM.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* currency
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-CURRENCY.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
WA_INPUT = wa_tab1-/BIC/GPUCSDJUL.
EXPORTING
INPUT
= WA_INPUT
IMPORTING
OUTPUT
= WA_OUTPUT.
* commodity spend
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = WA_OUTPUT.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
WA_INPUT = wa_tab1-CHNG_VS_PREV.
EXPORTING
INPUT
= WA_INPUT
IMPORTING
OUTPUT
= WA_OUTPUT.
* change vs prev
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = WA_OUTPUT.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* creation date
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-/BIC/GPUCOCDAT_1.
r_data = l_document->create_simple_element( name = 'Data' value = l_value
parent = r_cell ).
" Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Fig cycle
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_tab1-/BIC/GPU_FCYCL.
clear wa_tab1.
ENDLOOP.
DATA: objtxt
* Target Recipent
CLEAR reclist.
reclist-receiver = I_MAILID.
reclist-rec_type = 'U'.
RECLIST-EXPRESS = 'X'.
APPEND reclist.
= doc_chng
= 'X'
= 'X'
TABLES
packing_list
object_header
contents_txt
contents_hex
receivers
= objpack
= objhead
= objtxt
= objbin
= reclist
EXCEPTIONS
too_many_receivers
=1
document_not_sent
=2
operation_no_authorization = 4
OTHERS
= 99.
IF sy-subrc EQ 0.
MOVE: text-412 TO ee_return-message,
'I' TO ee_return-type.
ENDIF.
ENDFUNCTION.
---------------------------------------------------------------------------------------------------
The three field catalogs are built and the field catalog names are: I_FIELDCATALOG1,
I_FIELDCATALOG2 and I_FIELDCATALOG3.
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* PF status of the screen
PERFORM sub_pf_status.
* Set the title of report
SET TITLEBAR 'TTL'.
* Display ALV Data
PERFORM sub_display_firstalv USING i_fieldcatalog1
i_orders1.
PERFORM sub_display_secondalv USING i_fieldcatalog2
i_orders2.
PERFORM sub_display_thirdalv USING i_fieldcatalog3
i_invstatus.
* Send email to customers
PERFORM sub_send_mail.
*
ENDMODULE.
*&---------------------------------------------------------------------*
*&
Form sub_pf_status
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM sub_pf_status.
* Local data declaration
DATA: lt_excl TYPE ty_t_excl.
*Set PF status
SET PF-STATUS 'ZSTATUS_0100' EXCLUDING lt_excl.
ENDFORM.
SUB_PF_STATUS
Subroutine to Display First ALV
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_FIRSTALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG1 text
*
-->P_I_ORDERS1 text
*----------------------------------------------------------------------*
FORM sub_display_firstalv USING fp_i_fieldcatalog1 TYPE lvc_t_fcat
fp_i_orders1 TYPE ty_t_orders1.
DATA:
SUB_DISPLAY_FIRSTALV
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_SECONDALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG2 text
*
-->P_I_ORDERS2 text
*----------------------------------------------------------------------*
FORM sub_display_secondalv USING fp_i_fieldcatalog2 TYPE lvc_t_fcat
fp_i_orders2 TYPE ty_t_orders2.
* Local data declaration
DATA: li_layout TYPE lvc_s_layo,
lx_print TYPE lvc_s_prnt.
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM.
SUB_DISPLAY_SECONDALV
SUB_PREPARE_LAYOUT
Subroutine for Report header, which will be created dynamically based on the fields selected by
the User for a User selected report layout.
*&---------------------------------------------------------------------*
*&
Form SUB_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_top_of_page.
* Local data Declaration
DATA: l_text TYPE sdydo_text_element,
l_datel (10) TYPE c,
l_dateh (10) TYPE c.
* Calling the methods for dynamic text
CALL METHOD g_document->add_text
EXPORTING
text
= text-014
sap_emphasis = cl_dd_area=>strong " For bold
sap_fontsize = cl_dd_area=>extra_large.
* Adding Line
CALL METHOD g_document->new_line.
* Adding Line
CALL METHOD g_document->new_line.
* Sold-to customer
IF s_kunnr-high IS NOT INITIAL.
CONCATENATE s_kunnr-low 'to' s_kunnr-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_kunnr-low.
ENDIF.
CALL METHOD g_document->add_text
EXPORTING
text
= text-015
sap_emphasis = cl_dd_area=>strong. For bold.
CALL METHOD g_document->add_gap
EXPORTING
width = '15'.
CALL METHOD g_document->add_text
EXPORTING
text = l_text.
CALL METHOD g_document->new_line.
CLEAR: l_text.
* Change date
* Converting date format
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = s_erdat-low
IMPORTING
date_external = l_datel.
* Converting date format
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = s_erdat-high
IMPORTING
date_external = l_dateh.
IF s_erdat-high IS NOT INITIAL.
CONCATENATE l_datel 'to' l_dateh INTO l_text SEPARATED BY ' '.
ELSE.
l_text = l_datel.
ENDIF.
CALL METHOD g_document->add_text
EXPORTING
text
= text-016
sap_emphasis = cl_dd_area=>strong. For bold.
CALL METHOD g_document->add_gap
EXPORTING
width = '24'.
CALL METHOD g_document->add_text
EXPORTING
text = l_text.
CALL METHOD g_document->new_line.
CLEAR: l_text.
IF NOT s_vkorg IS INITIAL.
* Sales Organization
IF s_vkorg-high IS NOT INITIAL.
CONCATENATE s_vkorg-low 'to' s_vkorg-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_vkorg-low.
ENDIF.
CALL METHOD g_document->add_text
EXPORTING
text
= text-017
sap_emphasis = cl_dd_area=>strong. For bold.
CALL METHOD g_document->add_gap
EXPORTING
width = '12'.
CALL METHOD g_document->add_text
EXPORTING
text = l_text.
CALL METHOD g_document->new_line.
ENDIF.
CLEAR : l_text.
IF NOT s_bsark IS INITIAL.
* PO Type
IF s_bsark-high IS NOT INITIAL.
CONCATENATE s_bsark-low 'to' s_bsark-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_bsark-low.
ENDIF.
CALL METHOD g_document->add_text
EXPORTING
text
= text-018
sap_emphasis = cl_dd_area=>strong. For bold.
CALL METHOD g_document->add_gap
EXPORTING
width = '32'.
CALL METHOD g_document->add_text
EXPORTING
text = l_text.
CALL METHOD g_document->new_line.
ENDIF.
* Display the data
CALL METHOD g_document->display_document
EXPORTING
parent = g_top_container.
* Calling the method of ALV to process top of page
CALL METHOD g_grid1->list_processing_events
EXPORTING
i_event_name = text-019
i_dyndoc_id = g_document.
ENDFORM.
SUB_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&
Form SUB_CONVERT_SPOOL_TO_PDF
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_convert_spool_to_pdf CHANGING fp_size
TYPE i
fp_i_mess_att TYPE ty_t_mess_att.
TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
DATA: lv_buffer TYPE string,
lv_spool_nr TYPE tsp01-rqident,
lw_mess_att TYPE solisti1,
li_pdf_output TYPE ty_t_pdf,
lw_pdf_output TYPE tline.
* Get the spool number
MOVE sy-spono TO lv_spool_nr.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid
= lv_spool_nr "Spool Number
no_dialog
= space
dst_device
= 'LP01' "Printer Name
IMPORTING
pdf_bytecount
= fp_size "Output Size
TABLES
pdf
= li_pdf_output "Spool data in PDF Format
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob
=2
err_no_permission
=3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled
=6
err_spoolerror
=7
err_temseerror
=8
err_btcjob_open_failed = 9.
IF sy-subrc EQ 0.
LOOP AT li_pdf_output INTO lw_pdf_output.
TRANSLATE lw_pdf_output USING c_col1.
CONCATENATE lv_buffer lw_pdf_output INTO lv_buffer.
CLEAR :lw_pdf_output.
ENDLOOP.
TRANSLATE lv_buffer USING c_col2.
DO.
lw_mess_att = lv_buffer.
APPEND lw_mess_att TO fp_i_mess_att.
SHIFT lv_buffer LEFT BY c_255 PLACES.
IF lv_buffer IS INITIAL.
EXIT.
ENDIF.
CLEAR lw_mess_att.
ENDDO.
ENDIF.
ENDFORM.
SUB_CONVERT_SPOOL_TO_PDF
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result
= sent_to_all).
IF sent_to_all = 'X'.
* E-mail sent successfully
MESSAGE i028 WITH text-020.
ENDIF.
SUB_SEND_PDF_TO_MAIL
REUSE_ALV_BLOCK_LIST_INIT
b)
REUSE_ALV_BLOCK_LIST_APPEND
c)
REUSE_ALV_BLOCK_LIST_DISPLAY
The three field catalogs are built for this and the field catalog names are: LI_FIELDCAT1, LI_FIELDCAT2
and LI_FIELDCAT3.
The header of the three ALVs in the spool is created as follows by using the below code:
PERFORM sub_header_list CHANGING li_events_1
li_events_2
li_events_3.
*&---------------------------------------------------------------------*
*&
Form SUB_HEADER_LIST
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_LI_EVENTS_1 text
*
<--P_LI_EVENTS_2 text
*
<--P_LI_EVENTS_3 text
*----------------------------------------------------------------------*
FORM sub_header_list CHANGING fp_li_events_1 TYPE slis_t_event
fp_li_events_2 TYPE slis_t_event
fp_li_events_3 TYPE slis_t_event.
DATA: lw_events TYPE slis_alv_event.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_1'."Subroutine name
APPEND lw_events TO fp_li_events_1.
CLEAR lw_events.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_2'."Subroutine name
APPEND lw_events TO fp_li_events_2.
CLEAR lw_events.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_3'."Subroutine name
APPEND lw_events TO fp_li_events_3.
CLEAR lw_events.
ENDFORM.
SUB_HEADER_LIST
i_callback_program = lv_repid.
*call first ALV append list
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout
= lv_layout
it_fieldcat
= li_fieldcat1
i_tabname
= 'I_ORDERS1'
it_events
= li_events_1[]
TABLES
t_outtab
= i_orders1
EXCEPTIONS
program_error
=1
maximum_of_appends_reached = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
program_error
=1
maximum_of_appends_reached = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Get the print parameters
PERFORM sub_get_print_parameters.
NEW-PAGE PRINT ON PARAMETERS x_params
NO DIALOG.
lx_print-print = ' '.
lx_print-prnt_title = ' '.
lx_print-prnt_info = ' '.
lx_print-no_print_selinfos = 'X'. " Display no selection infos
lx_print-no_print_listinfos = 'X'. " Display no listinfos
lx_print-no_new_page = 'X'.
*display the data
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
i_interface_check = ' '
is_print
= lx_print
EXCEPTIONS
program_error = 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.
NEW-PAGE PRINT OFF.
Subroutine to get print parameters
*&---------------------------------------------------------------------*
*&
Form SUB_GET_PRINT_PARAMETERS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_get_print_parameters.
DATA: lv_valid.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
immediately = 'X'
no_dialog
= 'X'
line_size
= '255'
line_count = '65'
layout
= 'X_65_255'
destination = 'LP01'
IMPORTING
out_parameters = x_params
valid
= lv_valid
EXCEPTIONS
OTHERS
= 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
SUB_GET_PRINT_PARAMETERS
The above spool output is finally sent as a PDF attachment to email addresses of multiple
persons.
--------------------------------------------------------------------------------------------------------------------------
Include ICONS.
INCLUDE <icons>.
b)
Declare an internal table with the required fields and additional field called RADIO of type CHAR of size 4.
c) Define a class to handle an even HOTSPOT_CLICK o trigger when we click on the radio button icon.
Definition as coded below.
* Handles the Even when user clicks on any row.
METHODS: handle_hotspot_click FOR EVENT hotspot_click
OF cl_gui_alv_grid
IMPORTING e_row_id.
d) Do the implementation for the same class to handle the event i.e. if we select a radio button, then the already
selected radio button should be deselect and new radio button should be selected. Code as follows.
*&--------------------------------------------------------------*
*& METHOD handle_hotspot_click.
*&--------------------------------------------------------------*
*& On double clicking a particulat row
*&--------------------------------------------------------------*
METHOD handle_hotspot_click .
CLEAR : gs_emp.
READ TABLE gt_emp INTO gs_emp
WITH KEY radio = icon_radiobutton.
IF sy-subrc NE 0.
CLEAR gs_emp .
READ TABLE gt_emp INTO gs_emp INDEX e_row_id.
IF gs_emp-radio = icon_radiobutton.
gs_emp-radio = icon_wd_radio_button_empty.
MODIFY gt_emp INDEX e_row_id FROM gs_emp
TRANSPORTING radio.
ELSE.
gs_emp-radio = icon_radiobutton.
MODIFY gt_emp INDEX e_row_id FROM gs_emp
TRANSPORTING radio.
ENDIF.
ELSE .
gs_emp-radio = icon_wd_radio_button_empty.