adding explicit enhancement to custom program

95
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

Upload: raghu-vamsi

Post on 15-Nov-2015

49 views

Category:

Documents


12 download

DESCRIPTION

Document tells how to add Explicit Enhancement in Custom Program of ABAP

TRANSCRIPT

Adding Explicit Enhancement to custom programIntroduction: 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 'Enhancement-section' 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 'ENHANCEMENT-SECTION'. Source Code: *&---------------------------------------------------------------------**&ReportYDEV_CODE*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*

REPORTYDEV_CODE.TABLES:VBAK,VBAP.DATA:IT_VBAKTYPESTANDARDTABLEOFVBAKINITIALSIZE0,WA_VBAKTYPEVBAK,IT_VBAPTYPESTANDARDTABLEOFVBAPINITIALSIZE0,WA_VBAPTYPEVBAP.

INITIALIZATION.REFRESH:IT_VBAK,IT_VBAP.CLEAR:WA_VBAK,WA_VBAP.

START-OF-SELECTION.ENHANCEMENT-SECTIONYDEV_ENHANCE_SECTIONSPOTSYDEV_IMPLEMENT_SPOT.SELECT*FROMVBAPINTOTABLEIT_VBAP[]UPTO15ROWS.

WRITE:/02'SalesDocument',20'Date',40'Time',65'NameofPerson'.ULINE.IFIT_VBAP[]ISNOTINITIAL.LOOPATIT_VBAPINTOWA_VBAP.WRITE:/02WA_VBAP-VBELN,20WA_VBAP-POSNR,40WA_VBAP-MATNR,65WA_VBAP-MATWA.ENDLOOP.ENDIF.END-ENHANCEMENT-SECTION.*$*$-Start:YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*ENHANCEMENT1YDEV_IMPLEMENT_ENHC_SECTION."activeversionSELECT*FROMVBAPINTOTABLEIT_VBAP[]UPTO10ROWS.

WRITE:/02'SalesDocument',20'SalesItem',40'MaterialNumber',65'Materialentered'.ULINE.IFIT_VBAP[]ISNOTINITIAL.LOOPATIT_VBAPINTOWA_VBAP.WRITE:/02WA_VBAP-VBELN,20WA_VBAP-POSNR,40WA_VBAP-MATNR,65WA_VBAP-MATWA.ENDLOOP.ENDIF.ENDENHANCEMENT.*$*$-End:YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$* Understanding the concepts of Object Oriented ProgrammingWhat 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 FeaturesProcedure Oriented approachObject Oriented approach

EmphasisEmphasis on tasksEmphasis on things that does those tasks.

ModularizationPrograms are divided into smaller programs known as functionsPrograms are organized into classes and objects and the functionalities are embedded into methods of a class.

Data securityMost of the functions share global dataData can be hidden and cannot be accessed by external sources.

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

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 classesLocal 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 ClassLocal Class

Accessed ByAny programOnly the program where it is defined.

Stored InIn the Class RepositoryOnly in the program where it is defined.

Created ByCreated using transaction SE24Created using SE38

NamespaceMust begin with Y or ZCan 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 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 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 . ... 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 DEFINITION. PUBLIC SECTION. ... PROTECTED SECTION. ... PRIVATE 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 DefinitionThe Green block of code is CLASS ImplementationThe 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 : TYPE REF TO . Step 2 : Create an object from the reference variable:- Syntax: CREATE OBJECT .Output for the above code is

Attributes of Object Oriented Programming: Inheritance. Abstraction. Encapsulation. PolymorphismInheritance 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 InheritanceSingle Inheriting: Acquiring the properties from a single parent. (Children can be more).

Example for Single InheritanceMultiple 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 DEFINITION INHERITING FROM .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 (identically-named) 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 TYPE REF TO if_ixml_element, ns_attribute TYPE REF TO if_ixml_attribute, r_element_properties TYPE REF TO if_ixml_element, r_element TYPE REF TO if_ixml_element, r_worksheet TYPE REF TO if_ixml_element, r_table TYPE REF TO if_ixml_element, r_column TYPE REF TO if_ixml_element, r_row TYPE REF TO if_ixml_element, r_cell 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-microsoft-com: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 1-Table1' 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 = doc_chng put_in_outbox = 'X' COMMIT_WORK = 'X' TABLES packing_list = objpack object_header = objhead contents_txt = objtxt contents_hex = objbin receivers = 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 EmailIn 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 codeas 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_FIRSTALVSubroutine 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*----------------------------------------------------------------------** p1 text* 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_PAGEStep4: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* p1 text* 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*----------------------------------------------------------------------** refresh_table_displayEXPORTINGis_stable=ls_stableEXCEPTIONSfinished=1OTHERS=2.IFsy-subrc0.*MESSAGEIDSY-MSGIDTYPESY-MSGTYNUMBERSY-MSGNO*WITHSY-MSGV1SY-MSGV2SY-MSGV3SY-MSGV4.ENDIF. h) Please click here for the demo program Output of the Program: