Sie sind auf Seite 1von 49

 Object Oriented Program- http://www.beginners-sap.

com/object-
orientation-abap/
Different types of programming structures
1. Unstructured Programming
2. Procedural Programming
3. Object Oriented Programming

1. Unstructured programming: -
 The entire program contains only one mail.
 The same set of statements is placed in multiple locations of the same program.
 It’s very difficult to maintain if the program becomes very large.
2. Procedural programming: -
 The entire program is spitted into smaller programs.
 The same set of statements is placed in a procedure (Subroutines or Function Module) & later we
call the same procedure from different locations of the same program.
 All the subroutines & function modules can access the global declarations.
 It take little bit extra time to enhance the existing functionality.
3. Object Oriented Programming: -
 The entire program is visualized in terms of class & objects
 All the methods can’t access the global declarations.
 It takes very less time to enhance the existing functionality.

 Key features of object oriented programming: -


1. Better programming structure
2. Most stress on data security & access
3. Reduce the redundancy of code
4. Data abstraction & encapsulation.
5. Inheritance and polymorphism
The main feature of Object Oriented programming is representing real-time objects in the form of
class objects.
 Class
A class is a user defined data type with attributes, methods, events, user-defined types, interfaces etc
for a particular entity or business application .
Class is the blueprint or template of an object. Object is the real one.
 Object
Objects are nothing but instances of classes, each object has a unique identity that is memory and
it`s own attributes.
EX: - If you want to build a form house then we take a plan from engineer to build the form house.
It’s nothing but class. Based on the plan constructed house is an object.
Note: - Based on one class we can create any number of objects.
There are two types of classes.
1. Local Class – se24
2. Global class –se24
Attributes: -
Attributes are used to declare the variables, work areas, internal tables which are needed to
implement the logics.
Methods:
- Method is the collection of statements which perform the particular activity or provides some
functionality.
Events: -
Events are used to handle the methods of some other class.
Event is a mechanism by which method of one class can raise method of another class, without the
hazard of instantiating that class.
1. Public Section: - We can access the public components within the class as well as outside the class.
2. Protected section: - We can access the protected components within the class as well as derived or
child class.
3. Private section: - We can access the private components within the class only.
Note: - In ABAP we haven’t default visibility section.
Instance and Static Components
Instance components : These components exist separately in each instance (object) of the class and
are referred using instance component selector using ->
Static components : These components exists globally for a class and are referred to using static
component selector => .
Static methods cannot be Redefined
Interface
Interface is the collection of methods which are defined & not implemented. Interfaces are mainly
used to extend the scope or functionality of the class. by using interface concept in SAP ABAp, we
can achieve multiple inheritance
Me Variable
It just like a selfreference, by this we can call methods that are with in same class with out creating
object.
Limitations of redefining a method
Inherited methods can be redefined in subclasses Redefined methods must be re-implemented in
subclasses. The signature of redefined methods cannot be changed Static methods cannot be
redefined. In inheritance, static components are "shared": A class shares its non-private static
attributes with all its subclasses. In ABAP Objects, you can not only add new components, but also
provide inherited methods with new implementations. This is known as redefinition. You can only
redefine (public and protected) instance methods, other components (static methods, attributes and
so on) cannot be redefined. Changes to method parameters (signature changes) are not possible

The main use of interfaces is re-usability and maintain standard project framework
Abstract class
Abstract class is a class which contains at least one abstract method( Method without
implementation), Abstract class contains methods with implementation and without implementation
and we cannot create instance for the abstract class .
Abstract class is mainly for inheritance. No it is not mandatory to implement all normal interface
methods but it is mandatory to implement all Abstract method
Abstract Class is a special kind of class which can’t be instantiated. We can only instantiate the
subclasses of the Abstract class if they are not abstract.
Differences
Since both abstract class and interface are different entity, they have few differences:
Multiple Inheritance:We can achieve multiple inheritance using Interfaces. Since ABAP doesn’t
support more than one Super class, we can have only one abstract class as Super class.
New Functionality:If we add a new method in the Interface, all the implementing classes have to
implement this method. If we don’t implement the method, it would result into Run-time error. For
Abstract class, if we add a non-abstract method, its not required to redefine that in each and every
inherited class.
Default Behavior:We can have a default behavior of a non-abstract method in abstract class. We
can’t have any implementation in Interface as it only contains the empty stub.
Visibility:All interface components are PUBLIC by default. For Abstract class, we can set the visibility
of each component.

Alias
Alias is an alias name for the interface method implemented in the class . Aliases is a concept of
providing alternate method names for interface methods in implemented class(where interface is
implemented).
Inheritance
Inheritance is the concept of passing the behavior of one class to another class.
NOTE: In Object Oriented ABAP we have only single inheritance. There is no multiple inheritance.
Inheritance in general
Super Class Is a main class by using this we can derive a new class which will be called as Child class.
Final Class is a class which can not be used for inheritance, it is a class property (check box under
properties of class).
Polymorphism
It is a concept by which the same method names will behave differently in different classes i.e each
method will have its own implementation in different different classes but with the same name.
Interface is one of the concept in Object Oriented ABAP to achieve Polymorphism.
Overloading
Overloading allows to change the signature of the inherited methods in the subclasses. ABAP doesn't
support Overloading.Only exception is the CONSTRUCTOR method. Since we can create
CONSTRUCTOR method in each subclass, we can change the signature of this method.
Overriding
Overriding allows to change the functionality of the inherited methods. This is also known as the
redefinition.
Association
Association defines a relationship between different objects of different classes which allows one
object instance to cause another to perform an action on its behalf.
Modularity
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely
coupled modules.
Binding
Binding denotes association of a name with a class.
static binding
Static binding is a binding in which the class association is made during compile time. This is also
called as Early binding.
Dynamic binding
Dynamic binding is a binding in which the class association is not made until the object is created at
execution time. It is also called as Late binding.
Aggregation
Aggregation is a special form of association. Aggregation is the composition of an object out of a set
of parts. For example, a car is an aggregation of engine, tyres, brakes, etc.
Aggregation represents a "Has" relationship like a car has a engine.
Friends
In any Object Oriented programming language, the access to private or protected components –
both methods and attributes – would be prohibited. If someone try to access them, compiler would
generate syntax error.
Sometimes, it would be advantageous to give the access to these protected and private attributes to
other classes. This can be achieved using the FRIENDS addition.
Constructor in a class
CONSTRUCTOR is a special type of method, it is executed automatically whenever a object is created
or instantiated.
These methods are mainly used to set default values in classes.
CONSTRUCTORS are two types in SAP classes.
CONSTRUCTOR ( Instance Constructor).
CLASS CONSTRUCTOR (Static Constructor).
CONSTRUCTOR.
These methods can only have importing parameters, there will not be any exporting parameters.
The name of the CONSTRUCTOR method must be CONSTRUCTOR only.
CLASS CONSTRUCTOR (Also called as STATIC CONSTRUCTOR).
It is a type of constructor, this method will be executed automatically whenever a first call to the
class is made, the first call may be through instance or through class.
These CLASS CONSTRUCTORS are mainly used to set the default values globally i:e irrespective of
instances, these methods will not have any importing and exporting parameters. These methods will
be executed only once.
Name of the CLASS CONSTRUCTOR must be CLASS_CONSTRUCTOR.
If we have both CONSTRUCTOR and CLASS_CONSTRUCTOR in our class, upon a class call which will
trigger first.....First CLASS_CONSTRUCTOR will be triggered.

Singleton pattern :
is the one of the simplest design patterns which involves only one class which instantiates itself to
make sure that it creates one instance.Singleton ensues that it has only one instance and provides
global point of access to the object.
Example - Logger Classes
The Singleton pattern is used in the design of logger classes. This classes are usually implemented as
a singletons, and provides a global logging access point in all the application components without
being necessary to create an object each time a logging operations is performed.
Steps to be followed to create singleton class
Create a private class.
Add a private attribute with reference to the same class static.
Create a public static method with returning value of type reference to same class.
Create implementation and create object in the implementation of public static method.
Call static method in any program to create instance for the singleton class.
Type of classes created
Usual Abap Class.
Exception Class(With/Without messages).
Persistent Class.
Test Class(ABAP Unit).
reference variable
Objects can only be created and addressed using reference variables. Reference variables allow you
to create and address objects. Reference variables can be defined in classes, allowing you to access
objects from within a class.
the advantages of OOPs?
The major advantages of OOPs are:

Feature Description
Software objects model real-world objects, so the complexity is reduced and the program structure is
Simplicity
very clear.

Each object forms a separate entity whose internal workings are decoupled from other parts of the
Modularity
system.

It is easy to make minor changes in the data representation or the procedures in an OO program.
Modifiability Changes inside a class do not affect any other part of a program since the only public interface that
the external world has to a class is through the use of methods.

Adding new features or responding to changing operating environments can be solved by introducing
Extensibility
a few new objects and modifying some existing ones.

Maintainabilit
Objects can be maintained separately, making locating and fixing problems easier.
y
Re-usability Objects can be reused in different programs

defination Deferred’ Keyword In Ooabap ?


It is the keyword which indicates the class definition is delayed or postponed or Defined at some
place in program.
Syntax : CLASSÂ Â DEFINITION DEFERED
Narrowing Cast
The assignment of a subclass instance to a reference variable of the type “reference to superclass” is
described as a narrowing cast, because you are switching from a more detailed view to a one with
less detail.
Widening Cast
The widening cast is, as with inheritance, the opposite of the narrowing cast: Here it is used to
retrieve a class reference from an interface reference.
Standard class enhancement
Sometimes we come across a requirement which cannot be solved using available standard methods.
In such cases we can either enhance the existing method or go for our custom development. This
document explains how to add a custom method to a standard global class and how to enhance an
existing method using exits. Below are three different exits available to enhance a standard method:
1. Pre-Method Exit: Implement this exit if we want to execute our custom logic before standard
method gets executed.
2. Post-Method Exit: Implement this exit if we want to execute our custom logic after the standard
method gets executed.
3. Overwrite-Method Exit: If we want to completely replace the standard logic then this exit should
be implemented.
Some of the main advantages of Object Oriented ALV
We have no of events available in the classes when compared to ALV with function modules which
gives flexibility for the programmer to develop ALV'S for various scenarios.
We can display more than one ALV grid data on a single screen.
The ALV grid data is displayed in the form of custom container with which we can control the size of
ALV grid Whereas we cannot control the size of the ALV with function Modules.
We can also place different UI elements like checkbox, Radiobutton on the same screen in addition
ALV grid data.
Abap Architecture –
SAP is a type of software known as ERP (Enterprise Resource Planning) that large company use to
manage their day to day affairs. ABAP (Advanced Business Application Programming) is the coding
language for SAP to develop RICEFW objects. (Reports, Interfaces, Extensions, Forms and Workflows).
LUW –
The main purpose of the logical unit of work is to ensure data consistency in the R/3 systems.
Database LUW also known as DB LUW, each dialog step has its own DB LUW that is used to ensure
data consistency. database LUW is an inseparable sequence of database operations that ends
with a database commit. The database LUW is either fully executed by the database system
or not at all. Once a database LUW has been successfully executed, the database will be in a
consistent state. If an error occurs within a database LUW, all of the database changes since
the beginning of the database LUW are reversed. This leaves the database in the state it was
in before the transaction started.
SAP LUW
becomes critical in maintaining a logical relationship between several DB LUWs (dialog
phases) & making all the changes to the database in the final DB LUW.

Component 4: Work Process (WP)


The Work Process is the actual transaction processing area in an application.
Dialog
ABAP processor
Database Interface
Data Dictionary
To describe the logical structures of the objects that are used in application development ABAP 4
data dictionary is used. Data dictionary is the central source of the database management system.
The main functionality of the DDIC is to create or alter the tables.
data class
It specifies the physical area of a table in the database, the following options are available
under data class
APPL 0 Master data class
APPL 1 Transaction data class
APPL 2 Organization data class
delivery class in ABAP Dictionary
It specifies the type of data stored in a database table system data etc. It defines the owner
of the table as well as it controls the transport of the data from one table to another table.
ex: Application ( master data, Transaction data)- A, Customizing C,L system data
size category in Data Dictionary?
It specifies the number of records that can be stored in a database table, options available
under size category are below.
Transparent table
There is a physical table on the database for each transparent table. The names of the
physical tables and the logical table definition in the ABAP/4 Dictionary correspond. All
business data and application data are stored in transparent tables. Transparent tables are
one to one relationship. That is if you create one transparent table in the data dictionary, then
it’ll store like only one data base table in the data base.
Pooled table
Pooled tables can be used to store control data (e.g. screen sequences, program parameters
or temporary data). Pooled tables are many – one relationship. That means if you create many
pooled tables in DDIC, then they will form like a table pool & stored in the data base.
Cluster table
Cluster tables contain continuous text, for example, documentation. This tables are many –
one relationship. That is if you create the many clustered tables in DDIC then they will form like
a table cluster & store in the data base. Buffering isn’t possible for clustered table. From this
reason only fetching the data from clustered table take more time.
Clustered table is suitable when you fetch the fewer amounts of data from more fields.
Joins aren’t possible for Clustered & Pooled tables, (create table Extra table category, other
utilities for table pool)
Validation Type
Field Level validations:
We can validate entries at field level with the help of check table concept.
Domain level validations:
We can restrict entries at the domain level with the help of fixed values of the domain and
value table of the domain.
What is a check table?
It is a table which contains all valid entries of a field.
What is value table?
It is a table which contains all valid entries of a domain, this domain can be reused in
multiple tables.
T006 is the standard data base table which contains all the unit of measurements, SAP
domain “MEINS” into our field domain
“TCURC” is the standard data base table which contains all the currencies, SAP domain
“WAERS” into our table field domain
DATA : <ITAB> TYPE TABLE OF <DBTABLE> .
CLEAR is used to clear a value in a work area or in a variable.
REFRESH is used to clear all values in an internal table.
FREE is used to clear (free) memory of an internal table or work
area. We all know whenever we declare an internal table or work
area, 8kb memory will be allocated.

Standard Internal tables Sorted Internal Tables Hashed Internal tables


These are default These are a special type of internal These are used with
internal tables. tables, where data is already(auto) logical databases i:e
sorted as you insert the record with all fields and all
records.
To read a record we use To read a record we use either key Here the index
either key or index or index operation. operation is not allowed,
operation. we only use key
operation.
To search for a record, To search for a record, we use binary To search for a record,
we can use either linear search as data is already sorted. we use hashed
search or binary search. algorithm.
We can use sort We do not use sort as data is -
operation. already sorted.
We can use insert and We only use insert, not append. These are mainly used in
append to add records. ABAP with BI projects
SELECT SINGLE SELECT UP TO 1 ROWS
Used to read exact record from database table. Used to read appropriate record from
database table.
To read exact record from database table we We can read appropriate record from
need to provide all key fields. database table, we may not need to
provide all key fields.
This statement should be used only if all the key This statement should be used only if
fields are available. we have some key fields or no key
fields.
Syntax :SELECT SINGLE * FROM Syntax: SELECT * FROM
DATABASETABLE INTO WA WHERE ALL KEY DATABASETABLE INTO WA UP TO 1
FIELDS ROWS WHERE ALL KEY FIELDS/SOME
FIELDS. ENDSELECT.
This is very fast when compared to SELECT UPTO This is slow.

Ensure before using SELECT FOR ALL ENTRIES


Parent internal table must not be empty (If it is empty, where condition fails and it will get all records
from database).
Remove all duplicate entries in parent internal table.
'BYPASSING BUFFER'
Whenever we use open SQL statements to get fetch data in SAP, it will get data from buffer
area(depends on table buffer settings) for better performance, but in real world scenarios some
tables may updated very frequently(milliseconds), we may need to bypass buffer to get real-time
data, in that case we will bypass buffer using 'BYPASSING BUFFER' keyword.
SELECT DISTINCT
is a SQL Select query, which is used to get distinct values of a column from a database table.
SELECT DISTINCT eliminates duplicates records of a column of a table.
SELECT APPENDING
query is used to append SELECT query result directly to some other internal table.
Below is the syntax for SELECT APPENDING

Abap (Classical Reports)


Classical Reports are reports which contain both selection-screen
and output screen.
SAP ABAP is an event driven programming language, ABAP
programs executed based on events not line-by-line.
Events in Classical Reports
Load-of-praogram
This event is used to load program into memory for execution and this is
the first event in execution sequence.
Intialization
This event is used to initialize variables, screen default values and other
default actions.
At Selection-Screen output
By using this event we can manipulate dynamic selection-screen changes.
(only 1 time in program).
Loop At Screen. Screen is structure with Name, Group1, Group2, Group3, Group4, invisible,
active, intensified etc fields, this holds the screen information at run time, Loop at
Screen...Endloop. is used to loop through screen elements, and based on the values in above
structure (SCREEN) we can manipulate changes.
MODIF ID : MODIF ID is a three character id (without quotes), we can process a screen elements
group using this MODIF ID, this will be stored in SCREEN-GROUP1.
MODIFY SCREEN is keyword which is used to apply screen modification.

REPORT ZSPN_SELECTION_SCREEN_OUTPUT.
PARAMETERS P_ENABLE AS CHECKBOX USER-COMMAND UC1.
PARAMETERS: INPUT(5) TYPE C MODIF ID IN1 . "Based on modif id we will
Parameter P_DIS as checkbox.
Parameter: Male radiobutton group g,
Female radiobutton group g.
perform dynamic operations

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF P_ENABLE = 'X' . " If check box is selected
IF SCREEN-GROUP1 = 'IN1' .
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.

At Selection-Screen on field
This event is used to validate a single selection-screen input parameter.
Syntax: AT SELECTION-SCREEN ON <parameter name>. "Validate a input
parameter

At Selection-Screen on value request


This event is used to provide value help ( field help ) for a input field.
Syntax: AT SELECTION-SCREEN ON VALUE REQUEST FOR <parameter
name>. "Input search help for a input parameters

At Selection-Screen on help request


By using this event we can provide F1 help for a input field.
Syntax: AT SELECTION-SCREEN ON HELP REQUEST FOR <parameter
name>. "Input (F1) help for a input

At Selection-Screen
This event is used to validate multiple input fields.(only 1 time in
program).
Syntax: AT SELECTION-SCREEN . "used to validate multiple input fields

Start-of-Selection
This is default event which is used to write actual business logic.
Syntax: START-OF-SELECTION. "Default event
End-of-Selection
We can use this event just to state that start-of-selection is ended, this
event is used with logical databases, logical databases are in HR ABAP
only. In normal ABAP we don`t have much importance .
Syntax: END-OF-SELECTION . "Start of selection is ended

Top-of-Page
This event prints constant heading for all pages.
Syntax: TOP-OF-PAGE."Page heading
End-of-Page
This event prints constant footer for all pages.
Before using this event, we need to reserve some lines for displaying footer.
Syntax: END-OF-PAGE . "Page footer
Example: REPORT ZPROGRAM LINE-COUNT 27(3). " Here we reserve 3
lines for footer

Example-
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. "designs
a block just for design double click on TEXT-001 to add text

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR. " Material range input NO


INTERVALS. NO INTERVALS.
PARAMETERS: P_MTART TYPE MARA-MTART. "material type input

SELECTION-SCREEN END OF BLOCK B1.


PARAMETERS P_DLOAD AS CHECKBOX USER-COMMAND UC1.
PARAMETERS P_FILE TYPE RLGRAP-FILENAME MODIF ID DLD.
PARAMETERS P_LIMIT TYPE I. "Limit no of rows to display to avoid the
burden on database

LOAD-OF-PROGRAM. "loads program into memory


LV_START_TIME = SY-UZEIT. " see system variables
www.sapnuts.com/resourse/system-variable.html

INITIALIZATION. "triggers second


P_MTART = 'FERT'. "MATERIAL TYPE DEFAULT VALUE
P_LIMIT = '50'. "Limit rows to 50
Select-Options functionality in SAP ABAP
When ever we declare Select-Options, an internal table will be created with the following fields.
SIGN: This field contains I or E, where I stands for an inclusive (Include that value) and E stands for
exclusive (Exclude that values), default value is I.
OPTIONS: This field can accept values BT (Between), NB (Not Between), EQ (Equal), NE(Not equal),
GT(Greater than), LT(Less than) .
LOW: This field stores a low value of entering the range.
HIGH: This field stores a high value of entering the range.
Name to paramters:
Go to Program Source,Select Goto-Text Elements-Selectin Texts
Drop Down box in Selection Screen in SAP ABAP
To display drop down list we have to use type-group VRM as type-pools.
TYPE-POOLS: VRM. " Use type group VRM for list
DATA: IT_LIST TYPE VRM_VALUES.
DATA: WA_LIST TYPE VRM_VALUE.
DATA: IT_VALUES TYPE TABLE OF DYNPREAD,
WA_VALUES TYPE DYNPREAD.
DATA: LV_SELECTED_VALUE(10) TYPE C.
PARAMETERS: COLORS TYPE C AS LISTBOX VISIBLE LENGTH 20. "Parameter
INITIALIZATION. "initialize values to drop down list
WA_LIST-KEY = '1'.
WA_LIST-TEXT = 'Green'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '2'.
APPEND WA_LIST TO IT_LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'COLORS'
VALUES = IT_LIST
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2.
AT SELECTION-SCREEN ON COLORS.
CLEAR: WA_VALUES, IT_VALUES.
REFRESH IT_VALUES.
WA_VALUES-FIELDNAME = 'COLORS'.
APPEND WA_VALUES TO IT_VALUES.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TRANSLATE_TO_UPPER = 'X'
TABLES
DYNPFIELDS = IT_VALUES.
READ TABLE IT_VALUES INDEX 1 INTO WA_VALUES.
IF SY-SUBRC = 0 AND WA_VALUES-FIELDVALUE IS NOT INITIAL.
READ TABLE IT_LIST INTO WA_LIST
WITH KEY KEY = WA_VALUES-FIELDVALUE.
IF SY-SUBRC = 0.
LV_SELECTED_VALUE = WA_LIST-TEXT.
ENDIF.
ENDIF.
START-OF-SELECTION.
WRITE:/ LV_SELECTED_VALUE.

Using at Selection Screen output in SAP ABAP


At Selection Screen output
is a selection-screen event, which is used to manipulate dynamic changes on selection-screen.
Loop At Screen.
Screen is structure with Name, Group1, Group2, Group3, Group4, invisible, active, intensified etc
fields, this holds the screen information at run time, Loop at Screen...Endloop. is used to loop
through screen elements, and based on the values in above structure (SCREEN) we can manipulate
changes.
MODIF ID :
MODIF ID is a three character id (without quotes), we can process a screen elements group using this
MODIF ID, this will be stored in SCREEN-GROUP1.
All Screen modifications should be done under AT SELECTION-SCREEN OUTPUT event only.
MODIFY SCREEN is keyword which is used to apply screen modification.
The below is the sample code for dynamic screen modification .
REPORT ZSPN_SELECTION_SCREEN_OUTPUT.
PARAMETERS P_ENABLE AS CHECKBOX USER-COMMAND UC1.
PARAMETERS: INPUT(5) TYPE C MODIF ID IN1 . "Based on modif id we will
perform dynamic operations
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF P_ENABLE = 'X' . " If check box is selected
IF SCREEN-GROUP1 = 'IN1' .
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ELSE.
IF SCREEN-GROUP1 = 'IN1' .
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.

At Selection Scteen on Field At Selection Screen


This event is used to validate a single input field. This event is used to validate multiple input fields.
If we this event, if any, error the error field will be highlighted By using this event, the error field is heightened and all
and the remaining fields will be disabled. the remaining fields will be enabled.
At Selection Scteen on Field At Selection Screen
At Selection Screen At Selection Screen on Field
REPORT ZSPN_SELECTION_SCREEN_EVENT. REPORT ZSPN_SELECTION_SCREEN_EVENT.
PARAMETERS P_FIELD1 TYPE CHAR10 . PARAMETERS P_FIELD1 TYPE CHAR10 .
PARAMETERS P_FIELD2 TYPE CHAR10. PARAMETERS P_FIELD2 TYPE CHAR10.

AT SELECTION-SCREEN. AT SELECTION-SCREEN ON P_FIELD1.


IF P_FIELD1 IS INITIAL. IF P_FIELD1 IS INITIAL.
MESSAGE 'Please enter field1' TYPE 'E'. MESSAGE 'Please enter field1' TYPE 'E'.
ENDIF. ENDIF.
IF P_FIELD2 IS INITIAL. AT SELECTION-SCREEN ON P_FIELD2.
MESSAGE 'Please enter field2' TYPE 'E'. IF P_FIELD2 IS INITIAL.
ENDIF. MESSAGE 'Please enter field2' TYPE 'E'.
ENDIF.

ALV- ABAP List Viewer


Better look and feel.
ALV report consists of some per-defined options like sort, filters, sum,
downloading, print, changing the layout structure and many more.
REUSE_ALV_GRID_DISPLAY. "Display ALV grid format
REUSE_ALV_LIST_DISPLAY. "Display ALV List format
REUSE_ALV_COMMENTARY_WRITE. "Display Top of page, logo, etc.
REUSE_ALV_FIELDCATELOGUE_MERGE. "Used to generate field catalogue
REUSE_ALV_EVENTS_GET. "Use events in ALV
REUSE_ALV_HEIRARCHY_LIST_DISPLAY. "Display ALV Hierarchy
REUSE_ALV_BLOCKED_LIST_DISPLAY. "Display blocked list

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_STRUCTURE_NAME = 'MARA' “direct structure without field catalog
IT_SORT = I_SORT
IS_LAYOUT = WA_LAYOUT"” with all fields of output is editable, no horizontal and vertical lines and
hotspot on material no

IT_FIELDCAT = IT_FCAT "if PASS FIELD CATALOG TO ALVTABLES


T_OUTTAB = IT_MARA.
Field Catalog
Field catalog is an internal table which is used to pass a list of fields to display in ALV report, we can
set different properties to fields which are going to display in ALV.

Type Group
It is a data dictionary object which contains all the reusable user-defined
types. Example for a type group is SLIS, which contains all the user-defined
types for developing ALV reports. TYPE-POOLS is a keyword which is used to
assign the type-group to a ALV report
eg - Syntax : TYPE-POOLS SLIS . "TO USE FIELD CATALOG WE HAVE TO INCLUDE SLIS
TYPE-POOLSDATA : <IT_FCAT> TYPE SLIS_T_FIELDCAT_ALV . "INTERNAL TABLE FOR
FIELD CATALOGDATA : <WA_FCAT> TYPE SLIS_FIELDCAT_ALV . " WORK AREA FOR FIELD
CATLOG
WA_FCAT-COL_POS = '1' . "Specify position of a field
WA_FCAT-FIELDNAME = 'MATNR' . "Specify field name
WA_FCAT-TABNAME = 'IT_MARA' . "Specify internal table name
WA_FCAT-SELTEXT_M = 'MATERIALNO' . "Specify text to display column header
WA_FCAT-KEY = 'X' . "Specify if it is a key field APPEND
WA_FCAT TO IT_FCAT . "Append to field catalog internal table

Layout like horizontal and vertical line


DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
WA_LAYOUT-ZEBRA = 'X' .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
WA_LAYOUT-EDIT = 'X' .
WA_LAYOUT-NO_VLINE = 'X' .
WA_LAYOUT-NO_HLINE = 'X' .

Sorting and Subtotal


DATA : I_SORT TYPE SLIS_T_SORTINFO_ALV .
DATA : WA_SORT LIKE LINE OF I_SORT .
WA_SORT-FIELDNAME = 'VBELN '.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X '.
APPEND WA_SORT TO I_SORT .

Events in ALV
There are total 17 events available for ALV reporting, by using this ALV events we can display report
headers, report footers, user command, pf status etc.
NAMEFORM,CALLER_EXIT,USER_COMMAND,TOP_OF_PAGE,TOP_OF_COVERPAGE,END_OF_COVERP,
AGE,FOREIGN_TOP_OF_PAGE,FOREIGN_END_OF_PAGE,PF_STATUS_SET,LIST_MODIFY,TOP_OF_LIST,E
ND_OF_PAGE,END_OF_LIST,AFTER_LINE_OUTPUT,BEFORE_LINE_OUTPUT,REPREP_SEL_MODIFY,SUBT
OTAL_TEXT,GROUPLEVEL_CHANGE
STEP1: Call the function module 'REUSE_ALV_EVENTS_GET' and get all the events into a Internal
Table(I_EVENTS).
STEP2: For each EVENT we need to provide a Sub-Routine name. So Read the EVENT from Internal
Table into WorkArea and provide the Sub-Routine name.
STEP3: Finally, define the Sub-Routine and write logic.
Get events using function module
DATA : I_EVENTS TYPE SLIS_T_EVENT .
DATA : WA_EVENTS LIKE LINE OF I_EVENTS .
DATA : I_HEADING TYPE SLIS_T_LISTHEADER .
DATA : WA_HEADING LIKE LINE OF I_HEADING .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'


* EXPORTING*
I_LIST_TYPE = 0
IMPORTIN
GET_EVENTS = I_EVENTS .*add perform name to a eventREAD TABLE I_EVENTS INTO
WA_EVENTS WITH KEY
NAME = ‘<EVENT NAME>' .
WA_EVENTS-FORM = '<FORM_XXX>' .
MODIFY I_EVENTS FROM WA_EVENTS INDEX SY-TABIX .
*<EVENT NAME> = name of the event
*<FORM_XXX> is perform name to implement for particular event
Add heading to ALV
WA_HEADING-TYP = 'A' .
WA_HEADING-KEY = 'DATE' .
WA_HEADING-INFO = SY-DATUM .
APPEND WA_HEADING TO I_HEADING .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_HEADING*
I_LOGO =*
I_END_OF_LIST_GRID =*
I_ALV_FORM = .

Dynamic Alv-
Step1: build field catalog for the input table.
PARAMETERS: P_TABLE TYPE DD02L-TABNAME. "table input
START-OF-SELECTION.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' "create field catalog
EXPORTING
I_STRUCTURE_NAME = P_TABLE
CHANGING
CT_FIELDCAT = IT_FCAT.
Step2: Create dynamic table.
Create dynamic table using 'CREATE_DYNAMIC_TABLE' method of class 'CL_ALV_TABLE_CREATE'.
DATA : FS_TAB TYPE REF TO DATA.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
* I_STYLE_TABLE =
IT_FIELDCATALOG = IT_FCAT
* I_LENGTH_IN_BYTE =
IMPORTING
EP_TABLE = FS_TAB.

Display Alv in Blocks


REUSE_ALV_BLOCK_LIST_INIT: is used to initialize blocked list ALV.
REUSE_ALV_BLOCK_LIST_APPEND: is used to add blocked list ALV's(we can
add multiple).
REUSE_ALV_BLOCK_LIST_DISPLAY: is used to display blocked list ALV.
To stop other menu items on header
Get Standard GUI function codes
We can get standard GUI function codes using function module
RS_CUA_GET_STATUS_FUNCTIONS bypassing standard program SAPLKKBL and
statusSTANDARD_FULLSCREEN.
DATA : FUN TYPE TABLE OF RSEUL_FUN.
DATA : WA_FUN LIKE LINE OF FUN.
CALL FUNCTION 'RS_CUA_GET_STATUS_FUNCTIONS'
EXPORTING LANGUAGE = 'E'
PROGRAM = 'SAPLKKBL'
STATUS = 'STANDARD_FULLSCREEN'
TABLES FUNCTIONS = FUN.
IF SY-SUBRC <> 0.* Implement suitable error handling here ENDIF.

Exclude functions using IT_EXCLUDE parameter of ALV grid


Loop through the standard GUI function which we got in the previous step,
and pass to exclude table.
DATA : IT_EXCLUDE TYPE SLIS_T_EXTAB,
WA_EXCLUDE TYPE SLIS_EXTAB.
LOOP AT FUN INTO WA_FUN. "loop through all functions
IF WA_FUN-FCODE EQ '&F03' OR WA_FUN-FCODE EQ '&F15' OR WA_FUN-FCODE EQ '&F12'.
"don`t add back, exit, stop functions
ELSE.
WA_EXCLUDE-FCODE = WA_FUN-FCODE. "add all remaining
APPEND WA_EXCLUDE TO IT_EXCLUDE.
CLEAR WA_EXCLUDE.
ENDIF.
ENDLOOP.

Interactive Alv –
First set Field catalog property hotspot with X
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV . "field catalog table
DATA : WA_FCAT LIKE LINE OF IT_FCAT . "field catalog work area
*** build field catalogue
WA_FCAT-COL_POS = '1' . "column position
WA_FCAT-FIELDNAME = 'MATNR' . "column name
WA_FCAT-TABNAME = 'IT_MARA' . "table
WA_FCAT-SELTEXT_M = 'Material' . "Column lable
WA_FCAT-KEY = 'X' . "is a key field
WA_FCAT-HOTSPOT = 'X' . "Set hotspot for matnr
APPEND WA_FCAT TO IT_FCAT . "append to fcat
CLEAR WA_FCAT .
WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Industry Sec' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .
After Reuse alv –
**for to handle user command
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'. "standard Function code for doubel click
READ TABLE IT_MARA INTO WA_MARA INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.
SET PARAMETER ID 'MAT' FIELD WA_MARA-MATNR. "set parameter id
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. "call
transaction
ENDIF.
ENDCASE.
ENDFORM. "user_command
ALV Popup with checkbox for input help
Step1: Call ALV popup function module under value request event

Call REUSE_ALV_POPUP_TO_SELECT function module under event SELECTION-SCREEN


ON VALUE-REQUEST .
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
I_TITLE = 'Select Material Type'
I_CHECKBOX_FIELDNAME = 'CHECK'
I_TABNAME = 'IT_T134'
IT_FIELDCAT = IT_FCAT
I_CALLBACK_PROGRAM = SY-REPID
TABLES
T_OUTTAB = IT_T134
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.

Error log in Report (slg1)


CALL FUNCTION 'BAL_LOG_MSG_ADD'”to add
EXPORTING
i_log_handle = mv_loghandle
i_s_msg = ls_s_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.

CALL FUNCTION 'BAL_DB_SAVE' “to save


EXPORTING
i_client = sy-mandt
i_in_update_task = ' '
i_save_all = ' '
i_t_log_handle = mt_loghandle
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.

CALL FUNCTION 'BAL_DSP_PROFILE_STANDARD_GET'


IMPORTING
e_s_display_profile = ls_display_profile.

IF iv_title IS SUPPLIED.
ls_display_profile-title = iv_title.
ELSE.
ls_display_profile-title = ms_bal_control-title.
ENDIF.
ls_display_profile-bydetlevel = iv_hierarchy.
ls_display_profile-exp_level = 1.
ls_display_profile-show_all = 'X'.
ls_display_profile-disvariant-report = ms_bal_control-repid.

CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'


EXPORTING
i_s_display_profile = ls_display_profile
i_t_log_handle = lt_handle
EXCEPTIONS
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5.

Ole
For the Windows front-end, SAP provides interfaces based on Microsoft's 'Object Linking and
Embedding' Technology (OLE Automation) for embedding objects such as Microsoft Excel files.
CREATE OBJECT - CREATE OBJECT application 'excel.application'.
CREATE OBJECT gs_word 'WORD.APPLICATION' .
CALL METHOD
GET PROPERTY
SET PROPERTY
FREE OBJECT,

Interactive report(Abap)
It’s nothing but to display the summarized information in the basic list & detailed information in
the secondary list.
Note: - We can have only one basic list & up to 20 secondary lists (1-20).
Interactive Reports Events
At Line-Selection

This event will trigger whenever the user double click on any list line.
At User Command

This event will trigger whenever user clicks on any custom buttons of the GUI. It’s an
event which is triggered at the time of user clicks on any menu item.
At PF Status

This event will trigger whenever user clicks on any function buttons. It’s an event which
is triggered at the time of user clicks on F1 to F12 function keys
Top Of Page During line selection

This is used to print heading for secondary lists in interactive reports. It’s an event
which is triggered at the top of each secondary list.
Note: - Classical events are also triggered for basic list.
System variables related to interactive report
SY-LSIND: -
It’s the system variable which contains the current list index number.
SY-LISEL: -
It’s the system variable which contains the contents of the selected record.
SY-LILLI: -
It’s the system variable which contains the exact line number of the selected record.
SY-UCOMM: -
It’s the system variable which contains the function code of the selected menu item.
SY-LINNO: -
It’s the system variable which contains the line number of the last record display.
Techniques used in interactive reporting
Hide area
It is a key word which is used to store the data into a temporary memory call as HIDE area.4
Module Pool
It is a special type of programming which is used to create custom SAP screens.
Transaction code for creating module pool programs is SE80.
Every module pool program must be executed with a transaction (T-code).
Events in Module pool programming
There are four events available in module pool programming.
PBO (Process Before Output): Triggered before MPP screen is displayed.
PAI (Process After Input): Triggered after MPP screen is displayed whenever user raises an
action. Also,Now PBO is also triggered.
POV (Process On Value Request): Triggered when User Clicks on search help or F4 Button.
F4IF_FIELD_VALUE_REQUEST
POH (Process On Help Request): Triggered when User Clicks on search help or F1 Button.
HELP_OBJECT_SHOW_FOR_FIELD
Modularization techniques in Module Pool
Basically there are four include programs which are created automatically for an MPP program.
_TOP "top include program ,All data declarations.
_O01 "PBO include program , All logic related to PBO event
_I01 "PAI include program , All logic related to PAI event
_F01 "Forms include program , All logic related to subroutines
SCREEN
It is a visible layout which is displayed in the output. The components of the Screen are
Components of Screen:
Attributes : Properties of screen
Element List : List of UI/Library elements
Flow-Logic : Abap logic related to MPP
Layout : Screen Designing Area
MODULE:
It is an sub-program which contains the ABAP code for a screen .
Flow-Logic cannot understand ABAP statements. So the entire ABAP code is written in the form of
modules.
Since the entire ABAP logic is divided in the form of modules, that is why it is called MODULE POOL
PROGRAMMING
Dynpro
A screen together with its Flow logic is called a Dynpro ("Dynamic Program" since the screen flow
logic influences the program flow)
Each dynpro controls exactly one step of your Dialog Program.
The screens belonging to a program are numbered. The screen flow sequence can be either linear or
cyclic. From within a screen chain, you can even call another screen chain and, after processing it,
return to the original chain. You can also override the statically-defined next screen from within the
dialog modules of the ABAP program.
ABAP Module Pool
On a PBO or PAI event a Dynpro calls an ABAP dialog program. Collection of such programs is called
the ABAP module pool.
For example modules called at the PAI event are used to check the user input and to trigger
appropriate dialog steps, such as the update task.
All dynpros to be called from within one transaction refer to a common module pool.
Structure of a Dialog Program

Process Flow for a Dialog Program

Difference in Module pool and Report


Report Program:
A report is a program that typically reads and analyzes data in database tables without changing the
database.

Dialog Program:
A dialog program allows you to work interactively with the system and to change the contents of the
database tables. Each dialog program has a certain sequence of screens that are processed by the
system one after the other.

CALL FUNCTION 'DD_DOMA_GET'

Lock Objects
Lock objects are used to synchronize the multiple set of users who are accessing the same set of
data.
There are three types of locks.
Exclusive Lock.
Shared Lock.
Exclusive but not cumulative lock.
Exclusive Lock
The locked data can be read or proceed one user only. A request for another exclusive lock for a
shared lock is rejected.
Shared Lock
Several users can read the same data at the same time, but as same as a user edits the data,a second
user can not longer access this data. Requests for further shared locks are accepted, but exclusive
locks are rejected.
Exclusive but not cumulative lock.
Exclusive locks can be requested by the same user more than once and handled successfully, but an
exclusive but not cumulative lock can only be requested once by a given user, all the other lock
requests are rejected.
Use of lock objects
Lock objects are used when ever we are modifying or updating or inserting or deleting the database
table data using OPEN SQL statements.
Lock objects are part of data dictionary objects, when ever we create a lock object using data
dictionary, two function modules will be generated automatically in the back end.
All custom objects in SAP starts with Y or Z except lock objects.Lock objects starts with EZ or EY.
Name of the generated function modules are with following naming convention .
ENQUE_<LOCK OBJECT NAME>. "USED TO PUT A LOCK ON DATABASE TABLE RECORD
DEQUE_<LOCK OBJECT NAME>. "USED TO RELEASE LOCK ON DATABASE TABLE RECORD
*HERE <LOCK OBJECT NAME> IS THE LOCK OBJECT NAME WHICH IS CREATED IN DATA DICTIONARY
When ever we create a lock object two function modules will be created, go to SE37, check FM`s
DEQUEUE_EZSTUDENT and ENQUEUE_EZSTUDENT.
REPORT ZSAN_LOCKOBJECT.
DATA : IT_STUDENT TYPE TABLE OF ZSTUDENT,
WA_STUDENT TYPE ZSTUDENT.

WA_STUDENT-STUDENTID = '09'.
WA_STUDENT-NAME = 'SAPNuts'.
CALL FUNCTION 'ENQUEUE_EZSTUDENT' "add lock
EXPORTING
MODE_ZSTUDENT = 'E'
MANDT = SY-MANDT
STUDENTID = WA_STUDENT-STUDENTID "record to lock, optional
parameter
* X_STUDENTID = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
* EXCEPTIONS
* FOREIGN_LOCK = 1
* SYSTEM_FAILURE = 2
* OTHERS = 3
.
IF SY-SUBRC = 0.
MODIFY ZSTUDENT FROM WA_STUDENT.
ENDIF.

CALL FUNCTION 'DEQUEUE_EZSTUDENT' "release lock


EXPORTING
MODE_ZSTUDENT = 'E'
MANDT = SY-MANDT
STUDENTID = WA_STUDENT-STUDENTID "record to release lock,
optional parameter
.
SAP Script:
SAP Script is a tool which is used to printable business documents in SAP like invoice form, Sales
Order form, Delivery form, other form related to HR etc.
Scripts are older version of SAP print forms, advanced version to scripts are smartforms( we will learn
in next chapters ).
SAP Scripts are client dependent, that is if we develop a script in client 200, it will not be visible in
other clients like 300, 100.
Advanced version of scripts, smartforms are client independent, they will be visible in all clients.
Why SAP Scripts are client dependent ?
If we generate a SAP Script, it will be internally stored as texts.
Texts are nothing but a data, as per SAP all data is client dependent, so SAP Scripts are client
dependent.
SE71 is the T-code for SAP scripts.
Components of SAP Scripts

Header ( Administrative data and basic settings ).


Pages.
Windows.
Page windows.
Paragraph format.
Character Format.
Layout.
Header

It contains header information of SAP Script i:e administrative data and basic settings of SAP script.
Administrative Data: It contains administrative data like package, client, user and language.
Basic Settings: It contains settings like page format, first page, default paragraph etc.
Pages

SAP Script is a group of pages, each page contains layout.


The layout is used to design page.
Page is a group of windows.
In SAP Scripts we can create 99 pages only.
Windows

A window is a container which contains some information to display, the entire page is designed
using windows.
There are four types of windows.
Main window:
A Window which automatically expands depending upon the data is called main window.
Each page contains only one main Window.
As there are 99 pages only in scripts, we can have maximum 99 main windows only The main
Window data is divided into blocks called as text elements.
Text Element:

It is used to display the specific block of information.


Text elements are represented by /E
The entire main Window data is divided into blocks called as text elements.
Now,Display a particular text element, so that only that specific info related to text element is
displayed.
Constant Window:
A Window which is constant for all the pages is called constant Window.
Variable Window:
A Window which does not expand i.e., width and height is fixed .
Graphical Window:
A window which is used to display graphics or images.
Page windows:
The windows assigned to particular page are called page windows.
Paragraph format :
It is used to specify a particular format (font size/family/Bold/italic/underlined) for all the characters
in a paragraph .
We can also specify TABS.
Tabs : Tabs are used to specify a position in sap script so that the text will be displayed at that
particular position.
Tabs are represented by ,, (2 commas).
Character format :
A format which is used by a group of characters inside a paragraph is called a character format .
Layout:
It is a place where we design the page with windows.
Function Modules used in SAP Scripts
We use some function modules to develop SAP Scripts, explained below.
OPEN_FORM
This is used to open a form for execution by loading it into memory.
WRITE_FORM
It is used to write Some information on the SAP Script form using Text Element.
CLOSE_FORM
It is used to close the form which is opened by open form.
START_FORM
It is used to call another SAP Script into current SAP Script(Nested Scripts).
END_FORM
It is used to end the form which started by START_FORM.
Driver Program
A program which contains business logic statements i.e., all select statements ,loops,appends etc, is
called Driver prg.
In simple words, a program which is used to drive or print the script.
All the variables ,work areas ,internal tables which are declared in the driver program will be
automatically transferred to SAP Scripts.
If we want to display the variables or workarea values we need to follow below syntax.
Syntax : &variable&
&workarea-fname&
Views
ABAP views in data dictionary are logical data sets which contain data extracted on one or more
tables as a single entity. the data from a view is not actually physically stored instead
being derived from one or more tables. A view can be used to summarize data
which is distributed among several tables
Database view
Database view is a view created on two or more tables using inner join concepts. In database view,
you can not maintain the data and you can only read the data. Fields which are not required can be
hidden, thereby minimizing the interfaces. A view can be used in ABAP programs for data selection.
At least one relationship is required.
In database views, the join conditions can be formulated using equality relationships between any
base fields. In the other types of view, they must be taken from existing foreign keys. That is, tables
can only be collected in maintenance or help view if they are linked to one another via foreign keys.
Basis Tables, View Fields, Join Conditions, Maintenance Status, SAP Buffering
Projection View
A projection view is used to hide certain fields from in a given table. The main purpose of Projection
views is gaining access to pooled, cluster as well as transparent tables. There are no selection
conditions in a projection view. The definition of the structure type lies in the view fields that may be
referenced to using TYPE in ABAP. You cannot define selection conditions for projection views. You
can also access pooled tables and cluster tables with a projection view.The maintenance status of
the view controls how the data of the table can be accessed with the projection view. - You cannot
define selection conditions for projection views. - Modification (create, delete, insert, and update)
can be done.
Maintenance view
Maintenance views offer easy ways to maintain complex application objects.
Data distributed on several tables often forms a logical unit, for example an application object, for
the user. You want to be able to display, modify and create the data of such an application object
together. All the tables in a maintenance view must be linked with foreign key. You cannot directly
enter the join conditions as for database views.
Help Views
You have to create a help view if a view with outer join is needed as selection method of a search help.
The selection method of a search help is either a table or a view. If you have to select data from several tables
for the search help, you should generally use a database view as selection method. However, a database view
always implements an inner join. If you need a view with outer join for the data selection, you have to
use a help view as selection method. When the F4 button is pressed for a screen field, a check is first
made on whether a match code is defined for this field. If this is not the case, the help view is
displayed in which the check table of the field is the primary table. Thus, for each table no more than
one help view can be created, that is, a table can only be primary table in at most one help view. You
can not execute help views directly, instead you have to include help views inside the search helps. It
provides help functionary F4 for an input field.

Restrictions for Maintenance and Help Views


There are some restrictions for selecting the secondary tables of a maintenance view or help view.
The secondary tables have to be in an N:1 dependency to the primary table or directly preceding
secondary table. This ensures that there is at most one dependent record in each of the secondary
tables for a data record in the primary table.
View Cluster
SE54
Table Maintaince generator(Tmg)-
Table Maintaince Generator is used to insert, update and delete the data of data base table with
out any code (with out DML Commands). Table Maintaince Generator is only possible for custom
tables. The transaction code for TMG is SM30.
1. One Step Method - In one step method there is only one overview screen. In single step over view
screen number is compulsory but single screen is not required. In this case single screen number will
get ignored. You can enter any screen number other than 1000, which is reserved for selection
screen. In One Step Method, you will be able to see and maintain only through overview screen.

2. Two Step Method - In two step method there is two screens. Over View Screen and Single Screen
(Detail Screen). Here both the screen (Overview and Single) number is required to enter. In this the
overview screen contains only the key fields and single screen contains all the fields. On single screen
you can only maintain screen, Like Delete and Insert. You cannot update from single screen. From
overview screen you can delete and update. When you press 'New Entries' button then it will take
you to Single Screen. This happen only when you had selected Two step method.
FORM before_save.
DATA:
ls_int_rate TYPE yrre_d_int_rate,
lv_error TYPE xfeld.
LOOP AT total.
IF <action> EQ 'D'.
DATA(lv_activity) = yrre_if_delivery_constants=>gc_ao_activity-
delete.
ELSEIF <action> EQ 'N'.
lv_activity = yrre_if_delivery_constants=>gc_ao_activity-
add_or_create.
ELSEIF <action> EQ 'U'.
lv_activity = yrre_if_delivery_constants=>gc_ao_activity-change.
ENDIF.
MOVE-CORRESPONDING <vim_total_struc> TO ls_int_rate.

So10 Standard text

CALL FUNCTION 'READ_TEXT' o read text

SNRO Number range

CALL FUNCTION 'NUMBER_RANGE_ENQUEUE' “lock object


EXPORTING
object = 'YRRE_BL'
EXCEPTIONS
foreign_lock = 1
OTHERS = 4.

IF sy-subrc = 0.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'YRRE_BL'
IMPORTING
number = rv_blno
EXCEPTIONS
interval_not_found = 1
OTHERS = 8.
IF sy-subrc <> 0.
IF sy-msgty = 'E' OR sy-msgty = 'A'.
ls_msg-msgty = sy-msgty.
IF eo_message IS NOT BOUND.
eo_message = /bobf/cl_frw_factory=>get_message( ).
ENDIF.
eo_message->add_message( is_msg = ls_msg ).
ENDIF.
ENDIF.
CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
EXPORTING
object = 'YRRE_BL'
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
ENDIF.
Performance Tuning
Run-time analysis is SE30 or SAT
Performance tuning ST05
Key Points.
When reading data from database table, never use SELECT *, always use
select with list of fields.
Always specify key fields in where conditions of SELECT statements,
because these will have primary index.
Sometimes we may need to use non-key fields in where conditions of
SELECT statements, in that case create secondary indexes and use.
Never use select with corresponding in SELECT statements.
Always use read table with binary search and make you have sorted the
internal table in ascending order before using read table binary search.
Never use select joins for more than 3 tables.
Always use select for all entries for more than 3 tables.
Always check whether the parent internal table is initial or not before
using for all entries.
Never use nested loops, instead use parallel cursor .
Never use select statements inside loops, instead use for all entries.

Badi(Abap)
BADI (Business Add-in)
BADI is another way of implementing enhancements to the standard programs with out modifying
the original code.
BADI's are implemented using oo programming technique Technically a BADI is nothing but an
interface.
Each BADI consists of the method with out implementation called as BADI definition.
We need to create classes to write the abap code by implementing the methods called as BADI
implementation.
Single implementation BADI:- A BADI which has only one implementation (single class) is called
single implementation BADI.
Multiple implementation BADI:- A BADI which has multiple implementations is called multiple
implementation BADI. By default all the implementations will be executed.
We cannot control the sequence of execution of multiple implementations.
Filter BADI It is type of BADI which has a filter value so that only those implementations which
satisfy the filter value are executed. The remaining implementations are not executed this type of
BADI is called a filter BADI.
Steps to find BADI using CL_EXITHANDLER
Go to T-code SE24,provide class name as CL_EXITHANDLER and display.
Double click on the method GET_INSTANCE and put a break-point on the below method
GET_CLASS_NAME_BY_INTERFACE.
Execute the transaction (example VA01), the break-point will trigger, not down the values
that comes to variable exit_name. (Press F8 to get next exit name, continue process until
screen displays).
Using SE84 to find BADI

Find package for a T-code.Go to SE93, provide t-code name(VA01), display.


Go to SE84, expand enhancements, expand Business Add-ins and select definition.
Provide package name and execute, you will find list of BADI`s.
Screen Badi
BADI Name: MB_MIGO_BADI
Method Name: PBO_BETAIL
Badi is implemented through SE19.
E_CPROG = 'ZSCREEN990'.
E_DYNNR = '2222'.
E_HEADING = 'GR ADITIONAL SCREEN'.
Enhancement Spot: -
Enhancement Spot is the collection of BADI definitions. If you want to create a BADI then first we
create the enhancement spot. In that we create the BADI definition.
Differences between Customer exit (Enhancement) and BADI.
Customer Exit (Enhancement)
1. We can implement the customer exit only once.
2. Customer exit is the procedural approach. So it takes some extra time to enhancing.
3. In the screen exit the screen number is fixed which is provide by SAP.
4. By using CMOD transaction we can implement the customer exit.

BADI
1. We can implement the same BADI any number of times.
2. BADIs are object oriented approach. So it takes very less time to enhancing.
3. In the screen BADI we provide our own screen number.
4. By using SE19 transaction we can implement the BADI.
Note: - In the real time we never create our own BADI. We always use existing BADIs.
User Exit (Abap Enhancement)
Initially SAP implemented enhancements in the form of User Exits and these are only available in SD
module, user exits are implemented in the form of subroutines and hence are also called as FORM
EXITS, User exits are empty subroutines that SAP developers have provided for you, you can add your
own source code in the empty subroutines.
All user exits starts with the word USEREXIT.
Customer Exit (Abap Enhancement)
These are one type of enhancements that are available in some specific programs, screens and
menus within standard SAP Applications. These are Function Modules with a custom empty include
program, you can add your own functionality in these include programs.
Customer Exits are available in all SAP modules, whereas user exits are only available in SD module.
All customer exits ( Function Modules) starts with CALL CUSTOMER word.
User Exit Customer Exit
User exit is implemented in the form of a Subroutine i.e. A customer exit can be implemented as:
PERFORM xxx.
PERFORM userexit_save_document_prepare.  Function exit

 Screen Exit

 Menu Exit

 Field Exit

Example: CALL Customer function "XXX"


INCLUDE ZXXX. ."create and add logic
In case of a PERFORM, you have access to almost all the You have access only to the importing, exportin
data. So you have better control, but more risk of making the changing and tables parameter of the Function
system unstable. Module. So you have limited access to data.
User exit is considered a modification and not an A customer exit is considered an enhancement
enhancement because we are changing the existing code. because we are adding additional functionality
the existing one..not changing any thing.
You need Access Key for User Exit. You do not need access key.
Changes are lost in case of an upgrade. Customer exits came later and they overcome th
shortcomings of User Exit.
User Exit will be activated automatically when ever you To activate a function exit, you need to create a
activate the application(program). project in CMOD and activate the project.

BAPI stands for Business Application Programming Interface (B + API), BAPI`s are methods
(Function Modules) defined in Business Object Repository (BOR).
BAPI is a remote enabled function module, which is used to communicate between SAP to
SAP, SAP to NON-SAP systems.
BAPI RFC function module will be inserted into business object, it will convert into BAPI.
How BAPI is created?
 Remote Enabled Function Module created.
 Remote enabled function module inserted into a business object.
 BAPI created.
Field symbols
are similar to pointers in C language, field symbols does not have any memory
instead they will be pointing to a memory location.
The concept of field symbols is very important in order to increase the performance
of SAP applications, but unethical use of field-symbols leads to application issues.

SAP memory and ABAP memory


SAP Memory ABAP Memory
SAP memory is global memory, all SAP GUI ABAP memory is local memory, all programs within
sessions have access. a session can have access.
SAP memory is a memory area, which can be ABAP memory is a memory area, which can be
accessible by all SAP GUI sessions. By using accessed by all ABAP programs with in internal
SAP memory we can share data between session, these data sharing can be processed by
sessions as well as SAP programs. using EXPORT/IMPORT statements. To pass data
from a program to another program we have to fill
memory id using EXPORT and can be imported by
using IMPORT .
The data can be exchanged by using GET/SET The data can be exchanged by using
parameters. EXPORT/IMPORT parameters.
These parameters can be set either for a The most frequent use of EXPORT/IMPORT
particular user or for a particular program using parameters is to share data between programs.
the SET PARAMETER statement. Other ABAP
programs can then retrieve the set parameters
using the GET PARAMETER statement. The
most frequent use of SET/GET parameters is to
fill screen fields .
SAP memory-
REPORT ZSAPN_SAP_MEMORY.
SET PARAMETER ID 'MAT' FIELD '470000-001' ." 'MAT' is the parameter id
of material input in MM03<br>
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN .
Abap memory –
REPORT ZSAPN_ABAP_MEMORY1.
PARAMETERS : P_INPUT TYPE CHAR10 .
START-OF-SELECTION.
EXPORT P_INPUT TO MEMORY ID 'TEST'.
SUBMIT ZSAPN_ABAP_MEMORY2 AND RETURN.
IF SY-SUBRC EQ 0.
WRITE:/ 'Only trigger when submit and return'.
ENDIF.
REPORT ZSAPN_ABAP_MEMORY2.
DATA P_INPUT TYPE CHAR10.
IMPORT P_INPUT FROM MEMORY ID 'TEST'.

WRITE :/ P_INPUT .

Buffering Types
The buffering type defines which table records are loaded into the buffer of the application server
when a table record is accessed. There are the following buffering types:
Full buffering:
All the records of the table are loaded into the buffer when one record of the table is accessed. Tables best
suited to full buffering are small, read frequently, and rarely written.
Generic buffering:
When a record of the table is accessed, all the records having this record in the generic key fields (part of the
table key that is left-justified, identified by specifying a number of key fields) are loaded into the buffer.
Single-record buffering:
Only the records of a table that are really accessed are loaded into the buffer.

Smart Forms
Smartform
Smart form is a GUI Tool which is used to design the business legal documents such as Delivery
note,Purchase order,Invoice etc. The transaction code is SMARTFORMS. Smartforms are client
independent objects. Smartforms are advanced version of SAP Scripts.It is a GUI tool and it is user
friendly.

Smartforms SAP Scripts


Smartforms are client independent. SAP Scripts are client dependent.
Main window is not compulsory. Main window is compulsory.
Smartforms generates a Function module when activated. No Function Module will be generated
Smartforms texts supports various colors. Scripts allows black and white colors
only.
There is no transfer of control between program and form, once the control is Scripts has repeated transfer of contro
transfered to Function Module, it will never come back.
Only single page format is possible. Multiple page formats are available.
COMPONENTS OF SMARTFORMS.
There are two main nodes in Smartforms.
1.Global Settings
Form Attribute.
Form Interface.
Global Definition.
2.Pages and Windows.
Global settings:
It is used to provide the basic settings for the smartform.
Form Attributes:
It specifies the general attributes like who created,Date,time, package,translate options, default
smartstyle, Page format (DINA4/DINA5).
Form interface:
It acts as a mediator between a driver program and a smart form.
The main functionality of form interface is, it will import the parameters which are exported by driver
program.
The parameters can be variables, work areas, internal tables..etc.
Global definition:
It will contain the variables to be used within the smart form.
We can define variables, user defined data types, field symbols, initialization code,Subroutine,
currency/quantity fields.
It is mainly used for declaring or defining the above variables.
Pages and Windows
Page. Window.Graphic.Address.Text.Table.Header.Body.Footer.Template.Folder.Program
Lines.Alternative.Command.Loop.
Pages and windows
This will contain all the pages and the windows, which are used in the smartform.
By default, a page will be created by name %page1.
By default, a window will be created by name 'Main' under the page1.
For each page, we need to specify the next page.
Eg: page = %page1
Next page = %page1 or %page2
Nodes under pages
Page : It is used to define the layout of a smartform.
We can have different pages with different layouts.
Window : it is used to display information or text at a particular place on a page.
Graphic : it is used to display logos or images on the smartforms.
Address : It is used to display the address of customer or vendor or employe, organization address ,
workplace address etc.
Just provide address no, it will automatically display the address as per the country formats.
Nodes under the window
Text : it is used to display the information or text in a window.
Table : It is used to display the information in the form of table.
When ever we create table by default HEADER, MAIN AREA, FOOTER will be displayed.
The main functionality of a table is, it expands automatically depending on the internal table data.
We need to provide the name of the internal table for a table.
Template : template is also like a table which does not expand. That means it will have fixed
number of rows and columns.
Program lines : it is used to write some lines of abap code.
Window Types in Smartforms
Main window: For continuous output .
Secondary window: For output with a fixed length.
Final window: Special type of secondary window for outputting the information that is not known
until the end of form processing .
Copies window: Special type of secondary window for marking pages as copy or original.
Example Smartform GUI

Menu Painter
Menu painter is used to create custom GUI with custom buttons, custom toolbar and custom menu
for a specific ABAP program.
The t-code for menu painter is SE41, we can create menu using SET PF-STATUS keyword from
ABAP program .
Screen Painter
Screen Painter in the ABAP Workbench through transaction SE51

SPLIT
is a key word which is used to cut a string into pieces at a specified value.
Keyword syntax is SPLIT AT '<VALUE> INTO < IT_TABLE >
CONCATENATE
is a string function which is used to add different variables into a single string variable.
Syntax : CONCATENATE <STRING1> <STRING2> <STRING3>... INTO <STRING>.
TRANSLATE
is a string function which is used to change the case of a string i:e from lower case
to upper case and upper case to lower.
TRANSLATE <STRING> TO <LOWER CASE/UPPER CASE>
CONDENSE
is a string function/keyword which is used to remove blank spaces in a given string.
Syntax: CONDENSE <STRING>.
BDC(Abap)
BDC(Batch Data Communication) is a batch interfacing technique which is used to
insert mass data into SAP R/3 system, in BDC the data will be loded into R/3 using
SAP Screen which we use to create a record(Example: Material in MM01).
BDC is a inbound process.
Types-The BDC can be performed in two methods:

 Call Transaction.

 Session Method.

CALL TRANSACTION METHOD:


It is the process of transferring the data from flat file into SAP by calling a transaction
through a series of sequence of steps.
Properties of call transaction method

 This method is used for transferring less amount of data(<10,000 records).

 This method uses Synchronous and Asynchronous updates.

 This method will update the DB immediately.

 We need to handle the errors and the success messages by declaring an internal
table of type BDCMSGCOLL.

 This method is very fast.

CALL TRANSACTION ''


USING
UPDATE ''
MODE ''
MESSAGES INTO .

*T CODE, is a transaction to which we are loading data ex:MM01


*bdcdata is a table which contains data related to each screen
*A/S asynchronous or synchronous method.
*A/E/N all screen mode or error screen mode or no screen mode.
*MESSTAB is a message table to store messages (success, error, warning
etc)
BDCDATA is a structure defined with below fields in data dictionary, it holds the
information related to each screen field .

 Program - Name of the program.

 Dynpro - Screen Number.

 Dynbegin - Start the process.

 Fnam - Field name on the SAP screen.

 Fval - Field value on to the field name of SAP screen.

Use of BDCDATA

It is a structure which holds the information related to each screen i.e. program name, screen
no, field name, field values, information of that particular screen to be transferred into the
SAP.
In simple words, it holds all the screen related information and field information to be transferred
into corresponding SAP transaction. Program Dynpro Dynbegin Fnam Fval
SAPLGMM 0060 "X"
RMMG1-MATNR "1011"
RMMG1-MBRSH "FOOD"
RMMG1-MTART "FERT"
 SAPLGMM 0070 "X" RZSEL "X"
To find the above information for each field, press F1 on particular field It will display help
information.
Click on the button "technical information".
It will show the entire technical information of a screen.
Please note down the program name, screen number, screen field name.
This procedure has to be repeated for each field on a SAP screen.Since, it is very difficult to
note down the technical information for each field, we have an alternate and easy method
called as "RECORDING METHOD".
Update: There are two types of updates are available.
Asynchronous update (COMMIT).
Synchronous update (COMMIT & WAIT).

DIALOG WORK PROCESS: A work process which is dedicated to process screen


information is called "Dialog work process".
There will be 6 to 7 dialog work processes.
These dialog work processes are defined by basis consultant.
UPDATE WORK PROCESS: This work process is responsible for updating the data into
the database.
There will be always only "1" update work process.
ASYNCHRONOUS UPDATE (COMMIT):

 In this type the call transaction screens will communicate with the update work process to
update the data into database.

 It doesn"t wait for the update to be finished.

 It immediately starts to process the next record without waiting for the update to be
finished.

 That"s why this process is very fast.

 It is generally not recommended for the large amount of data, because the called transaction
does not return any success or error messages.

SYNCHRONOUS UPDATE (COMMIT & WAIT):

 In this mode, the called transaction communicates with the update work process to update
the data into database.
 It will wait for the update to be finished.

 Once the update is finished, then it continues to process the next record.

 That’s why this process is very slow.

 It is generally recommended for large amount of data because it returns success and error
messages.

MODE:

It specifies the type of the mode to execute the transaction.


There are 3 options for mode

 A All screen mode(Foreground).

 E Error screen mode (only error screens will be displayed).

 N No screen mode (Background).

RECORDING METHOD:

Since, it is very difficult to find technical information of each field on the screen, we go for a
method called as "Recording method".
The recording method is going to record all the fields in the transaction and it generated the
technical information such as program name, screen no, field name, field value for each field
on the SAP screen.
By using the recording method, it is very easy to create a BDC program.

Steps for recording a transaction.

SHDB is the T-code for recording method, go to SHDB, list of recordings will be displayed( if any), click
on New Recording to create new recording.
A pop up will open, provide a recording name ZSAPN_MM01, provide transaction code as MM01 and
click recording.
It will go to material creation screen, provide values for material creation.
A pop up will open, select basic data1 and enter
Enter below details.
Click Save( Ctrl S), it will go to a screen with recording code.
Click Save, go back, you will go to recording overview screen and click on program button to create a
program for this.

Abap7.4
Initializing work areas with ABAP 7.4 VALUE #()
wa_mara = VALUE #( MATNR = 0001 MTART = 'FERT' ).
it_mara = VALUE #( ( MATNR = 0001 MTART = 'FERT' )
( MATNR = 0001 MTART = 'HALB' )).
READ TABLE with INDEX using ABAP 7.4
SELECT *
FROM MARA
INTO TABLE @DATA(IT_MARA)
UP TO 50 ROWS
WHERE MTART = 'FERT'.

TRY .
DATA(wa_mara) = it_mara[ 51 ]. "Read 51 index will fail because only 50
records are there
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
WRITE:/ 'Error Reading Record'.
ENDTRY.
WRITE:/ wa_mara-matnr.
With Key
TRY .
DATA(wa_mara) = it_mara[ matnr = '0001' mtart = 'FERT' ].
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
WRITE:/ 'Error Reading Record'.
ENDTRY.
WRITE:/ wa_mara-matnr.
Check If record exists using line_exists ABAP
WHERE MTART = 'FERT'.
IF line_exists( it_mara[ matnr = '0001' mtart = 'FERT'] ).

WRITE:/ 'Records Exists'.


ENDIF.

IF NOT line_exists( it_mara[ matnr = '0002' ] ).

write:/ 'No Record Exists'.

ENDIF.
Get Index of a row using line_index
DATA(lv_index) = line_index( it_mara[ matnr = '0001' matkl =
'0001' ] ).
IF lv_index > 0. "Line exists
WRITE:/ lv_index.
ENDIF.
To Exclude coloum
it_mara_2 = CORRESPONDING #( it_mara_1 EXCEPT matkl ).
Then matkl will not coppy
To map column with different name
it_mara_2 = CORRESPONDING #( it_mara_1 MAPPING matkl = matl_group ).
COND to replace IF..ELSE ABAP 7.4
DATA(lv_mtart) = 'HAWA'.
DATA(lv_matkl) = '0001'.

DATA(lv_text) = COND text30(


WHEN lv_mtart ='FERT' AND lv_matkl = '0001' THEN 'You selected
FERT'
WHEN lv_mtart ='HALB' AND lv_matkl = '0001' THEN 'You Selected
HALB'
WHEN lv_mtart ='HAWA' AND lv_matkl = '0001' THEN 'You Selected
HAWA').

WRITE:/ lv_text.
Concate:
DATA(lv_out) = | Entered Text id: { lv_text } |.
DATA(lv_out) = | Entered Text id: { ZCL_CHECK_BOOLEAN=>GET_TEXT( ) } |.
DATA(lv_out) = | HELLO | && lv_text && | WORLD | .
WRITE / |{ 'TEXT ALIGNED TO LEFTSIDE OF THE SCREEN' WIDTH = 200 ALIGN =
LEFT } | .
WRITE / |{ 'SAPnuts' CASE = (cl_abap_format=>c_upper) }|.
WRITE / |{ lv_number ALPHA = OUT }|.
WRITE / |{ lv_date DATE = ISO }|. "Date Format YYYY-MM-DD
WRITE / |{ lv_date DATE = User }|. "As per user settings
WRITE / |{ lv_date DATE = Environment }|.

Exception Handling:

ODATA
OData Defilation-
OData(Open Data Protocol) is an open protocol to allow the creation and consumption of queryable
and interoperable RESTful APIs in a simple and standard way
A protocol is a set of rules by which official procedures are conducted.
OData interface is an open standard that can be consumed by any application, program, software or
device of the Non-SAP World that can connect with SAP using the HTTP(s) protocol and can
manipulate (read, write, modify and understand i.e. parse and construct) an XML document. Since
the protocol is HTTP based, any programming language with HTTP stack can be used for consuming
OData services.
Server hosts the Data(“Producers”) and Clients can call the Service(consumers)
OData offers database-like access to server-side resources. Hence, OData is also described as “ODBC
for the Web”.
HTTP (Hyper Text Transfer Protocol) is based on Client-Server Architecture.
very single HTTP request that is received by the Web Server is forgotten after a response has been
sent across. Web Servers do not remember or recall the previous request. This is called stateless.
OData is REST-inspired technology for reading, writing, and modifying information on the Web (not
just SAP). REST = REpresenational State Transfer. REST is an architectural style that uses simple and
lightweight mechanism for inter-machine communication. It is an alternative to the RPC (Remote
Proced Calls) and Web Services. REST is Resource-based, unlike RPC or SOAP which are Action-based.
REST
services are called as REST services because the Services are really working with Resources instead of
Operations. Any communication between client and services are using URI (Unified Resource
Identifier) over HTTP protocol using HTTP method. The URI is really the representation of the
Resources (like POHeader, POItem, Customer, Vendor etc). Also, in RESTful service, once you
identified the Resource, you will be working with a uniform interface, because it uses HTTP methods
(GET, PUT, POST and DELETE) to work with the resource. So, the client does not need to know what
the exact operation name defined in the service contract to call that method.
At NW 7.3 and prior to NW 7.3, SAP Netweaver Gateway had three add-ons namely GW_CORE,
IW_FND and IW_BEP. The GW_CORE and IW_FND components were required for Gateway Server
functionalities, whereas IW_BEP was used for Gateway Backend functionalities.
After 7.4 release, all the three components are bundled into a single component SAP_GWFND called
Gateway Foundation.
The project gets created with four folders, namely Data Model, Service Implementation, Runtime
Artifacts and Service Maintenance. Please take note that Data Model further has three sub-folders
viz Entity Types, Associations and Entity Sets. All the folders are empty by default.
Entity Type is our very own structure (or a work area (holds just one row)). And you guessed it right,
Entity Set is an internal table (holds more than one entity/rows).
Technical Service Name is the actual Service which the external system needs to call. Two classes,
Model Provider Class (MPC) and Data Provider Class (DPC)

Advantages of OData for Programmers and Developers.


i. The OData interface is implemented using XML or JSON. Both of these formats are well known,
plain text protocols for the transmission of information over the Web.
ii. OData message is self-describing. So any non-SAP Web developer can understand the content of
the OData message without the knowledge of ABAP or how SAP works.
Model Provider Class inherits from /IWBEP/CL_MGW_ABS_MODEL and Data Provider Class inherits
from /IWBEP/CL_MGW_ABS_DATA. The below image shows the relationship between the generated
classes and their superclasses (parents).
Data Provider Class provides the Gateway Service functionalities. Model Provider Class defines the
Gateway Service interface. DPC and MPC are not connected by any coding. They talk to each other
via Configuration.
Embedded Deployment Strategy
Hub Deployment with Development in the Backend System
Hub Deployment
with Development in the Gateway Hub

t-code SICF. Execute it with default values. Menu Goto->Port Information. The pop-up window would
have the Hostname and the Service name (Port Number) for the system.
URI,URL and URN-

Association
specifies the cardinality between Entity Types. When an Association is created, a Navigation Property
of the Entity Type is also generated. The Navigation tells the relationship between entities with the
help of Association which it points to and the Association, in turn, tell the cardinality relationship
between entities.
Batch
In some cases, business entity instances may logically belong together and need to be handled or
processed together in the same logical unit of work. For example, on a sales order, an update of two
or more related item entries could be required and must be processed together in a single request
(all or none).
OData Batch requests allow the grouping of multiple operations into a single HTTP request payload.
The components of a batch request, how the request is handled, and the components of the batch
response have some significant differences from components and processing of a normal,
singleoperation OData request.
The main difference between an OData batch request and a normal OData request is that a batch
request is represented as a Multipart MIME v1.0 message as specified in RFC2046. This standard
format allows multiple parts of various content types to be represented within a single overall
request.
A ChangeSet is an atomic unit of work that is made up of an unordered group of one or more of the
insert, update or delete operations… ChangeSets cannot contain retrieve requests and cannot be
nested (i.e. a ChangeSet cannot contain a ChangeSet).

Core data service(CDS.)


According to SAP, CDS Brings Conceptual and Implementation Level Closer Together. With CDS, data
models are defined and consumed on the database rather than on the server. CDS also
offers capabilities beyond the traditional data modeling tools,including support for conceptual
modeling and relationship definitions, built-in functions, and extensions. Originally, CDS was available
only in the design-time and runtime environment of SAP HANA. Now, the CDS concept is also fully
implemented in SAP NetWeaver AS ABAP, enabling developers to work in the ABAP layer with ABAP
development tools while the code execution is pushed down to the database. CDS is an
infrastructure layer for defining semantically rich data models, which are represented as CDS views.
In a very basic way, CDS allows developers to define entity types (such as orders, business partners,
or products) and the semantic relationships between them, which correspond to foreign key
relationships in traditional entity-relationship (ER) models. CDS is defined using an SQL-based data
definition language (DDL) that is based on standard SQL with some additional concepts, such
as associations, which define the relationships between CDS views and annotations, which direct the
domain-specific use of CDS artifacts. Another example is expressions, which can be used in scenarios
in which certain CDS attributes are considered as measures to be aggregated.
Similar to the role of the DDIC in the traditional ABAP world, data models based on CDS serve as
central definitions that can be used in many different domains, such as transactional and analytical
applications, to interact with data in the database in a unified way . However, CDS data models go
beyond the capabilities of the DDIC, which were typically limited to a transactional scope (think of
traditional online transaction processing functionality). For example, in CDS, you can define views
that aggregate and analyze data in a layered fashion, starting with basic views and then adding
powerful views that combine the basic views. Another difference is the support for special operators
such as UNION, which enables the combination of multiple select statements to return only one
result set.
CDS artifacts are stored in the DDIC and can be accessed in ABAP programs via Open SQL in the same
manner as ordinary ABAP tables or views.
In simple words:
Core data services are a new infrastructure for defining and consuming semantically rich data model
in SAP HANA. Using a data definition language (DDL), a query language (QL), and an expression
language (EL), CDS is envisioned to encompass write operations, transaction semantics, constraints,
and more .

CDS entities and their metadata are extensible and optimally integrated into the ABAP Data
Dictionary and the ABAP language
When do we need CDS Views?
Answer: It depends on reusability. If the functionality of a view is only needed once, then no need to
create CDS Views. We can use Joins, SQL expressions, subqueries etc in Open SQL for this code push
down. But if we want to reuse a view, need semantical or technical capabilities of CDS that exceed
those of Open SQL (but we try to keep the technical capabilities on the same level, e.g., CDS knows
UNION, Open SQL will know UNION with an upcoming release) or we just want to push down the full
data model to the database, we need CDS.

What is the fundamental difference between HANA CDS and ABAP CDS?
Answer: The subtle differences between CDS in native SAP HANA and CDS in ABAP lies in the view
definition. In both the ABAP and HANA scenarios, views are created on top of existing database
tables that are contained in the DDIC. With CDS in native SAP HANA, we must create the basic entity
types that correspond to the DDIC tables as part of the CDS view definition. With CDS in ABAP, we
can refer to any underlying DDIC table, view, or type from within the CDS view definition, avoiding
the need to “duplicate” the DDIC table definitions on the CDS layer. In the ABAP scenario, the CDS
definitions are considered DDIC artifacts and need to be activated like any other DDIC artifact and
when changes are made, their impact is propagated to dependent artifacts.
What is preferred ABAP CDS or HANA CDS if the client is in ABAP on HANA
DB?
If you use ABAP on HANA DB, you can work directly on the DB and also use HANA CDS there. But
then the CDS objects created are not managed by the ABAP Dictionary meaning you cannot access
them directly with Open SQL and they are not TYPEs in the ABAP TYPE system.
When should we use ABAP CDS and when should we use HANA CDS?
If you run SAP HANA standalone or in a side-by-side scenario (there is no ABAP stack on top) you
cannot use ABAP CDS. You must use HANA CDS.
If you have an ABAP stack on top of a HANA database (an AS ABAP uses the HANA database as
central database) then:
i) If you want to access the CDS entities in ABAP as data types or in Open SQL or if you want to
evaluate the CDS annotations in ABAP, you must use ABAP CDS.
ii) If you do not want to access the CDS entities in ABAP, but you want to transport and upgrade them
like ABAP repository objects, you can use ABAP CDS.
iii) If you do not want to access the CDS entities in ABAP as data TYPEs or in Open SQL, you can use
HANA CDS, which is better integrated into SAP HANA. An access from ABAP is then possible using
Native SQL (ADBC, AMDP) only.

Can we consume ABAP CDS natively in HANA?


Yes we can. For each CDS view a database view (SQL view) is created in the database during
activation. We can access that database view natively if we want to. CDS table functions are managed
by AMDP. The respective database functions can also be accessed natively.
Question: Is it also possible to access the database views (generated by having a corresponding ABAP
CDS view) in HANA natively and simultaneously consider the authorization logic defined in the
corresponding DCL?
Answer: Yes. Open SQL checks the authorization implicitly but is of course translated into native SQL
code doing that on DB level (implicit conditions). Same for the SADL framework that checks the
authorizations itself natively. The problem is that you need to have access to the internal role
representation which is not published and subject to change or you have to build a framework
yourself that parses the role definition and creates the corresponding conditions.
How can we find all CDS views in SAP?
Answer: Check the table TADIR in SE16; PGMID = ‘R3TR’, OBJECT = ‘DDLS’; here we find all DDL
sources and the package of each source in column DEVCLASS. Knowing the package, we can use ADT
(ABAP Development Tool in HANA Studio) to find the DDL sources in ADT.

Examine table DDLDEPENDENCY in SE16; it contains the names of all DDL sources and the names of
the CDS entities (value STOB in column OBJECTTYPE) defined therein as well as the names of the
generated database views (value VIEW in column OBJECTTYPE); (one row for each -> two rows for
each DDL source). => Selecting VIEW for OBJECTTYPE gives you all CDS database views.
Now let us try to open the DDL source of the CDS in SE11.
Check it would prompt us to go to ADT Tools to view it.
Now, let us open the DDL SQL View of the CDS. Note the warning below which says DDL SQL views
are only supported in a limited way by SE11.
Having one name is just not good enough in CDS; we need two names.

One name is for the SQL view that is going to be created in the dictionary (the one we will be able to
look at in SE11), and the other name we have is a name for the CDS view entity, which is viewed and
changed via Eclipse.
PS: We could name both the SQL view and the CDS view the same, but we should not as they are
different things, so the name should reflect the difference.
SQL view is visible in SE11, however, we cannot edit it in SE11.
CDS View entity is the one we should refer to in SELECT statements in our ABAP programs. Although
we can use DDL SQL View in our programs, but we should not.
How can we use CDS views?
Basically, a CDS View is an entity that can be addressed by its name:
in ABAP as a TYPE
in Open SQL as a DATA SOURCE
Basically, a CDS View is an entity that can be addressed by its name in ABAP as a TYPE in Open SQL as
a data source
Seeing a CDS View in SE11 is kind of a technical artifact and we should not address the database view
that is shown there in our ABAP programs. From SE11 you can also navigate to the database object
that is generated from the definition. This database object can even be accessed directly with Native
SQL.
This means we can access our CDS Views directly in ABAP programs or from elsewhere. For
evaluating the semantic properties (annotations) of a CDS View (stored in system tables) we should
use an appropriate API (CL_DD_DDL_ANNOTATION_SERVICE if available in your system).
The database views created from the CDS source code are merely “for technical” reasons. The CDS
source code and the CDS entity defined there should be the “real thing”.
What are the Salient Features of CDS?
1. Semantically Rich Data-Models
2. Domain specific languages (DDL, QL, DCL)
3. Declarative, close to conceptual thinking
4. CDS is completely based on SQL
5. Any ‘Standard SQL’ features (like joins, unions, built-in functions) is directly available in CDS
6. Fully Compatible with Any DB
7. Generated and managed SQL Views
8. Native integration in SAP HANA
9. Common Basis for Domain-Specific Framework e.g. UI, Analytics, Odata, BW,…
@AnalyticsDetails.aggregationBehaviour: SUM
10 Built-in Functions and Code Pushdown
11 Table Functions for Breakout Scenarios
12 Rich Set of Built-in SQL Functions
13 Extensible
14 On model level thru extensions
15 On meta-model level thru annotations
Summary of Core Data Services
SAP claims that whereas a traditional database view is just a linkage of one or more tables, a CDS
view is a fully fledged data model, which, in addition to having extra features that SE11-defined views
do not, can be used even by applications outside of the SAP domain.
Note: We cannot do OUTER JOINs in an SE11 database view (just one limitation to point which CDS
can overcome).
Technically, CDS is an enhancement of SQL which provides us with a data definition language (DDL)
for defining semantically rich database tables/views (CDS entities) and user-defined types in the
database.
The enhancements include:
i) Annotations to enrich the data models with additional (domain specific) metadata. An annotation
is a line of code that starts with an @ sign.
ii) Associations on a conceptual level, replacing joins with simple path expressions in queries
iii) Expressions used for calculations and queries in the data model
CDS views, like the well-known dictionary views created and maintained in transaction SE11,
are managed by the ABAP data dictionary. During activation, a database view is created on the HANA
layer, yet only the ABAP CDS view (defined in a so-called DDL source) has to be transported via the
ABAP Change and Transport System (CTS). Moreover, the functionality provided by CDS views can be
used on all SAP supported databases, we don’t have to worry when transporting these objects in a
heterogeneous system landscape.
CDS views are entities of the ABAP CDS in the ABAP Dictionary that are much more advanced than
the classical SE11 views. We can influence CDS views with parametersthat can be used at different
positions of the DCL. As for classical SE11 views, for a CDS View, a platform dependent runtime object
is generated at the database that we can examine in SE11. When accessing a (CDS) view with Open
SQL (i.e ABAP), the database interface accesses this runtime object. A CDS view is created with a
source code basededitor in Eclipse using a DDL (which ha nothing to do with SQLScript).
For technical reasons, from the source code a classical DB view is generated in SE11 that we can
access like any classical view, but we shouldn’t. Instead, the so-called CDS entity should be
accessed because it carries more meaning than the mere technical DB view and involves new kind of
client handling.
PS: In an upcoming release, the direct access to the DB view of a CDS view will be declared as
obsolete. So, better not to use them if it can be avoided.
We use CDS to model large parts of our application in the Dictionary and use simple Open SQL
SELECTs in ABAP for relatively straight joins and subqueries in ABAP. Some day Open SQL might have
the same power like CDS but it doesn’t mean that those are redundant. Already before CDS, we had
the choice between creating a reusable view in SE11 or programming a join in Open SQL in ABAP. As
a rule of thumb, we created a view if it is used in more than one program and programmed a join
when we needed it only once. That is very similar for CDS, but with much more possibilities
for modeling semantically rich models for reuse in ABAP programs.

Motivation behind Core Data Services


Semantically Rich data-models:
Entity relationship model and is declarative in nature, very close to conceptual concept.Domain
specific languages (DDL, QL, DCL). Declarative, close to conceptual thinking.
CDS is completely based on SQL: Any ‘Standard SQL’ features are directly available like joins, build-in
functions .
Fully Compatible across any DB:
CDS is generated into managed Open SQL views and is integrated into SAP HANA layer. These views
are supported by all major DB.
Support for Annotations:
CDS syntax supports domain-specific annotations that can be easily evaluated by other components,
such as the UI, analytics, and OData services.
@AnalyticsDetails.aggregrationBehaviour
SUM()
Substring() [SQL functions]
Associations:
Simplified definition of views on top of views. Path expressions to navigate along relations.
Extensibility:
We can extend SAP-defined CDS views with fields that will be automatically added to the CDS view
along with its usage hierarchy.
On model level through extensions.
On meta-model level through annotations.

Challenges before hana


Hardware restricted -too expensive and less powerfull
Software – usage of Row store and Sap optimize for OLTP(write)
Design – Insert and update and need of secondary index
Traditional data were write optimized not read optimized

Launchpad Configuration
Link 1 ref - https://blogs.sap.com/2017/11/19/sap-fiori-ui5-app-configuration-in-sap-fiori-
launchpad/
Link 2 ref- https://www.sap.com/documents/2015/08/d2bc1629-5a7c-0010-82c7-eda71af511fa.html
In SAP-Fiori Launchpad, a SAP-UI5 application get accessed using following flow of components:

Create Semantic Object in SAP Fiori Server (Front-end) server


T-code: /n/UI2/SEMOBJ
Semantic object with which we link ‘Business Tile‘ and ‘Target Mapping‘ within ‘Business Catalog’
Create Launchpad Role in SAP Fiori Server (Front-end) server
T-code: LPD_CUST
We define Launchpad roles to link SAP UI5 Application with Tiles
One Launchpad role can have multiple SAP UI5 Application references each will be differentiated
with help of Alias name.
Launchpad role and specific Alias combination will be referred in ‘Target Mapping’ of Catalog
configuration to link one SAP-UI5 application.
Go to t-code -> click on button ‘New Launchpad’ ->

Create Business Catalog


SAP Fiori Designer Url:
http://<host>:<port>/sap/bc/ui5_ui5/sap/arsrvc_upb_admn/main.html
Create Business Group
One ‘Business Group’ can have single or multiple Tile from same Catalog or multiple Catalog
With this ‘Business Group’, we control app/tile accessibility to users in SAP Fiori Launchpad
Create App’s PFCG Role in SAP Fiori Server (Front-end) server
T-code: PFCG
Once ‘Business Catalog’ and ‘Business Group’ gets created, their access needs to be provided to user-
id, for same we create a PFCG role specific to UI5 application which can be assigned to user-ids
For customized app’s accessibility in Fiori Launchpad page, one user-id will be assigned two PFCG
Roles, which are:
Role assignment to user-id
Suppose 1 user-id ‘DP’ needs to access our tes app, then we need to assign PFCG role to this user-id
In SAP-fFori server, Go to t-code ‘SU01’ -> Tab ‘roles’ -> add roles
SD FLOW
Sales and distribution module is a part of logistics and it handles all the process of order to delivery,
Sales Order: Once we receive the purchase order from customer then as a vendor we need to
raise the sales order, while raising sales order we should know the partner functions.
Sold-To-Party – who as raised the purchase order.
Ship-To-Party – where we need to deliver the goods.
Bill-to-party – to whom we have to give the bill.
Payer – who is going to pay the money?
Commonly used SAP SD tables:
Sales Documents:
VBAK – Sales Document: Header Data VBAP -Sales Document: Item Data
VBUP – Item Status VBFA – Sales Document Flow
VBUK – Header Status and Administrative Data
Delivery Tables:
LIKP – SD Document: Delivery Header Data
LIPS – SD document: Delivery: Item data
Customer Tables:
KNA1 – General Data in Customer Master KNVV – Sales area data
KNB1 – Customer Master (Company Code)
KNB5 – Customer master (dunning data) KNBK – Customer Master (Bank Details)
Pricing Tables:
KONV – Conditions (Transaction Data) KONH – Conditions (Header)
KONP – Conditions (Item)
Billing Tables:
VBRK – Billing Document: Header Data VBRP – Billing Document: Item Data
Shipping Tables:
VEKP -Handling Unit – Header Table
VEPO – Packing: Handling Unit Item (Contents)
Vendor Tables:
LFA1-Vendor Master (General Section) LFB1-Vendor Master (Company Code)
LFB5-Vendor master (dunning data) LFBK -Vendor Master (Bank Details)
Link Between SD and MM.

MM Flow
Transaction codes:
Purchase Requisition – ME51N
Request for Quotation – ME41
Vendor Evaluation – ME61
Purchase Order – ME21N
Goods Receipt – MIGO
Invoice Verification – MIRO
Goods Issue -MB1A
Physical Inventory – MI01
Frequently used tables:
MARA – General Material Data MARC – Plant Data for Material
MARD – Storage Location Data for Material MAKT – Material Descriptions
MVKE – Sales Data for materials MSEG – Document Segment- Material
MBEW – Material Valuation MKPF – Header- Material Document
EKKO – Purchasing Document Header EKPO – Purchasing Document Item
EBAN – Purchase Requisition EBKN – Purchase Requisition Account Assignment
EINA – Purchasing Info Record- General Data MAKT – Material Descriptions
EINE – Purchasing Info Record- Purchasing Organization Data
LFA1 – Vendor Master (General section) LFB1 – Vendor Master (Company Code)
T023 – Mat. Groups T024 – Purchasing Groups
T156 – Movement Type

Das könnte Ihnen auch gefallen