Vous êtes sur la page 1sur 78

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

STEP 2: Navigate to 'Enhancements' folder of your package. Package (YDEV) Enhancement.


Right click the 'Enhancements' 'Create' 'Enhancement Spot'.

Fill in the details in the 'Create Enhancement Spot' dialog.

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

Fill in all the details in the 'Create Enhancement Implementation' dialog.

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.

Now we are able to see program lines have Enhancement-SectionEnd Enhancement-Section.

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.

STEP 10: Execute the transaction/program to find out the difference.


Before Enhancement:

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.

ENHANCEMENT-SECTION YDEV_ENHANCE_SECTION SPOTS YDEV_IMPLEMENT_SPOT .


SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 15 ROWS.
WRITE: /02 'Sales Document',
20 'Date',
40 'Time',
65 'Name of Person'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
END-ENHANCEMENT-SECTION.
*$*$-Start: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*
ENHANCEMENT 1 YDEV_IMPLEMENT_ENHC_SECTION. "active version
SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 10 ROWS.
WRITE: /02 'Sales Document',
20 'Sales Item',
40 'Material Number',
65 'Material entered'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
ENDENHANCEMENT.
*$*$-End: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*

Understanding the concepts of Object Oriented Programming


What
is
Object
Orientation?
In the past, information systems used to be defined primarily by their functionality: Data and functions
were kept separate and linked together by means of input and output relations.
The object-oriented approach, however, focuses on objects that represent abstract or concrete things of
the real world. These objects are first defined by their character and their properties, which are
represented by their internal structure and their attributes (data). The behavior of these objects is
described by methods (functionality).
Comparison between Procedural and Object Oriented Programming

Features

Procedure Oriented approach

Object Oriented approach

Emphasis

Emphasis on tasks

Emphasis on things that does


those tasks.

Modularization

Programs are divided into


smaller programs known as
functions

Programs are organized into


classes and objects and the
functionalities are embedded into
methods of a class.

Data security

Most of the functions share


global data

Data can be hidden and cannot be


accessed by external sources.

Extensibility

Relatively more time


New data and functions can be
consuming to modify for
easily added whenever necessary
extending existing functionality.

Object Oriented Approach - key features


1. Better Programming Structure.
2. Real world entity can be modeled very well.
3. Stress on data security and access.
4. Reduction in code redundancy.
5. Data encapsulation and abstraction.
What are Objects and Classes?
Objects: An object is a section of source code that contains data and provides services. The data
forms the attributes of the object. The services are known as methods (also known as operations or
functions). They form a capsule which combines the character to the respective behavior. Objects
should enable programmers to map a real problem and its proposed software solution on a one-to-one
basis.
Classes: Classes describe objects. From a technical point of view, objects are runtime instances of a
class. In theory, you can create any number of objects based on a single class. Each instance (object)
of a class has a unique identity and its own set of values for its attributes.
Local and Global Classes
As mentioned earlier a class is an abstract description of an object. Classes in ABAP Objects can be declared
either globally or locally.
Global Class: Global classes and interfaces are defined in the Class Builder (Transaction SE24) in the ABAP
Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP
programs in an R/3 System can access the global classes
Local Class: Local classes are define in an ABAP program (Transaction SE38) and can only be used in the
program in which they are defined.
Global Class
Local Class
Accessed By

Any program

Only the program where it is defined.

Stored In
Created By

In the Class Repository


Created using transaction SE24

Only in the program where it is defined.


Created using SE38

Namespace

Must begin with Y or Z

Can begin with any character

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.

The yellow block of code is CLASS Definition


The Green block of code is CLASS Implementation
The Grey block of code is for object creation. This object creation includes two steps:
Step1 is Create a reference variable with reference to the class.
Syntax: DATA : <object name> TYPE REF TO <class name>.
Step 2 : Create an object from the reference variable:Syntax: CREATE OBJECT <object name> .
Output for the above code is

Attributes of Object Oriented Programming:


Inheritance.
Abstraction.
Encapsulation.
Polymorphism
Inheritance is the concept of adopting the features from the parent and reusing them . It involves passing the
behavior of a class to another class. You can use an existing class to derive a new class. Derived classes
inherit the data and methods of the super class. However, they can overwrite existing methods, and also add
new ones.

Inheritance is of two types: Single Inheritance and Multiple Inheritance


Single Inheriting: Acquiring the properties from a single parent. (Children can be more).

Example for Single Inheritance


Multiple inheritance: Acquiring the properties from more than one parent.
Example

Tomato4 (Best Color, Size, Taste)


Tomato1
(Best color)
Tomato2
(Best Size)
Tomato3
(Best Taste)

Syntax : CLASS <subclass> DEFINITION INHERITING FROM <superclass>.


Let us see a very simple example for creating subclass(child) from a superclass(parent)

Multiple Inheritance is not supported by ABAP.


Output is as follows :

Abstraction: Everything is visualized in terms of classes and objects.


Encapsulation The wrapping up of data and methods into a single unit (called class) is known as
Encapsulation. The data is not accessible to the outside world only those methods, which are wrapped in the
class, can access it.

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
*"

REFERENCE(I_MAIL_ID) TYPE ADR6-SMTP_ADDR

*" EXPORTING
*"

REFERENCE(E_RETURN) TYPE BAPIRET2

*"----------------------------------------------------------------------

*"----------------------------------------------------------------------

*"----------------------------------------------------------------------

DATA: lv_date TYPE d.


DATA: lv_filename TYPE string.

data : wa_tab1 type Ztab1,


wa_tab2 type Ztab2.

TYPES: BEGIN OF xml_line,


data(255) TYPE x,
END OF xml_line.

DATA: l_ixml

TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,


l_ostream

TYPE REF TO if_ixml_ostream,

l_renderer

TYPE REF TO if_ixml_renderer,

l_document

TYPE REF TO if_ixml_document.

DATA: l_element_root
ns_attribute

TYPE REF TO if_ixml_element,


TYPE REF TO if_ixml_attribute,

r_element_properties TYPE REF TO if_ixml_element,


r_element
r_worksheet
r_table
r_column
r_row
r_cell

TYPE REF TO if_ixml_element,


TYPE REF TO if_ixml_element,
TYPE REF TO if_ixml_element,
TYPE REF TO if_ixml_element,
TYPE REF TO if_ixml_element,
TYPE REF TO if_ixml_element,

r_data

TYPE REF TO if_ixml_element,

l_value

TYPE string,

l_type

TYPE string,

l_text(100)

TYPE c,

r_styles

TYPE REF TO if_ixml_element,

r_style

TYPE REF TO if_ixml_element,

r_style1

TYPE REF TO if_ixml_element,

r_style2

TYPE REF TO if_ixml_element,

r_style3

TYPE REF TO if_ixml_element,

r_style4

TYPE REF TO if_ixml_element,

r_format

TYPE REF TO if_ixml_element,

r_border

TYPE REF TO if_ixml_element,

num_rows

TYPE i.

DATA: l_xml_table

TYPE TABLE OF xml_line,

wa_xml

TYPE xml_line,

l_xml_size

TYPE i,

l_rc

TYPE i.

DATA: d_value type p decimals 2,


d_num_result(20) TYPE c,
d_decimal(2)

TYPE c,

d_number(20) type c.

lv_date = sy-datum - 1.

* Creating a ixml Factory


l_ixml = cl_ixml=>create( ).

* Creating the DOM Object Model


l_document = l_ixml->create_document( ).

* Create Root Node 'Workbook'


l_element_root = l_document->create_simple_element( name = 'Workbook'
parent = l_document ).
l_element_root->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoftcom:office:spreadsheet' ).

ns_attribute = l_document->create_namespace_decl( name = 'ss' prefix = 'xmlns'


uri = 'urn:schemas-microsoft-com:office:spreadsheet' ).
l_element_root->set_attribute_node( ns_attribute ).

ns_attribute = l_document->create_namespace_decl( name = 'x' prefix = 'xmlns'


uri = 'urn:schemas-microsoft-com:office:excel' ).
l_element_root->set_attribute_node( ns_attribute ).

* Create node for document properties.


r_element_properties = l_document->create_simple_element( name =
'TEST_REPORT' parent = l_element_root ).
l_value = sy-uname.
l_document->create_simple_element( name = 'Author' value = l_value parent =
r_element_properties ).

* Styles

r_styles = l_document->create_simple_element( name = 'Styles' parent =


l_element_root ).

* Style for Header


r_style = l_document->create_simple_element( name = 'Style' parent = r_styles
).
r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ).

r_format = l_document->create_simple_element( name = 'Font' parent =


r_style ).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Interior' parent =


r_style ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#FFFFFF' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).

r_format = l_document->create_simple_element( name = 'Alignment' parent =


r_style ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).

r_border = l_document->create_simple_element( name = 'Borders' parent =


r_style ).
r_format = l_document->create_simple_element( name = 'Border' parent =
r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).

r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =


'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

***
* Style for tablename
r_style2 = l_document->create_simple_element( name = 'Style' parent =
r_styles ).

r_style2->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header1' ).

r_format = l_document->create_simple_element( name = 'Font' parent = r_style2


).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#FFFFFF' ).

r_format = l_document->create_simple_element( name = 'Interior' parent =


r_style2 ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#4F81BD' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).

r_format = l_document->create_simple_element( name = 'Alignment' parent =


r_style2 ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'Horizontal' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).
*
r_border = l_document->create_simple_element( name = 'Borders' parent =
r_style2 ).
r_format = l_document->create_simple_element( name = 'Border' parent =
r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
****

* Style for header2


r_style4 = l_document->create_simple_element( name = 'Style' parent =
r_styles ).
r_style4->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header2' ).

r_format = l_document->create_simple_element( name = 'Font' parent = r_style4


).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#FFFFFF' ).

r_format = l_document->create_simple_element( name = 'Interior' parent =


r_style4 ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#4F81BD' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).

r_format = l_document->create_simple_element( name = 'Alignment' parent =


r_style4 ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'Horizontal' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).
*
r_border = l_document->create_simple_element( name = 'Borders' parent =
r_style4 ).
r_format = l_document->create_simple_element( name = 'Border' parent =
r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).

r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
***********

*Style for main title


r_style3 = l_document->create_simple_element( name = 'Style' parent =
r_styles ).
r_style3->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Main' ).

r_format = l_document->create_simple_element( name = 'Font' parent = r_style3


).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#366092' ).

******************

* Style for Data


r_style1 = l_document->create_simple_element( name = 'Style' parent =
r_styles ).
r_style1->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Data' ).

r_border = l_document->create_simple_element( name = 'Borders' parent =


r_style1 ).
r_format = l_document->create_simple_element( name = 'Border' parent =
r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent =


r_border ).

r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).


r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value =
'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Alignment' parent =


r_style1 ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'Horizontal' prefix = 'ss' value = 'Left' ).

* 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'

prefix = 'x' value = '1' ).

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

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).

r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

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

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'MergeAcross' prefix = 'ss' value = '3' ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Main' ).
* r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 's78' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Sheet 1Table1' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).
r_row->set_attribute_ns( name = 'Height' prefix = 'ss' value = '27' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'MergeAcross' prefix = 'ss' value = '3' ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Main' ).
* r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 's78' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Data of 1st
table' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).

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

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'MergeAcross' prefix = 'ss' value = '2' ).

r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header1' ).


r_data = l_document->create_simple_element( name = 'Data' value =
'COMMODITY IMPACT' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Column Headers Row

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).
*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 =


'Commodity' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

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

r_data = l_document->create_simple_element( name = 'Data' value = l_value


parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Blank Row after Column Headers


r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

DATA: WA_INPUT TYPE P DECIMALS 8,

WA_OUTPUT TYPE P DECIMALS 2.

* Data Table
LOOP AT T_tab2 INTO wa_tab2.

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).

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

CALL FUNCTION 'ROUND'

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.

CALL FUNCTION 'ROUND'

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.

**************

* * Worksheet2( second tab)


r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent
= l_element_root ).
r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Tab2' ).

* 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'

prefix = 'x' value = '1' ).

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

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

r_column = l_document->create_simple_element( name = 'Column' parent =


r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).

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

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'MergeAcross' prefix = 'ss' value = '3' ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Main' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Atlas - PPV
Forecast Transformation' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).
r_row->set_attribute_ns( name = 'Height' prefix = 'ss' value = '27' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'MergeAcross' prefix = 'ss' value = '3' ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Main' ).
* r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 's78' ).
r_data = l_document->create_simple_element( name = 'Data' value =
'FEEDSTOCK COMMODITY IMPACT' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

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

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).


r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '0' ).

* Column Headers Row


r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).

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

* CURRENT COMMODITY PRICE


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 = 'CURRENT
COMMODITY PRICE' 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 ).

r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

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

r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header2' ).


r_data = l_document->create_simple_element( name = 'Data' value = 'FIG
CYCLE' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Blank Row after Column Headers


r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
*
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
*
*
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).


r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).

* Data Table
LOOP AT T_tab1 INTO wa_tab1.

r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).

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

r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).


l_value = wa_tab1-/BIC/GPU_FDUOM.
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

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

* current commodity price


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/GPUCCPRIC.
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.

CALL FUNCTION 'ROUND'

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.

CALL FUNCTION 'ROUND'

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.

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

clear wa_tab1.

ENDLOOP.

* *Mail sending functionality*************

* Creating a Stream Factory


l_streamfactory = l_ixml->create_stream_factory( ).

* Connect Internal XML Table to Stream Factory


l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).

* Rendering the Document


l_renderer = l_ixml->create_renderer( ostream = l_ostream document =
l_document ).
l_rc = l_renderer->render( ).

* Saving the XML Document


l_xml_size = l_ostream->get_num_written_raw( ).

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.


DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin

LIKE solix OCCURS 10 WITH HEADER LINE.

DATA: objtxt

LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.


DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA: l_num(3).
DATA: subj_date(10) TYPE c.

doc_chng-obj_descr = 'Multiple Tabs' .

DESCRIBE TABLE objtxt LINES tab_lines.


READ TABLE objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

* Packing List For the E-mail Body


objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.

* Creation of the Document Attachment


LOOP AT l_xml_table INTO wa_xml.
CLEAR objbin.
objbin-line = wa_xml-data.
APPEND objbin.
ENDLOOP.

DESCRIBE TABLE objbin LINES tab_lines.


objhead = Multiple tabs'.
APPEND objhead.

* Packing List For the E-mail Attachment


objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-obj_descr = 'Summary Table'.
objpack-doc_type = 'XLS'.
objpack-doc_size = tab_lines * 255.
APPEND objpack.

* Target Recipent
CLEAR reclist.
reclist-receiver = I_MAILID.

reclist-rec_type = 'U'.
RECLIST-EXPRESS = 'X'.

APPEND reclist.

* Sending the document


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data
put_in_outbox
COMMIT_WORK

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

Sending the Multiple ALVs as PDF Attachment through Email


In this document, an email, with the PDF attachment of 3 ALV outputs, will be send to the Email
addresses of multiple persons or single person as required. The principle is to print ALVs to spool directly,
convert spool to PDF, and send the PDF to email. It can be used in background as well as in foreground.
The program must be executed in background to generate the spool request.
Scenario:
The program will display 3 ALV grids using Custom containers in foreground and will use FM
REUSE_ALV_BLOCK_LIST_APPEND to generate spool. When the program is executed in foreground,
the three ALV grids will be displayed and an email with PDF attachment of the ALV outputs will be
send .When the program is executed in background, spool request will be generated containing the 3 ALV
outputs and an email with PDF attachment of the ALV outputs will be send.
Challenge:
The challenge in this scenario is, the 3 ALV grids built using OOPS concept cannot be sent to Spool
directly in foreground. For sending the 3 ALV grids to spool, FM REUSE_ALV_BLOCK_LIST_APPEND
has been used. The foreground mode uses both the normal ALV grid display methods of OOPS to display
the three ALVs in foreground and then uses REUSE_ALV_BLOCK_LIST_APPEND FM to send the report
to spool as list. The background mode uses only REUSE_ALV_BLOCK_LIST_APPEND to send the
report to spool.
Step1:

Creating screen for foreground display

Go to Screen painter Transaction Code SE51.


Create a screen with no 100.
Provide description for the screen and click on the Layout Button.
Place 3 Custom container UI elements and give names as G_CONTAINER1 , G_CONTAINER2 and
G_CONTAINER3 .The screen 100 will have 3 custom containers as shown below. Activate the Object.

Step 2: Flow Logic


Go to the Flow Logic Tab to write coding for PBO & PAI.

Step3: ABAP Editor


Create a Z program with the code as below:
The three internal tables for 3 ALVs are: I_ORDERS1, I_ORDERS2 and I_INVSTATUS.

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

Refresh the first display table


CALL METHOD g_grid1->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.

Refresh the second display table


CALL METHOD g_grid2->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.

Refresh the third display table


CALL METHOD g_grid3->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.

ENDMODULE.

" STATUS_0100 OUTPUT

Subroutine to set the PF Status of the report

*&---------------------------------------------------------------------*
*&
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:

lx_print TYPE lvc_s_prnt.

* Local data declaration


DATA: li_layout TYPE lvc_s_layo.
* Layout for ALV
PERFORM sub_prepare_layout USING c_x
text-011
c_x
c_cellstyle
CHANGING li_layout.
* Use Flush
CALL METHOD cl_gui_cfw=>flush.
IF g_custom_container1 IS INITIAL.

"To ensure that object is created only once

CREATE OBJECT g_custom_container1


EXPORTING
container_name = 'G_CONTAINER1'.
* Splitting the container

CREATE OBJECT g_split


EXPORTING
parent
= g_custom_container1
sash_position = 50 "Position of Splitter Bar (in Percent)
with_border = 0.With Border = 1 Without Border = 0
* Placing the containers in the splitter
g_top_container = g_split->top_left_container.
g_bottom_container = g_split->bottom_right_container.
*

Create an instance of ALV control


CREATE OBJECT g_grid1
EXPORTING
i_parent = g_bottom_container.

* Creating the document


CREATE OBJECT g_document
EXPORTING
style = 'ALV_GRID'.
*Top of page
PERFORM sub_top_of_page.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING
it_toolbar_excluding
= i_exclude
is_layout
= li_layout
is_print
= lx_print
CHANGING
it_outtab
= fp_i_orders1
it_fieldcatalog
= fp_i_fieldcatalog1
EXCEPTIONS
invalid_parameter_combination = 1
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_FIRSTALV

Subroutine to Display Second ALV

*&---------------------------------------------------------------------*
*&
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.

* Layout for ALV


PERFORM sub_prepare_layout USING c_x
text-012
c_x
c_cellstyle
CHANGING li_layout.
* Use Flush
CALL METHOD cl_gui_cfw=>flush.
IF g_custom_container2 IS INITIAL.

"To ensure that object is created only once

CREATE OBJECT g_custom_container2


EXPORTING
container_name = 'G_CONTAINER2'.
*

Create an instance of ALV control


CREATE OBJECT g_grid2
EXPORTING
i_parent = g_custom_container2.

CALL METHOD g_grid2->set_table_for_first_display


EXPORTING
it_toolbar_excluding
= i_exclude
is_layout
= li_layout
is_print
= lx_print
CHANGING
it_outtab
= fp_i_orders2
it_fieldcatalog
= fp_i_fieldcatalog2
EXCEPTIONS
invalid_parameter_combination = 1

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

Subroutine to Display Third ALV


*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_THIRDALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG3 text
*
-->P_I_INVSTATUS text
*----------------------------------------------------------------------*
FORM sub_display_thirdalv USING fp_i_fieldcatalog3 TYPE lvc_t_fcat
fp_i_invstatus TYPE ty_t_invstatus.
* Local data declaration
DATA: li_layout TYPE lvc_s_layo,
lx_print TYPE lvc_s_prnt.

* Layout for ALV


PERFORM sub_prepare_layout USING c_x
text-013
c_x
c_cellstyle
CHANGING li_layout.
* Use Flush
CALL METHOD cl_gui_cfw=>flush.
IF g_custom_container3 IS INITIAL.

"To ensure that object is created only once

CREATE OBJECT g_custom_container3


EXPORTING
container_name = 'G_CONTAINER3'.
*

Create an instance of ALV control


CREATE OBJECT g_grid3
EXPORTING
i_parent = g_custom_container3.

CALL METHOD g_grid3->set_table_for_first_display


EXPORTING
it_toolbar_excluding
= i_exclude
is_layout
= li_layout
is_print
= lx_print
CHANGING
it_outtab
= fp_i_invstatus
it_fieldcatalog
= fp_i_fieldcatalog3
EXCEPTIONS
invalid_parameter_combination = 1
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_THIRDALV
Subroutine for ALV layout
*&---------------------------------------------------------------------*
*&
Form SUB_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_LI_LAYOUT text
*----------------------------------------------------------------------*
FORM sub_prepare_layout USING fp_c_x
TYPE xfeld
fp_title
TYPE lvc_title
fp_smalltitle TYPE xfeld
fp_stylename TYPE lvc_fname
CHANGING fp_li_layout TYPE lvc_s_layo.
fp_li_layout-zebra
= fp_c_x.
fp_li_layout-grid_title = fp_title.
fp_li_layout-smalltitle = fp_smalltitle.
fp_li_layout-stylefname = fp_stylename.
ENDFORM.

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

Step4: Sending an Email with PDF attachment of the output.


The ALV output is first send to spool request, then the spool is converted to PDF and then the
PDF attachment is sent to Email.
a)

Converting Spool to PDF

*&---------------------------------------------------------------------*
*&
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

b) Sending PDF attachment to Email


The email addresses of the receivers are populated in table I_EMAIL which is passed in the below
subroutine as FP_I_EMAIL.
*&---------------------------------------------------------------------*
*&
Form SUB_SEND_PDF_TO_MAIL
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_send_pdf_to_mail USING fp_size
TYPE i
fp_i_mess_att TYPE ty_t_mess_att
fp_i_email TYPE ty_t_email.
DATA: l_ref_bcs
TYPE REF TO cl_bcs,
l_ref_document TYPE REF TO cl_document_bcs,
lv_text
TYPE so_obj_des,
lv_data
TYPE bcsy_text,
lv_filesize TYPE so_obj_len,
lw_email
TYPE ty_email,
l_recipient TYPE REF TO if_recipient_bcs,
l_ref_bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean.

LOOP AT fp_i_email INTO lw_email.


TRY.
* Create persistent send request
l_ref_bcs = cl_bcs=>create_persistent ( ).
* Mail subject
lv_text = text-021.
APPEND text-021 TO lv_data.
* Create document
l_ref_document = cl_document_bcs=>create_document (
i_type = c_raw
i_text = lv_data
i_subject = lv_text).
* Create document reference
lv_filesize = fp_size.
CALL METHOD l_ref_document->add_attachment
EXPORTING
i_attachment_type = c_pdf
i_attachment_size = lv_filesize
i_attachment_subject = lv_text
i_att_content_text = fp_i_mess_att [].
* Set the document
l_ref_bcs->set_document (l_ref_document).
* Get Recipient Object
l_recipient = cl_cam_address_bcs=>create_internet_address (lw_email-smtp_addr).
*
* Add recipient with its respective attributes to send request
CALL METHOD l_ref_bcs->add_recipient
EXPORTING
i_recipient = l_recipient.
* Set that you don't need a Return Status E-mail
CALL METHOD l_ref_bcs->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail
= 'E'.
* Set send immediately flag
l_ref_bcs->set_send_immediately( 'X' ).
* Send E-mail
CALL METHOD l_ref_bcs->send (

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.

CATCH cx_bcs INTO l_ref_bcs_exception.


IF l_ref_bcs_exception IS NOT INITIAL.
CLEAR l_ref_bcs_exception.
ENDIF.
ENDTRY.
ENDLOOP.
COMMIT WORK.
ENDFORM.

SUB_SEND_PDF_TO_MAIL

Step 5: Report output in foreground

Step 6: Functionality for executing the report in Background.


When the report is executed in background, the single spool of three ALV grids will be created.
For displaying the three ALV Grids in single spool, we will use the following FMs:
a)

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

Step 7: Displaying the three ALVs in background


lv_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'


EXPORTING

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.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'


EXPORTING
is_layout
= lv_layout
it_fieldcat
= li_fieldcat2
i_tabname
= 'I_ORDERS2'
it_events
= li_events_2
TABLES
t_outtab
= i_orders2
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.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout
= lv_layout
it_fieldcat
= li_fieldcat3
i_tabname
= 'I_INVSTATUS'
it_events
= li_events_3
TABLES
t_outtab
= i_invstatus
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.
* 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

Step 8: Report output in background.

The above spool output is finally sent as a PDF attachment to email addresses of multiple
persons.
--------------------------------------------------------------------------------------------------------------------------

Radio Buttons in the output of an ALV


As per business need there was a scenario for an ALV Report Output, It must have functionality selecting only one
row at a time. It is possible with Radio buttons.
NOTE: Here we have two types of Radio buttons Icons i.e. icon_wd_radio_button_empty (Empty Radio Button)
and icon_radiobutton (Selected Radio button)
Below are the steps to display Radio Buttons in the output of an ALV.
a)

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.

Vous aimerez peut-être aussi