Abap
Abap
Abap
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.
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
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
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
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
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 .
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.
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
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.
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
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.
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.
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
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:
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.
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
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
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.
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.
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.
We need to handle the errors and the success messages by declaring an internal
table of type BDCMSGCOLL.
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).
In this type the call transaction screens will communicate with the update work process to
update the data into database.
It immediately starts to process the next record without waiting for the update to be
finished.
It is generally not recommended for the large amount of data, because the called transaction
does not return any success or error messages.
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.
It is generally recommended for large amount of data because it returns success and error
messages.
MODE:
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.
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'] ).
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'.
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)
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).
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.
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.
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:
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