1. Encapsulation --> binding data and member functions into single unit (class)
4. Execute select queries to read data from db into work area / internal table
5. Process the work area/ internal table to show the content (data) to the user
field 2, ename
----
wa_emp1-empno = 1.
wa_emp1-ename = 'Raju'.
wa_emp2-empno = 4.
wa_emp2-ename = 'Ramesh'.
2. Global class --> global to all objects ----> class builder tool (se24)
1. Definition of class
Syntax:
declaration of components.
endclass.
Note: if class definition contains method declarations, then we need to implement the class
2. Implementation of class
Syntax :
implementation of methods.
endclass.
Note: class definition and class implementation doesn't allocate any memory, it only
provides template of the class
Instantiate the class ---> creating the object for the class--> memory will be allocated
Syntax: create object <ref.name>. --> Memory will be allocated based on components of
class
Instance Attributes: In local classes they are declared by using the keyword “Data”.
They are specific to object i.e. for every object, separate memory will be allocated for each
instance attribute.
Static Attributes:
Constant Attributes:
In Local classes, they are declared by using the keyword ‘constants’. They must be
initialized at the time of declaration itself. The value of the constant attribute remains same
throughout the program. They are not specific to any object.
The memory for them will be allocated whenever the class is loaded in to the memory i.e.
memory will be allocated only once which will be shared by all the objects of the class.
They can be accessed either by using the object or by using the class name.
Types Attributes
In Local classes, they are declared by using the keyword ‘Types’. Types attribute
declaration only provides template, but doesn’t allocated any memory. To make use of
Types attributes, we need to create references based on types attribute declaration. These
references can be either a normal data attribute / internal table / work area.
Methods:
- A method is a set of statements which is implemented only once and can be called
any no. of times.
Method Parameters:
We can use the keyword ‘optional’ as part of local class method parameters to declare it as
optional parameter and in case of global class methods, select the checkbox ‘optional’
1. Declaration
syntax:
2. Implementation
syntax:
statements.
endmethod.
3. Calling
syntax 1:
syntax 2:
- In case of ABAP a method can return any no. of values. The no. of return values
depends on no of Exporting/changing Parameters.
Returning Parameters:
- To restrict a method to return exactly one value, we must use returning parameter.
They can access any kind of components of the class (instance / static / constant / types).
Static methods:
They can access only static components, constant attributes and types attributes. i.e they
cannot access instance components.
Note: In Local classes, the sequence of visibility sections (access specifiers) for the class
components should be in the order of public, protected, private sections.
Note: It is recommended to define and implement the local class at the beginning of
executable program and explicitly handle the event ‘start-of-selection’ after the class
implementation to indicate the starting point of program execution.
Me keyword: “Me” keyword refers to current object in execution i.e. as part of every
instance method execution (runtime), an implicitly created object (created by SAP) will be
available and it refers to the object which is currently executing the method.
Note: If a class contains both attributes and methods, it is recommended to declare
attributes under protected/private sections and methods under public sections.
Since we cannot access protected/private components outside the class, we need to access
them through one of the public method and call the public method outside the class.
Friend keyword:
In General outside the class, A Object can access only public components of the class
directly. i.e protected and private components of the class cannot be accessed outside the
class using an object of a class.
In order to enable the objects of the class to access all components of the class outside the
class irrespective of the visibility, then we can go for Friend classes.
In local classes “Friend” is a keyword used as part of class definition to consider another
class as friend.
Deferred Keyword:
As part of declaring local friend classes, we need to forward declare the friend classes by
using “Deferred” keyword. This deferred keyword indicates that the class definition is
provided somewhere else in the program and not at the beginning of the program.
Load keyword:
It is used to load the global classes explicitly in the executable program. This is mandatory
before the release 6.20 for accessing static components of the global class before
instantiating them.
From 6.20, it is not required, but in case, if we get any compilation error while accessing
the static components / any other components of global class, then we can load the global
class explicitly from the class library by using load keyword.
Constructor:
- It is special method used for initializing the attributes of the class i.e. whenever an
object is created, the attributes should be initialized with some initial values.
1. Instance constructor.
2. Static constructor.
Instance constructor
- It is specific to object i.e. whenever a new object is created SAP executes “Instance
constructor”.
- Instance constructor is executed only once in the life time of every object.
Static constructor
- It is executed only once in the life time of every class. I.e. it is executed in either
of the following case.
- Case 1: When we access any static components of the class before creating any
objects for the class. (or)
- Case 2: when we create first object of the class before accessing any static
components of the class.
Note:
If a class contains static and instance Constructor and if we instantiate first object before
accessing any static components, than SAP first executes Static Constructor and then the
Instance Constructor will be executed on behalf of that first object, from the second object
onwards only instance constructor will be executed.
If an instance constructor contains any mandatory importing parameters, we must pass the
values to those parameters while creating objects itself.
INHERITANCE
It is a process of using the properties (com ponents) of one class inside other class.
The main aim of Inheritance is Reusability of the components i.e. a component declared in
one class can be accessed by other class.
In Inheritance, two classes are involved (super class/base class and sub class/derived
class).
The class which gives properties is called as super class / base class.
Only Public and Protected components can be inherited i.e. Private Components cannot be
inherited.
Types of inheritance:
2. MULTIPLE INHERITANCE: A class acquiring properties from more than one entity
(interface).
Note: In ABAP, Multiple inheritance can be implemented using the combination of class
and interfaces.
Inheriting from – is a keyword used as part of local class definition for inheriting another
class.
A class declared as Final cannot be inherited i.e. it cannot have subclass. In case of local
classes, we use the keyword ‘final’ as part of class definition to declare a final class.
Polymorphism
Morph-> forms,
Ism-> behaviour
Example:
Method overloading, Method Overriding.
Method Overloading:
It is a process of overloading the same method by passing different Number and different
types of parameters.
Method Overriding:
- Whenever a local subclass wants to redefine the super class method, the sub class as
to re-declare super class method by using “redefinition” keyword.
- Whenever the super class method is redefined in subclasses, we cannot change the
visibility / category.
- Instance public / Instance protected methods declared as final can be inherited but
cannot be redefined.
- A static public/static protected methods cannot be declared as final because by
default, static methods cannot be redefined.
Hierarchy of constructor execution-scenario 1
- If a super class contains static and instance constructor and subclass without any
constructors, and if we instantiate first object of super class/sub class before
accessing any static components of super/sub class ,then SAP first executes static
constructor of super class and then instance constructor of super class and from
second object of super class/sub class only instance constructor of super class will
be executed.
- In this case, if we instantiate first object of sub class before accessing any static
components of super/sub class and before creating any objects for super class, then
SAP first executes static constructors from super class to sub class (top to bottom)
and then instance constructors from sub class to super class (bottom to top) and
from second object of sub class, only instance constructors will be executed from
sub class to super class.
If a super class contains instance constructor with mandatory parameters and sub class
also contains instance constructor with mandatory parameters and whenever we
instantiate the sub class, make sure that you pass values for the parameters of sub class
instance constructors and from sub class instance constructor implementation we need to
call super class instance constructor by passing values for parameters of super class
instance constructor.
If a super class contains instance constructor with mandatory parameters and sub class
without any instance constructor and whenever we instantiate the sub class, make sure
that you pass values for the parameters of super class instance constructors and from sub
class instance constructor implementation we need to call super class instance constructor
by passing same values for parameters of super class instance constructor.
Public classes:
- Public class can be instantiated anywhere (within same class/ inside subclasses
/outside classes).
- The subclass inheriting the super public class is also created as public by default.
- The sub class inheriting the super public class can be created as explicit
protected/private.
Protected classes:
- Create protected is the keyword used as part of local class definition to create the
protected classes.
- Protected classes cannot be instantiated outside the classes but they can be
instantiated inside same classes as well as inside subclass methods.
- The subclass inheriting protected class can be created as explicit public class (or)
private class.
Private classes:
- Private class cannot be instantiated outside the classes and inside subclasses, but
they can be instantiated within the same class. In order to instantiate private classes
inside subclasses or inside any other independent class, the private super class
should consider sub class / independent class as friend.
- The subclass inheriting the private class is also created as private by default.
- By default, the subclass inheriting the private class cannot be created as explicit
public class / explicit protected class. This can be made possible if the super private
class considers subclass as friend.
Friend keyword:
In local classes “Friend” is a keyword used as part of class definition to consider another
class as friend.
In this case friend class should be forward declared by using “Deferred” keyword. This
deferred keyword indicates that the class is defined somewhere else in the program and
not at the beginning of the program.
ABSTRACT CLASS:
- We declare a method as abstract when we are not sure about the implementation.
- The implementation for the abstract methods can be provided as part of subclasses.
- If a class contains an abstract method, the class also should be declared as abstract.
- The subclass whichever is inheriting the abstract class must implement all the
abstract methods of the abstract super class otherwise the subclass also should be
declared as abstract.
- We cannot create the objects for abstract classes because they are not implemented
completely. But once abstract methods are implemented inside subclass, we can
instantiate the subclass and assign subclass object to abstract super class reference
which is called as narrow casting.
- Whenever narrow casting is done, by using super class object we can access
methods of super class only, in order to access direct methods of subclass using
super class object, we need to call the subclass method using dynamic calling
approach.
INTERFACES
- An interface is a pure abstract class i.e. by default all the methods of interface are
abstract.
- Interface components doesn’t contain any explicit visibility section, by default all the
components are public.
- The class which ever implements the interface is called as implementation class.
- If a class implements any interface and if that implemented interface contains any
included interfaces, then class must also implement all the methods of the included
interfaces.
- If a global class has to implement one or more global interfaces, then global class
must declare those interfaces in the interfaces tab.
Aliases
Aliases are the alternative names provided for interface components .i.e. whenever we
refer to the interface components outside the interface, it must be prefixed with the name
of the interface. This lengthy naming representation can be avoided by declaring “aliases”
for interface components.
- Aliases can be declared in any of the visibility sections inside implementation class
- If the aliases as to be declared in the interface it can be declared only for included
interfaces components and that alias will be created as component of interface.
Note: The included interfaces can be referred directly in the implementation class .i.e. the
interface which is included in other interface can be directly referred in the
implementation class.
Note: As Part of global classes, If a global class Includes any interface in the interfaces tab
and the checkbox ‘final’ is selected, it indicates that these interface methods cannot be
further implemented (re-defined) in other classes.
1. Generate the Selection screen for reading user input (Parameters / select- options)
3. Retrieve the data from database table/s into internal tables/work areas using Select
Query
a. REUSE_ALV_LIST_DISPLAY
b. REUSE_ALV_GRID_DISPLAY
Procedure for ALV reporting using function modules:
1. Declaration
2. Retrieve data
4. Display
As part of the function module “REUSE_ALV_GRID_DISPLAY” there is only one
mandatory parameter ‘T_OUTTAB’. This parameter holds the internal table containing
data. If we pass only this parameter value as part of F.M call, it leads to “Abort Error-
Field Catalog Not Found”. The reason for this error is, we must specify the “field
catalog “information. This information can be specified in two ways.
It is an object which contains the information’s of the fields display in the “ALV Grid”. This
information includes name of the field, position, label, grid, appearance etc. To specify the
field catalogue information using the dictionary structure, we need to use the importing
parameter “I_STRUCTURE_NAME” as part of the function module
“REUSE_ALV_GRID_DISPLAY”. Whenever this parameter is specified all the properties of
the field are taken from dictionary itself.
The structure name passed must match with the format of internal table i.e. the no of fields
and sequence of fields in the structure and in the internal table must match otherwise it
leads to runtime error.
- This internal table holds the events information (refer to the document of the
parameter ‘IT_EVENTS’ to get the events list).
This event is triggered when the user double clicks on ALV cell value (or) single click on
hotspot cell value. This event contains two parameters.
Step 2:
In OAER Transaction -> enter the values in following below.
Class name -> pictures.
And execute.
Step 3:
In the next screen , in the top pane, choose ‘pictures’, and in bottom pane, -
>doctype->expand->standard doc types->double click on ‘screen’ entry->choose
filename (logo file) from local drive->continue.
Blocked ALV:
1) Reuse_alv_block_list_init.
2) Reuse_alv_block_list_append.
3) Reuse_alv_block_list_display.
Procedure:
Step 1:
“Reuse_alv_block_list_init”.
Step 2:
Step 3:
Append the field catalog and the data to the blocked list using the function module
“Reuse_alv_block_list_append”.
Note:
Note: Reuse_alv_events_get is the function module which returns list of events supported
in ALV function modules.
Hierarchical ALV:
It is used for displaying the report in the form of header and items.
I_TABNAME_HEADER
I_TABNAME_ITEM
IS_KEYINFO
Setting variants:
Variants keeps track of the changes made to the alv layout in the runtime.
To choose the appropriate variant in the runtime we can use the function module
“reuse_alv_variant_f4”.
To get the default variant we can use the function module “reuse_alv_variant_default_get”.
To save the state of the layout in the runtime we need to set the following parameters.
a) I_save and
Whenever we display the data in the form of ALV report, we need to provide field catalog
information; otherwise the report execution leads to ABORT error. In case of ALV reporting
using classes, we can generate field catalog in 2 ways.
2. Manually
Note: In either of the above 2 process, once the fieldcatalog is generated, we need to pass it
as a value to the parameter ‘IT_FIELDCATALOG’ as part of the method call
‘SET_TABLE_FOR_FIRST_DISPLAY’.
For this we need to identify the function codes of the ALV toolbar buttons and prepare an
internal table with those function codes and pass the internal table as a value to the
parameter “IT_TOOLBAR_EXCLUDING” of the method “SET_TABLE_FOR_FIRST_DISPLAY”.
All the ALV toolbar buttons function codes exist in the form of constant public attributes
with the naming standard ‘MC_FC…’ of the class ‘CL_GUI_ALV_GRID’.
Note: For excluding entire ALV toolbar in the Report, set the field ‘NO_TOOLBAR’ to ‘X’ as
part of Layout.
For displaying the entire ALV column as pushbutton, set the field ‘STYLE’ as part of field
catalog. All the styles exist in the form of constant attributes with the naming standard
‘MC_STYL’ as part of the class ‘CL_GUI_ALV_GRID’.
For coloring the entire ALV column, set the field ‘EMPHASIZE’ to a color coding as part of
field catalog.
ALV Row Coloring:
Procedure:
Step1:
Take an additional column in the final internal table which is of type char4.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the
color coding for the additional field based on the condition.
As part of layout generation, set the field “info_fname” whose value is name of the
additional field which holds the row color coding.
Procedure:
Step1:
Take an additional column in the final internal table which is of type ‘LVC_T_SCOL’.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the
color coding for the additional field based on the condition.
For this, we need to prepare work area of type ‘LVC_S_SCOL’ and append the same to
the additional field and update the internal table.
As part of layout generation, set the field “ctab_fname” whose value is name of the
additional field which holds the cell color coding.
Splitter control
Each “PANE” should be associated with a container to hold an object. The object can be ALV
Grid, Image and Tree.
Step 1:
In SMW0, choose the radio button ‘binary data for webrfc applications’, click on ‘FIND’
(appl.toolbar) provide package name(any package), object name (any name, unique id)
description(…), click on execute click on ‘create’ button (appl.toolbar),provide object
name (ZBT), description(…), click on ‘import button’ (status bar of dialog box)
Step 2:
This function module takes an image object id as input and returns the “URL” of picture
which is of type “cndp_url”.
Note:
Step 3: Create the object of picture class ‘CL_GUI_PICTURE’ linking with a container.
Step 4: call the instance method “load_picture_from_url” of the class “cl_gui_picture”. This
method takes URL of the picture as input and displays the picture in the container.
- We can add the nodes to the tree control by using the instance method “add_nodes”
of the class “cl_gui_simple_tree”.
Procedure:
Step 1:
Take an additional column in the final internal table, this additional column needs to be
displayed as dropdown.
Step 2:
Prepare an internal table of type ‘LVC_T_DROP’ with drop down handle and dropdown
values and pass this internal table as a parameter to the method
‘SET_DROP_DOWN_TABLE’ of the class ‘CL_GUI_ALV_GRID’.
- These traffic lights by default are displayed as First column of the ALV report.
- Traffic light codes are 3 types (1-Red, 2-Yellow, 3-Green) and also we can refer to
the constant values in the ICON type-group.
Procedure:
Step 1:
Take an additional column in the final internal table which is of type character of “One”.
Step 2:
Before displaying the final data, loop the internal table and set the traffic light code for
an additional column.
Step 3:
As part of layout, set the field “EXCP_FNAME” the value of the field should be “Name of
the additional column” containing traffic light code.
Note: By default, Traffic light column is displayed in first column position. To display
traffic light in a specific column position, declare an additional column of type character
with some length, generate field catalog for this column including required column
position and assign traffic light code to its column value. In this case, we should not set
the field ‘EXCP_FNAME’ in layout.
Custom event handling process:
3. Raised by SAP itself depending on user actions (from. The std. methods)
Note:
1. To Display ALV column values as link, we need to set the field ‘HOTSPOT’ as part of
field catalog for that particular field.
5. As part of interactive ALV reporting using classes, when the user interacts and
navigates from one screen to another screen, we need to refresh the grid with the
corresponding internal table data using the method ‘REFRESH_TABLE_DISPLAY’ of the
class ‘CL_GUI_ALV_GRID’.
TOOLBAR Event: is the instance event of the class ‘CL_GUI_ALV_GRID’ which is triggered
when the ALV grid is displayed. This event can be used to manage the ALV Toolbar for
Enabling/Disabling standard ALV Toolbar buttons, Adding custom buttons.
Note:
1. To enable multiple selection of rows on ALV grid, we need to set the field ‘SEL_MODE’
TO ‘A’ as part of layout
2. To identify the selected rows on the ALV grid, we need to use the instance method
‘GET_SELECTED_ROWS’ of the class ‘CL_GUI_ALV_GRID’. This method returns the
internal tables containing the indexes of selected rows.
1. For the ALV column to be editable, set the field edit to ‘X’ As part of field catalog,
2. Handle the event ‘DATA_CHANGED’ of the class ‘CL_GUI_ALV_GRID’. This event is not
triggered by default as it is a system event, it requires explicit registration and it is done
by calling the instance method ‘REGISTER_EDIT_EVENT’ of the class
‘CL_GUI_ALV_GRID’. This method takes event id as a mandatory input parameter. These
event ids exist in the form of constant attributes of the grid class and we can use any of
the following attribute event ids.
a) Mc_evt_modified Allows only single cell editing, in this case the event
‘DATA_CHANGED’ is triggered when the user shifts the focus from the first modified
cell or when the user presses enter key in the first modified cell.
b) Mc_evt_enter -> Allows multi cell editing, in this case the event is triggered when the
user presses enter key in the last modified cell.
3. As part of the event handler method, we need to import the event parameter
‘MC_EVT_MODIFIED’ and using this event parameter (object) access the instance
attribute (internal table) ‘MT_MODIFIED_CELLS’ which keeps track about the
information of the modified cells which includes row_id and modified value. Based on
this, update the grid internal table as well as corresponding database table.
For this, we need to handle the event ‘TOP_OF_PAGE’. It is the instance event of the class
‘CL_GUI_ALV_GRID’ used for generating content in the TOP OF PAGE area of ALV Grid. This
event is not triggered by default; it should be registered explicitly by calling the instance
method ‘LIST_PROCESSING_EVENTS’ of the class ‘CL_GUI_ALV_GRID’.
Procedure:
Step1:
Take an additional column in the final internal table which is of table type “LVC_T_STYL”.
Step 2:
Before displaying the final data in the ALV grid, loop the final internal table and set the
button style (MC_STYLE_BUTTON) to ALV cells based on the condition.
As part of layout generation, set the field “style_fname” whose value is name of the
additional field which holds the style.
- Exception handling is a process of handling the Runtime Error’s and continues the
program execution without termination.
- The exceptions which are raised by SAP are called as Standard Exceptions.
- These standard exceptions are raised from standard exception classes which start with
Naming convention “CX___”.
- Inside the “TRY” Block we need to keep those statements where the possible exceptions
might occur.
- The ‘CATCH’ block is placed immediately after the Try Block; it is responsible for
handling the exceptions by providing appropriate exception handling statements which
can be system defined exception message / user-defined exception message.
- “CX_ROOT” is common for any exceptions i.e it is super class for all exception classes.
- As part of the catch block we need to provide the exception class name which is
responsible for raising the exception.
- If we are not sure about the exception class, we can give the exception class name as
“CX_ROOT”.
Note:
Whenever an exception is raised in a “TRY” block, SAP creates the object of the exception
class which is raising the exception and the control will jump to catch block.
As part of catch block, we need to receive the exception class object into our local reference
of exception class and using this referenced object we can access the appropriate methods
of Exception class to capture standard exception messages.
Whenever an exception is raised in try block, SAP ignores the rest of the statements in the
try block and the control will jump to catch block.
Standard Exceptions:
Cleanup block:
Cleanup block is provided as part of try block to execute certain statements mandatorily
whenever an exception is raised in the try block. In general, whenever an exception is
raised in the try block, the control jumps to catch block ignoring the rest of the statements
in the try block. In these cases, there might be certain statements which we need to execute
whenever an exception is raised, these statements we can provide as part of cleanup block.
If a try block contains cleanup block, we cannot have catch block, so in order to handle the
exception, catch block should be provided as part of outer try block. As part of cleanup
block, we can perform cleanup activities. i.e clearing the variables, free internal tables, close
the files…….
We should not abruptly terminate the execution of cleanup block using the statements
stop, submit and call transaction statements.
User-defined exceptions in methods:
Procedure
3. Handle the exception while calling the method by checking the sy-subrc status.
Note: We can use ‘raise’ keyword to raise any exceptions i.e system defined or user-
defined.
Raising keyword:
Raising is a keyword used as part of local class method declaration to indicate that a
method might raise the exception but cannot handle the exception.
In these cases, the caller of the method should take the responsibility of handling the
exception.
The advantage of this approach is since a method can be called any no. of times at different
places in the object, at each place, we can handle the exception in different way (custom
defined exception messages in one place, std. exception messages in another place..)
We create custom exception classes to store the repository of custom exception messages
Global custom exception classes starts with ‘ZCX_....’ / ‘YCX_....’ and it must be subclass of
‘CX_STATIC_CHECK’ / ‘CX_DYNAMIC_CHECK’ / ‘CX_NO_CHECK’.
Each Exception id must be associated either with OTR Text / with message of a message
class.
In case of Exception classes using OTR, each exception id that we create must be associated
with short text / long text / both.
In case of Exception classes using message class, each exception id that we create must be
associated with message id of a message class which can be static / dynamic message.
In case of Dynamic message, we need to create corresponding attributes for mapping to the
place holder of dynamic message.
The values for these attributes associated with placeholders should be passed at the time of
raising the exception.
Note: A Try block can be associated with ‘n’ of catch blocks, but the catch block exception
classes should be in the ascending order of exception classes i.e from sub class to super
classes.
Singleton class:
It is a class for which only one object can be created. It uses Singleton Design pattern.
Persistence service
It is used for storing the state of object (values of the object) permanently in the database.
By default, the life time of the object is local to the program i.e. once a program execution is
completed, memory allocated for the object will be destroyed.
Any database operation (CRUD operations) can be achieved by using “persistent service”.
Base agent class: is a friend of persistence class and it is super class of ACTOR class.
- In this, we need to consider a database table in which the primary key field of the
table is considered as “Business key identity”.
1. Consider a db table.
Table: z730emp
Fields:
3. Map the Persistence class with the Corresponding data base table. (goto
persistence representation)
Note:- We must Map all the fields of the db table to the persistence class (double
click on each field and click on ‘set attribute values’ button)
Note: Once the mapping is done, all the fields of the table will be added as attributes
of the persistence class.
- Apart from this, SAP GENERATES “GET_” Methods for all attributes and “SET_”
methods for non-primary key fields.
- Getter method is used for reading the value of the attribute and Setter method is
used for setting the value to the attribute.
4. Activate the persistence class so that dependent classes also get activated.
5. As part of this activation, SAP generates the following methods as part of base agent
class.
1. Create _Persistent
2. Delete_Persistent.
3. Get_Persistent
- To access the above 3 instance Methods we require object of base agent class, but
the base agent class is created as “Abstract class”. So, it cannot be instantiated
directly.
- The above 3 methods are public and they are inherited to sub class which is Actor
Class or Agent class.
- But, Actor class IS created as “Private Class”, so, it cannot be instantiated directly
outside.
- Actor class is created as Singleton class, so there is a possibility of creating one and
only one object. So in order to get the object of the Actor class we must follow the
following Procedure.
- As part of every Actor class, SAP Provides Static Public Attribute “Agent”. This
attribute is marked as ‘Read only’ i.e this attribute will return a value whenever it is
accessed.
- Whenever this attribute is accessed by using Actor class name , internally SAP
Executes Static Constructor of Actor class which is Responsible for creating
singleton (single object) of actor class, This object will be returned back to the static
attribute agent, we need to receive this returned object so that we can access the
above 3 methods.
- In this we need to consider a database table whose first field is GUID and the
corresponding data element should be “OS_GUID”. The value for this field “GUID”
will be dynamically generated by SAP itself.
- We need to map the persistence class with this database table. After Mapping,
except “GUID” field all the remaining fields will be added as attributes of the
persistence class.
- Apart from this, SAP Generates “Getter” &”Setter” methods as part of persistence
class for all the fields except “GUID”.
- When we activate the persistence class, SAP generates the following 3 Methods as
part of “BASE AGENT CLASS”.
1. Create_Persistent.
2. IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID
3. IF_OS_FACTORY~DELETE_PERSISTENT.
Procedure for creating Persistence service using GUID:
Table: Z8AMEMP
Fields:
EMPNO zeMPno
ENAME zename
EMPDESIG zempdesig
In persistence service using GUID the uniqueness of the object is controlled based
on the GUID field.
GET_PERSISTENT_BY_OID:
This method takes GUID as input and returns the object of the object class. This object class
in the runtime points to persistence class, so we need to type cast the object class object to
persistence class object. Using the persistence class object access the required getter
methods.
DELETE_PERSISTENT:
This method takes the object of the interface ‘if_os_state’ as input value, but we cannot
directly create objects for interfaces, so we need to analyze what is the implementation
class which is implementing this particular interface. As per the analysis, it is the
persistence class (zcl_9am_empl) which is implementing the interface ‘if_os_state’, so we
can pass the object of this persistence class as a parameter value. In order to get the object
of persistence class, first of all we have to check whether the “GUID” is existing or not this is
done by calling the instance method “Get_Persistence_By_Oid” .This method returns object
of the object class, this object class object needs to be type cast to persistence class object
and pass that object as parameter to “Delete_Persistent”.
The main use of this service is we can mark the begin of and end of OO transaction, so that
we can either save (commit) the complete transaction or cancel (rollback) the complete
transaction. As part of this transaction service, we use the following class and interfaces.
2. if_os_transaction
3. if_os_transaction_manager
1. Get the transaction manager object: This is done by calling the static method
'get_transaction_manager' of the class 'cl_os_system'
2. Using the above transaction manager object, get the transaction object. This is done by
calling the instance method 'create_transaction' of the interface 'if_os_transaction_manager'
3. Using the above transaction object, mark the start of OO Transaction. This is done by
calling the 'start' method of the interface 'if_os_transaction'
5. Try to end the transaction by calling the instance method 'end' of the interface
'if_os_transaction'. If the transaction fails, cancel the transaction by calling the method
'undo' of the interface 'if_os_transaction.
Note: The above steps are provided by SAP as part of interface documentation
‘IF_OS_TRANSACTION’.