abap-oops
abap-oops
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).
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.
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.
Local Classes
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.
Structure of a 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.
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 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.
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.
Single Inheriting: Acquiring the properties from a single parent. (Children can be more).
Multiple inheritance: Acquiring the properties from more than one parent.
Example
Let us see a very simple example for creating subclass(child) from a superclass(parent)
Output is as follows :
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.
ALV
ABAP List Viewer is used to enhance the readability and functionality of any report output. We
can develop ALV using different ways like using type pool SLIS or using the class
Cl_GUI_ALV_GRID. In case of Object-Oriented concept, the Control Framework is required as it
provides global classes for various functionalities.
CL_GUI_ALV_GRID
It is the wrapper class implemented to encapsulate ALV Grid functionality for list display. ALV
Grid control is a flexible tool which provides following capabilities:
1. List Data : Data to be listed is populated in an internal table. This table can be of any flat
type
2. Field Catalog: This is an internal table which contains the list of fields as per
specification. It comprises of some additional information about display options for each
column to be displayed. It must be referenced to the dictionary type “LVC_T_FCAT”
while the work-area should be of type “LVC_S_FCAT”. Function
“LVC_FIELDCATALOG_MERGE” can also be used to get field catalog by passing structure
name.
3. Container: Container is a storage area where the list will be displayed. It should be of
type “CL_GUI_CUSTOM_CONTAINER”. Other Container Classes are:
o CL_GUI_DOCKING_CONTAINER- For displaying multiple ALV’s by using methods
such as dock_at_left, dock_at_right, dock_at_top, dock_at_bottom. Internal
tables can be displayed in these containers.
o CL_GUI_EASY_SPLITTER_CONTAINER- For displaying two ALV Grids on single
screen, container is splitted into two containers by using this class.
o CL_GUI_DIALOGBOX_CONTAINER- This is used in case of Interactive ALV, where
details list will be displayed in dialog box. For this functionality refer to example
BCALV_GRID_02.
4. Layout Structure: It is a structure to specify general layout options for the grid. With this
structure we can set general display options, grid customizing, totals options, color
adjustments etc. The layout structure must be of type “LVC_S_LAYO”.
5. Event Handler: For handling events, we need to define and implement an event handler
class triggered by the ALV Grid instance. After creating ALV Grid instance, we must
register an instance of this event handler class to handle ALV Grid events.
Various Events are as follows-
o Print_Top_Of_Page: Used for Headers. Handler is ‘SET HANDLER’.
o Print_End_Of_Page: Used for Footers. Handler is ‘SET HANDLER’.
o OnDrag : This event is used to ‘fetch’ information from the drag source.
o OnDrop : This event is used to use the dragged information in combination with
drop source. Here, it should be checked whether the operation is successful.
o OnDropComplete: This event is used to change the state after a successful drag
and drop operation. For example: update the used internal table if a row has
been moved.NOTE: For Drag and Drop functionality refer to these standard
examples-BCALV_DND_01- Drag ALV row to Tree Folder
BCALV_DND_02- Drag Icons from Tree to rows of Grid
BCALV_DND_03- Drag & Drop on cells of grid
BCALV_DND_04- Drag & Drop within ALV Grid Control
BCALV_GRID_DND_TREE- ALV Grid: Drag and Drop with ALV Tree
BCALV_GRID_DND_TREE_SIMPLE- ALV Grid: Drag and Drop with ALV Tree
(Simple)
6. Additional Data: To trigger some additional features of ALV Grid we can have some
additional data to pass as parameters. For example, initial sorting criteria (class used is
LVC_S_SORT), buttons to be deactivated, GUI Status and title etc.
IF g_dock1 IS INITIAL.
CREATE OBJECT g_dock1
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
side = g_dock1->dock_at_left
extension = 300.
CREATE OBJECT r_grid1
EXPORTING
i_parent = g_dock1.
ENDIF.
IF g_dock2 IS INITIAL.
CREATE OBJECT g_dock2
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
side = g_dock2->dock_at_bottom
extension = 100.
CREATE OBJECT r_grid2
EXPORTING
i_parent = g_dock2.
ENDIF.
Step2:
Take two internal tables and populate them with desired data.
For example:
it_tab, it_count.
Also fill the field catalog with corresponding structures of internal tables.
Step3:
Set internal table it_tab to grid r_grid1.
IF it_tab[] IS INITIAL.
CALL METHOD r_grid1->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = it_tab
it_fieldcatalog = gt_fieldcat.
ENDIF.
Step4:
Set internal table it_count to grid r_grid2.
IF NOT it_count[] IS INITIAL.
CALL METHOD r_grid2->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = it_count
it_fieldcatalog = gt_fieldcat1.
ENDIF.
Screen-shots for Output of ALV for displaying two internal tables in two different Docking
Containers along with Selection-screen:
we can display more than one internal table on the same screen as selection-screen unlike ALV
using Type-pool SLIS
SD FLOW IN SAP
SD PROCESS FLOW
1.Sales Inquriy
2.Quotation.
3.sales order.
4.Delivery/Shipping
5.Billing.
6. Invoice
sales order - Transaction VA01 - Tables VBAK, VBAP, VBEP, VBKD, VBPA, VBUK, VBUP.
Customer is returning...
Return order - Transaction VA01 - Tables VBAK, VBAP, VBEP, VBKD, VBPA, VBUK, VBUP.
Credit memo request - Transaction VA01 - Tables VBAK, VBAP, VBEP, VBKD, VBPA, VBUK, VBUP.
Customer was charged less money ..Meaning we want some money back from customer..
Debit memo request - Transaction VA01 - Tables VBAK, VBAP, VBEP, VBKD, VBPA, VBUK, VBUP.
MM FLOW IN SAP
MM Process Flow
1. Determination of Requirements
Materials requirements are identified either in the user departments or via materials planning
and control. (This can cover both MRP proper and the demand-based approach to inventory
control. The regular checking of stock levels of materials defined by master records, use of the
order-point method, and forecasting on the basis of past usage are important aspects of the
latter.) You can enter purchase requisitions yourself, or they can be generated automatically by
the materials planning and control system.
Purchase Requisition
ME51N – Create ME52N – Change ME53N - Display
2. Source Determination
The Purchasing component helps you identify potential sources of supply based on past orders
and existing longer-term purchase agreements. This speeds the process of creating requests for
quotation (RFQs), which can be sent to vendors electronically via SAP EDI, if desired.
Request for Quotation (RFQ)
ME41 – Create ME42 – Change ME43 – Display ME44 – Maintain Supplement ME45 – Release
Quotation
ME47 – Maintain ME48 – Display ME49 – Price Comparison
7. Invoice Verification
The system supports the checking and matching of invoices. The accounts payable clerk is
notified of quantity and price variances because the system has access to PO and goods receipt
data. This speeds the process of auditing and clearing invoices for payment.
----------------------------------------------------------------------------------------------------------------------
Integration Points for SD (Sales) and MM
1. During the creation of Sales Order Availability check is carried out which is integrated with
Inventory management
2. During the Delivery Creation the Stock is removed from the Inventory (Once u do Delivery a
material document is created triggering the Movement of material)
----------------------------------------------------------------------------------------------------------------------------
Display Document Flow & Status Overview are the two buttons on the right side of application
tool bar to click (See VA03 Display Sales order: Initial screen)
MM Cycle:
Purchase Requisition-> Staff in an organization places Purchase requisition for want of some
goods/products - ME51
Request for Quotation(RFQ)-> The Purchase dept in the organization calls/requests for the
quotation for the products against which PR was raised. - ME41
Vendor Evaluation->after receiving the RFQ's, after comparison a Vendor is finalized based on
the terms and conditions.
Purchase Order (PO) -> Purchase order was issued to that vendor asking him to supply the
goods/products -ME21N
Goods Receipt Note (GRN) ->Vendor supplies the material/Products to the organization
MB01
Goods Issue (GI) -> People receives their respective items for which they have placed the
Requisitions
Invoice Verification-> Along with the Material Vendor submits a Invoice for which the Company
Pays the amount - MIRO
In this article we will see of how to make the ABAP report an interactive one.
One way to make a report interactive is using ALV tool. I will give a brief idea of what ALV is all
about using OOPs concept.
The name itself indicates that the output view of a report is in the form of a list. This list
can be displayed in two forms
1. CL_GUI_ALV_GRI
2. CL_GUI_CUSTOM_CONTANIER
3. CL_GUI_SPLITTER_CONTAINER
4. CL_GUI_CONTAINER
5. CL_DD_DOCUMENT
6. CL_GUI_HTML_VIEWER
7. CL_ALV_CHANGED_DATA_PROTOCAL
CL_GUI_ALV_GRID: This class contains all the methods required to create an ALV and holds the
events required for the generated ALV. The methods in this class are useful for:
For instance, there may be a requirement in which top portion of the ALV Grid must hold the
company logo and some other details like date and user ID and the remaining part must hold
the loaded data. In this case we can use this class to split the container into two parts one for
holding the company details and the other contains all the records.
CL_GUI_CONTAINER: This class is also useful while splitting a container. Each container part
that is separated using the above class holds the form of this class.
CL_DD_DOCUMENT: This class is used to write text or labels or variables or logos etc., on the
container layout.
CL_ALV_CHANGED_DATA_PROTOCAL: If the ALV is in edit mode then the changed values can
be viewed through this class.
The following example demonstrates how to make use of the methods and events of
CL_GUI_ALV_GRID.
Note: This program is not specific to any application. It will give the basic idea of implementing
the double click, hotspot, data change, tool bar and user command events in ALV.
SAP Reports Interview Questions And Answers
How can validate input values in selection screen and which event was fired?
Answer1:
We can Validate Selection Screen With the Help of the Following Events, the Event Follows the
Same hierachy.
AT SELECTION-SCREEN ON
AT SELECTION-SCREEN ON BLOCK
AT SELECTION-SCREEN OUTPUT
AT SELECTION-SCREEN.
Answer2:
At selection-screen on
select stmt ------------------ where = .
if sy-subrc = 0.
validation success for LOw value in selection screen
At selection-screen on
select stmt-------------------- where =
if sy-subrc <> 0.
validation failure on high value in the selection field.
else
success.
endif
We can Navigate from basic list to secondary list with the help the event called AT LINE-
SELECTION. for every Secondary List the System Field SY-LSIND increases by 1. So there will be
Totally 21 list possible in SAP.
Answer1:
Domain: Defines the attributes such as length,type and possible value range.
Data element; An intermediate object between domain and table type
Answer2:
1)standered table
2)index table
3)hashed table
4)sorted table
Table controls have both horizontal and vertical scrollers and cursor control logic is designed
implicitly.
Step loops have only horizontal scrollers and cursor control logic is to be designed by the user
explicitly.
2.Bottom-to-top approach: In this approach, first domain and data element are defined and
later fields are defined.
get
put
get late
What are Difference Between Classical Batch Input and Call Transaction?
Answer1:
In Batch input many transactions can be executed, where as in Call transcation only one
transactioin can be executed.
BI is a background process, Ct can be either background or foreground .
BI is Synchronous process, Ct is both Asynchronous & Synchronous.
BI Sessions cannot be runed parallel.
Log file is generated automaticly in BI, errors can be found through BDCMSGCOLL.
Answer2:
1.batch input works for multiple applications where as call transactions doen't work
2.batch input has an implicit log file with it. where as call transaction doesn't have
3.batch input has sy-subrc check with the database where as call transaction doesn't have so
call transaction is fast.
How can you call the Sessions?
Yes, we can.
Just write in Line editor:
/:perform f_display_report
--------------
----------
----------
/:endperform
THIS PERFORM WOULD BE DECLARED IN THE PRINT PROGRAMME IN WHICH YOU CAN ALWAYS
WRITE STATEMENT
SUBMIT REPORT...
You can also upload a Logo in BMP format - it has to be saved as "%^ Colours if it is a colour
Bitmap.
If you don't save a colour Bitmap as 256 Colours then it will be uploaded in Black.
This can be done in Smart Forms, SAPScript or Transaction SE78
Question 1: What is the difference between User Exit and Function Exit?
User Exit Customer Exit
User exit is implemented in the form of a A customer exit can be implemented as:
Subroutine i.e. PERFORM xxx. Function exit
Example: INCLUDE MVF5AFZZ Screen Exit
PERFORM Menu Exit
userexit_save_document_prepare. Field Exit
Example: CALL Customer function ‘xxx’
INCLUDE xxx.
You modify this include.
In case of a PERFORM, you have access to You have access only to the importing,
almost all the data. So you have better exporting, changing and tables parameter of
control, but more risk of making the system the Function Module. So you have limited
unstable. access to data.
User exit is considered a modification and A customer exit is considered an
not an enhancement. enhancement.
You need Access Key for User Exit. You do not need access key.
Changes are lost in case of an upgrade. Changes are upgrade compatible.
User exit is the earliest form of change Customer exits came later and they
option offered by SAP. overcome the shortcomings of User Exit.
No such thing is required here. To activate a function exit, you need to
create a project in SMOD and activate the
project.
The way SMARTFORM is developed and the way in which SCRIPT is developed is entirely
different. Not listing down those here. That would be too much.
Question 4:What is the difference between Call Transaction Method and the Session
method ?
BAPI BDC
BAPI is faster than BDC. BDC is relatively slower than BAPI.
BAPI directly updates database. BDC goes through all the screens as a
normal user would do and hence it is
slower.
No such processing options are available Background and Foreground processing
in BAPI. options are available for BDC.
BAPI would generally used for small data BDCs would be preferred for large
uploads. volumes of data upload since background
processing option is available.
For processing errors, the Return Errors can be processed in SM35 for
Parameters for BAPI should be used.This session method and in the batch input
parameter returns exception messages or program for Call Transaction method.
success messages to the calling program.
Question 6: What is the difference between macro and subroutine?
Macro Subroutine
Macro can be called only in the program it is Subroutine can be called from other
defined. programs also.
Macro can have maximum 9 parameters. Can have any number of parameters.
Macro can be called only after its definition. This is not true for Subroutine.
A macro is defined inside: Subroutine is defined inside:
DEFINE … FORM …..
…. …..
END-OF-DEFINITION. ENDFORM.
Macro is used when same thing is to be done Subroutine is used for modularization.
in a program a number of times.
Question 7: What is the difference between SAP memory and ABAP memory?