Tuesday, 3 December 2013
Friday, 11 October 2013
zSQL: A tool to execute SQL statements directly in sap – Source Code
*&———————————————————————*
*& Report ZSQL
*&
*&———————————————————————*
*& Developer: Basar Ozgur KAHRAMAN – @basarozgur
*&———————————————————————*
REPORT zsql.
*& Report ZSQL
*&
*&———————————————————————*
*& Developer: Basar Ozgur KAHRAMAN – @basarozgur
*&———————————————————————*
REPORT zsql.
Sunday, 10 February 2013
Essential Basis for SAP (ABAP, BW, Functional) Consultants Part-III
Lets give a fresh look at Developer Key and Object Key: If we know how to check Installation Number of any SAP system then we can verify that installation number remain same across that landscape(example ECC-Sandbox, ECC-Dev, ECC-Quality, ECC-Test, ECC-Production etc). This means if you have developer key for your sandbox system, same key can be used in your development system.
How to check installation Number?
How to check installation Number?
Essential Basis for SAP (ABAP, BW, Functional) Consultants Part-III
Lets give a fresh look at Developer Key and Object Key: If we know how to check Installation Number of any SAP system then we can verify that installation number remain same across that landscape(example ECC-Sandbox, ECC-Dev, ECC-Quality, ECC-Test, ECC-Production etc). This means if you have developer key for your sandbox system, same key can be used in your development system.
How to check installation Number?
How to check installation Number?
Thursday, 13 December 2012
Essential Basis for SAP (ABAP, BW, Functional) Consultants Part-I
I am sure, while working with any type of SAP system, or interacting with Basis team, sometime it feels that a minimal overview of certain topics should be known.
Being a Basis guy, I have taken several sessions to Non-Basis folks in couple of organizations. This overview helps them to improve their understanding about SAP system, what goes behind the curtain and gives considerably better visualization.
When we login to SAP-ABAP we need SAP Logon-pad. Then let’s first talk around it!
It’s always suggested to keep logon pad updated, do you know where to check its version and patch number?
Being a Basis guy, I have taken several sessions to Non-Basis folks in couple of organizations. This overview helps them to improve their understanding about SAP system, what goes behind the curtain and gives considerably better visualization.
When we login to SAP-ABAP we need SAP Logon-pad. Then let’s first talk around it!
It’s always suggested to keep logon pad updated, do you know where to check its version and patch number?
Monday, 5 November 2012
Essential Basis for SAP (ABAP, BW, Functional) Consultants Part-II
This blog is continuation of Essential Basis for SAP (ABAP, BW, Functional) Consultants Part-I
Transport system in SAP is used to move objects from one system to another system, most of the time in one direction.
Transport system in SAP is used to move objects from one system to another system, most of the time in one direction.
This is the picture we visualize when we think about transport system in SAP. Someone made some changes or created a new program that is captured in transport, after releasing it, Basis imported in QAS system then again Basis imported in Prod system, its kind of linear flow attached tightly in sequence (Dev to QA then QA to Prod).
Saturday, 26 May 2012
Object Oriented Design Principles (OODP): Open-Closed Principle(OCP)
Definition:
The name itself sounds like contradicting – OPEN & CLOSE, but by definition, A module should be OPEN for extension but CLOSED for modification. The Open-Closed Principle (OCP) is one of the most important Design Principle. OCP originated from the work of by the Bertrand Meyer.
In simple words: We can add new features in the module without changing the existing code (CLOSED) but by adding new code (OPEN). By following this principle, we can make sure that by changing the code in the method we are not going to break existing functionality. Let us try to see it using the example.
Example:
First of all we would see the code which doesn’t follow this principle. Consider we have a class which prints the shape information of different shapes based on the input.
The name itself sounds like contradicting – OPEN & CLOSE, but by definition, A module should be OPEN for extension but CLOSED for modification. The Open-Closed Principle (OCP) is one of the most important Design Principle. OCP originated from the work of by the Bertrand Meyer.
In simple words: We can add new features in the module without changing the existing code (CLOSED) but by adding new code (OPEN). By following this principle, we can make sure that by changing the code in the method we are not going to break existing functionality. Let us try to see it using the example.
Example:
First of all we would see the code which doesn’t follow this principle. Consider we have a class which prints the shape information of different shapes based on the input.
Code snippet which violates this principle.
*——————————————————–* *& Author : Naimesh Patel *& Purpose: Open-Closed Principle (violation) *——————————————————–* REPORT ztest_np_ocp. *——————————————————–* * CLASS lcl_circle DEFINITION *——————————————————–* * Circle *——————————————————–* CLASS lcl_circle DEFINITION. PUBLIC SECTION. METHODS: write_circle. ENDCLASS. “lcl_circle DEFINITION *——————————————————–* * CLASS lcl_square DEFINITION *——————————————————–* * Square *——————————————————–* CLASS lcl_square DEFINITION. PUBLIC SECTION. METHODS: write_square. ENDCLASS. “lcl_square DEFINITION *——————————————————–* * CLASS lcl_report DEFINITION *——————————————————–* * Report *——————————————————–* CLASS lcl_report DEFINITION. PUBLIC SECTION. METHODS: create_shape IMPORTING if_type TYPE char30, write_shape IMPORTING if_type TYPE char30. PRIVATE SECTION. DATA: o_circle TYPE REF TO lcl_circle. DATA: o_square TYPE REF TO lcl_square. ENDCLASS. “lcl_report DEFINITION PARAMETERS: p_shape TYPE char30. START-OF-SELECTION. DATA: o_report TYPE REF TO lcl_report. CREATE OBJECT o_report. o_report->create_shape( p_shape ). o_report->write_shape( p_shape ). *——————————————————–* * CLASS lcl_circle IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_circle IMPLEMENTATION. METHOD write_circle. WRITE: / ‘I am a Circle’. ENDMETHOD. “write_circle ENDCLASS. “lcl_circle IMPLEMENTATION *——————————————————–* * CLASS lcl_square IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_square IMPLEMENTATION. METHOD write_square. WRITE: / ‘I am a Square’. ENDMETHOD. “write_square ENDCLASS. “lcl_square IMPLEMENTATION *——————————————————–* * CLASS lcl_report IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_report IMPLEMENTATION. METHOD create_shape. CASE if_type. WHEN ‘CIRCLE’. CREATE OBJECT: me->o_circle. WHEN ‘SQUARE’. CREATE OBJECT: me->o_square. ENDCASE. ENDMETHOD. “create_shapes METHOD write_shape. CASE if_type. WHEN ‘CIRCLE’. me->o_circle->write_circle( ). WHEN ‘SQUARE’. me->o_square->write_square( ). ENDCASE. ENDMETHOD. “write_shapes ENDCLASS. “lcl_report IMPLEMENTATION
Now the problem with this code is, when ever we need to add a new type of Shape, we need to change the code in the CREATE_SHAPE, WRITE_SHAPE method, which is clear violation of the OCP. According to OCP, we should only change the method to add new functionality. Here we are not adding a new functionality. Creation of the Shape Object and writing the information of the different Shape is not a new functionality. So, we must re-design our class and methods to be able to follow the Open Closed Principle.
We can use the dynamic polymorphism to achieve Open-Closed design. Check the UML for the new design.
Now we would create an interface LIF_SHAPE which we will use to create different shapes like circle using LCL_CIRCLE, square using LCL_SQUARE and so on.
*——————————————————–* * INTERFACE lif_shape *——————————————————–* * Shpae Interface *——————————————————–* INTERFACE lif_shape. METHODS: write_shape. ENDINTERFACE. “lif_shape *——————————————————–* * CLASS lcl_circle DEFINITION *——————————————————–* * Circle uses interface *——————————————————–* CLASS lcl_circle DEFINITION. PUBLIC SECTION. INTERFACES lif_shape. ENDCLASS. “lcl_circle DEFINITION *——————————————————–* * CLASS lcl_square DEFINITION *——————————————————–* * Square uses interface *——————————————————–* CLASS lcl_square DEFINITION. PUBLIC SECTION. INTERFACES lif_shape. ENDCLASS. “lcl_square DEFINITION
Implementation of the class LCL_CIRCLE and LCL_SQUARE implements the method
*——————————————————–* * CLASS lcl_circle IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_circle IMPLEMENTATION. METHOD lif_shape~write_shape. WRITE: ‘I am a Circle’. ENDMETHOD. “lif_shape~write_shape ENDCLASS. “lcl_circle IMPLEMENTATION *——————————————————–* * CLASS lcl_square IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_square IMPLEMENTATION. METHOD lif_shape~write_shape. WRITE: ‘I am a Square’. ENDMETHOD. “lif_shape~write_shape ENDCLASS. “lcl_square IMPLEMENTATION
Design of the report class is also changed. LCL_REPORT would now accept the class name instead of the simple type to instantiate required object as the parameter of the method CREATE_SHAPE.
*——————————————————–* * CLASS lcl_report DEFINITION *——————————————————–* * Report *——————————————————–* CLASS lcl_report DEFINITION. PUBLIC SECTION. METHODS: create_shape IMPORTING if_type TYPE char30, write_shape IMPORTING if_type TYPE char30. PRIVATE SECTION. DATA: o_shape TYPE REF TO lif_shape. ENDCLASS. “lcl_report DEFINITION
Implementation of the class LCL_REPORT needs to be changed. CREATE_SHPAE would create the object and WRITE_SHAPE would call the method WRITE_SHAPE from the object O_SHAPE.
*——————————————————–* * CLASS lcl_report IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_report IMPLEMENTATION. METHOD create_shape. * Instantiate the object based on the type CREATE OBJECT me->o_shape TYPE (if_type). ENDMETHOD. “create_shapes METHOD write_shape. * write shape me->o_shape->write_shape( ). ENDMETHOD. “write_shapes ENDCLASS. “lcl_report IMPLEMENTATION
Full code Snippet which shows how to achieve OCP design.
*——————————————————–* *& Author : Naimesh Patel *& Purpose : Open-Closed Principle (Achieved) *——————————————————–* REPORT ztest_np_ocp. *——————————————————–* * INTERFACE lif_shape *——————————————————–* * Shpae Interface *——————————————————–* INTERFACE lif_shape. METHODS: write_shape. ENDINTERFACE. “lif_shape *——————————————————–* * CLASS lcl_circle DEFINITION *——————————————————–* * Circle uses interface *——————————————————–* CLASS lcl_circle DEFINITION. PUBLIC SECTION. INTERFACES lif_shape. ENDCLASS. “lcl_circle DEFINITION *——————————————————–* * CLASS lcl_square DEFINITION *——————————————————–* * Square uses interface *——————————————————–* CLASS lcl_square DEFINITION. PUBLIC SECTION. INTERFACES lif_shape. ENDCLASS. “lcl_square DEFINITION *——————————————————–* * CLASS lcl_report DEFINITION *——————————————————–* * Report *——————————————————–* CLASS lcl_report DEFINITION. PUBLIC SECTION. METHODS: create_shape IMPORTING if_type TYPE char30, write_shape IMPORTING if_type TYPE char30. PRIVATE SECTION. DATA: o_shape TYPE REF TO lif_shape. ENDCLASS. “lcl_report DEFINITION *……selection screen……………………………..* PARAMETERS: p_shape TYPE char30. *….. START-OF_SELECTION……………………………* START-OF-SELECTION. DATA: o_report TYPE REF TO lcl_report, w_type TYPE char30. * Name of the Class CONCATENATE ‘LCL_’ p_shape INTO w_type. * Instantiate the object CREATE OBJECT o_report. * Shape o_report->create_shape( w_type ). o_report->write_shape( w_type ). *——————————————————–* * CLASS lcl_report IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_report IMPLEMENTATION. METHOD create_shape. * Instantiate the object based on the type CREATE OBJECT me->o_shape TYPE (if_type). ENDMETHOD. “create_shapes METHOD write_shape. * write shape me->o_shape->write_shape( ). ENDMETHOD. “write_shapes ENDCLASS. “lcl_report IMPLEMENTATION *——————————————————–* * CLASS lcl_circle IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_circle IMPLEMENTATION. METHOD lif_shape~write_shape. WRITE: ‘I am a Circle’. ENDMETHOD. “lif_shape~write_shape ENDCLASS. “lcl_circle IMPLEMENTATION *——————————————————–* * CLASS lcl_square IMPLEMENTATION *——————————————————–* * *——————————————————–* CLASS lcl_square IMPLEMENTATION. METHOD lif_shape~write_shape. WRITE: ‘I am a Square’. ENDMETHOD. “lif_shape~write_shape ENDCLASS. “lcl_square IMPLEMENTATION
Now, if we want to add a new shape, say TRIANGLE. We can easily add a new shape without changing any existing code.
1. Create a new class LCL_TRIANGLE which implements the interface LIF_SHAPE
2. Implement the method LIF_SHAPE~WRITE_SHAPE in this class.
Subscribe to:
Posts (Atom)



