Sap Abap Basics
Sap Abap Basics
We can maintain data within a table using SE11, SE16N, or SE16. However, we
cannot directly add values to a table; instead, we use the table maintenance
generator.
Append structure: It is not a reusable structure and can only be inserted at the
end. It is applicable to both customer and SAP tables.
View : View is a virtual table, it is logical database, it is don’t have any data.
Brings data from different tables
Types:
- Database view: A combination of multiple views.
- Projection view: A single table view that selects only the required fields.
- Maintenance view: This view maintains the values for multiple views as a single
view. Each entry should only appear once in both the header and item table. The
relationship cardinality needs to be 1:1.
Pre-requirement: Tables must have a relationship between them.
- Help: Used in search assistance. (The relationship cardinality needs to be 1:1.)
In Help View, I can’t display the contents. We can display this view’s contents using
the Search Help feature.
INDEX:
An index is created to provide high performance, always storing data in a sorted
index.
Occupy space in the database. Store in database as ZI~data
Search help
Search help, also known as F4(value help) help, displays the possible values for an
input field.
Search help 2 types
Elementary search help, or single search help, provides information about a
single search term.
Collective search help, or combination search help, combines information from
multiple elementary search terms.
Selection Method: It is the name of the table or the name of the view from
which we are fetching the data.
Dialog Type:
- Display values display: The values are displayed immediately.
- Dialog with values restriction: Before displaying the values, a restriction dialog
will appear.
– Dialog depends on the set of values: If the table has less than 100 values,
it will immediately trigger a dialog box.
Table Buffering:
- Buffer: Temporary storage in the application layer.
- Improves performance: When accessing data records in the table.
Buffering Types:
- Single Record Buffered: This type is used when we are performing a filter on a
table with a key field.
- Generic Area Buffered: This type is used for records that match a generic key,
defined by the user. It is used on language-dependent tables. For example, if we
need to retrieve English language record values, we would use this generic area
buffer.
- Full Buffering: This type is used for tables that are frequently accessed and
rarely changed. However, it is important to note that full buffering should not be
activated for transactional data.
Lock objects.
Lock objects are used to synchronise data. If multiple users are trying to change
the data, only one user will be able to change it, while the others will be locked.
Tcode SM12 allows you to view lock attempts. If we lock entries coming from the
enqueue server, these are temporary entries.
Types of lock
Read lock (shared lock): The default value is ’S’. Other users can display the data,
but they cannot change it.
Write lock (exclusive lock, Change lock): The default value is ‘E’. It prevents other
users from displaying, reading, or writing the data. A same user can request this
lock multiple times during the same transaction.
Enhanced write lock (exclusive lock without cumulation): The default value is ‘X’. It
prevents other users from displaying, writing, or reading the data. It also
prevents the user from requesting multiple accesses for the same transaction.
To create lock objects, we must begin with a prefix of either ‘EZ’ or ‘EY’.
Whenever we create an active lock object, it automatically creates two function
modules: ENQUEUE and DEQUEUE.
Check Table:
• Check Table Functionality: Checks field values and restricts possible
values.
• Check Table Definition: Defines the set of all possible entries to a field.
• Input Help: Contents of the check table are automatically offered as
input help.
Value Table :
● Value Table Function: Value table works at domain level and checks table
fields referring to a domain.
● Value Table Definition: A value table is defined in a domain when table fields
need to be checked against a certain table.
● Value Table as Check Table: A value table becomes a check table when a
foreign key is defined.
*************************REPORTS*************************
Classical Reports:
Whenever we display output using the write statement called as classical report.
We can provide input to the programs through parameters(single) and select
options.(multiple or Range )
SQL (Structured Query Language) has two types: open SQL and native SQL.
● Open SQL operates independently of the database.
● Native SQL is dependent on the specific database system.
Selecting items based on a header table internal table means that only the values
present in the header table will be checked in the item table
JOINS
Joins allow us to fetch data from multiple tables.
Inner join: A inner join finds and returns the matching data from tables based
upon the condition.
If no condition is met, no records will be retrieved.
Outer join
An outer join finds and returns matching data from both tables, as well as non-
matching data from the table.
There are two types of outer joins: left outer join (left join) and right outer join
(right join).
- A left outer join takes all the data from the left table and combines it with the
values from the right table to meet the criteria.
- A right outer join takes all the data from the right side table and combines it
with the values from the left side table that meet the criteria.
Column Labels:
Column labels are used to display the names of the columns or fields in the output
screen.
Instead of hardcoding the field names to display in the output screen, we can use
the text elements feature.
Text Elements.
Text symbols are data objects that are not declared within the program and are
part of text elements.(000 to 999)
If we want to translate the English language to German, we need to go to Edit,
Translation, and add the German language in text elements.
Add vertical lines for fields in the output screen using the Sy-vline.
Sy-uline for horizontal line.
Message Classes
The Message class plays a crucial role in displaying messages to the end user. In
ABAP, there are various types of messages, including Abort (A), Error (E),
Information (I), Success (S), Warning (W), and Exit (E).
Transaction code : SE91.
We can declare the message class at the start of the program so we can use it
every time.
- Never use the asterisk (*) in your query; instead, only fetch the required
columns.
- Ensure that the column fetching sequence in your query matches the order of
columns in your data dictionary.
- The where condition column sequence should be as similar as possible to the
data dictionary column sequence.
- Avoid using the corresponding keyword in your query.
- For traditional databases, avoid using joins; instead, use the “for all entries in”
clause. (HANA is not a traditional database, so we can use joins.)
– When retrieving data from foreign key or dependent tables, verify if the
subquery=0 results in 0 or if the internal table remains uninitialised.
– Employ binary search to access the internal table (sorting is mandatory).
– Use Parallel cursor in nested loops.
– Parallel cursor - Improves performance for nested loops.
– Sy-tabix = Current index in loop.
–
– The parallel cursor method works like a nested loop. It checks the condition
of the outer loop and goes inside the inner loop. It loops until it fails, then
comes out of the inner loop and starts from the outer loop, trying different
values.
– Never write a query inside a loop.
1. Initialisation
2. At the selection screen
3. The start of the selection
4. The end of the selection
5. The top of the page
6. The end of the page
7. At the selection screen, output data
8. At the selection screen, requesting a value for a field
9. At the selection screen, requesting help for a field
10. At the selection screen, on a field
Example selection screen for below logic.
Initialisation:
This event triggers before (F8) displaying the selection screen. Its purpose is to
provide default values for parameters and options on the selection screen.
At selection screen:
This event is triggered when a user performs an action (such as entering or
clicking any thing on screen include F8 ) on the selection screen. Its purpose is to
validate the input; if the input is incorrect, it throws an error.
Start of selection.
The event occurs when the user presses the “Execute” F8 button on the section
selection screen. The selection logic is part of this event.
***Even after pressing the execute F8 button, the selection screen first validates
the input. If the input is correct, it moves to the start of the selection.
End of selection :
This event is triggered when the selection process ends, helping to identify the
end of records.
Top of Page :
This event is triggered when the first write statement occurs in a program. Its
purpose is to provide a title or header at the beginning of a new page.
SY-PAGENO it will automatically prints page number.
End of Page :
When a last write statement occurs on a page, this event will automatically
trigger.
Lines 10(2) means 2 are reserved for the end of the page
- At line selection
- At user command
- Top of the page during line selection
At line selection:
When the user double-clicks on a line or selects a line and presses F2(choose), or
when the user selects a line and clicks, the line-selection event triggers.
SY-LISEL: Which returns the contents of the selected row.
AT User Command :
Whenever we create our own function, this event will trigger. The ‘sy-ucomm’
system variable is used to capture the values within the function code.
Example : This event will trigger when the function outputs the order on the
display screen based on a PO number in ascending and descending order.
We need to create a function within our program that will display when we
double-tap on it. We can then create this function in the application toolbar.
• Event Trigger: Occurs on the first WRITE statement for a new page on
the secondary list.
• Event Purpose: To display a title or header at the beginning of a new
page in secondary list.
Field symbol.
• Field Symbol Definition: Placeholders for data objects that don’t reserve
physical memory space.
• Field Symbol Syntax: `FIELD-SYMBOLS <fs>`, where `<fs>` is the name
of the field symbol.
• Generic Field Symbol: Field symbols with generic data types like `ANY`
and `ANY TABLE`, used for dynamic programming.
ALV, also known as Application List Viewer or ABAP List Viewer, offers several
inbuilt features. These include sorting data in ascending or descending order,
filtering data, exporting data, and calculating the sum of amounts in specific
columns.
OOPS ABAP.
Inheritance.
By inheriting the properties of the parent class, the child class can be created.
The final class cannot be inherited.
Abstract Class.
● Abstract Class Definition: A special type of class with at least one abstract
method.
● Abstract Method: A method with only a definition, lacking implementation.
● Object Creation: Objects of an abstract class cannot be created; only objects
of its subclasses can be created.
Never take an abstract class with a final.
Steps:
1. Create an Abstract class in SE24.
2. Create a subclass for the same by giving the abstract class as a
property(super class) in the subclass.
3. Redefine the Abstract method in the subclass to write the code in the subclass
method using the keyword “Redefinition”.
Polymorphism
(Taking Abstract class for polymorphism example)
Polymorphism is the ability for a single method definition to behave differently
based on the class implementation being called.
Method overriding:
● The task is performed in two classes with an inheritance relationship
(superclass method and subclass method).
● In method overriding, methods must have the same name and signature.
● The behaviour of the parent class is changed in the subclass.
Interface :
● In interface, all methods are public by default.
● In the interface, all methods are Abstract methods (there is only definition, no
implementation).
Interface is also exhibiting the properties of Polymorphism.
Key Concepts:
. Inheritance: Class 3 inherits features (methods/attributes) from both Class 1
and Class 2.
. Polymorphism: Class 3 can override or redefine methods from parent classes.
This flow shows how Class 3 utilises functionalities from Class 1 and Class 2,
enabling code reusability and efficient object-oriented programming in SAP ABAP.
Events
● Events: Method of one class can call method of another class.
● Triggering Method: which will raise method.
● Event handler method: which will handle the method.
● Register event handler method using set handler method.
Modifications: We will enhance the SAP functionality in the SAP namespace. The
name of the namespace should not start with Z or Y).
Implicit Enhancement:
- Implicit point: can be found at the start or end of a line.
- We create an implicit enhancement at those points
Steps: Edit->enhancement operation-> show implicit enhancement.->create
implementation
Explicit Enhancement:
- Explicit point and section are available at any line.
- We create explicit enhancements at those points and sections.
Function module Exit allows us to add our code to SAP programs using function
modules.
● Syntax: CALL CUSTOMER-FUNCTION ‘three digit number’.
● The three digit number in the above syntax can vary from 000 to 999.
• Example: CALL CUSTOMER-FUNCTION ‘001’.
How to find an exit?
Put the brake point in the call customer-function, trigger the debugger mode,
check will function is satisfy our requirement.
We can find with the help of package in Tcode SMOD to implement the function
module exit Tcode is CMOD.
Menu Exit.
● Menu Exit Functionality: Allows adding menu items to SAP programs with
function codes starting with “+”.
● Menu Item Purpose: Enables customer-specific functionalities within SAP
programs.
How to find Menu exit?
• Menu Item Check: Check for menu items starting with “+” in the menu
bar.
• Package Name Retrieval: Use SMOD transaction code to find the
package name of the program.
• Customer Exits Access: Use transaction code SE84 to access
enhancements and customer exits.
Screen Exit
● Screen exit allows us to add fields to the screen of SAP programs using the
customer sub screen. SAP provides sub-screen areas within a standard screen.
The customer sub screen is called within the standard screen flow logic.
● To call a customer sub screen into a standard screen, use the syntax:
● CALL CUSTOMER-SUB SCREEN ‘sub screen area’ INCLUDING ‘program name’
‘customer sub screen number’.
● For example, you could call the customer sub screen “custscr2” within the
standard screen “SAPLXT” with the sub screen number “2000”.
BADI
● BADI Definition: BADI is an enhancement that enhances SAP functionalities
within the customer namespace.
● BADI Basis: BADI is based on OOPS concepts, including interfaces and classes.
● BADI Transaction Codes: SE18 and SE19 are used for defining and
implementing BADI, respectively.
Two types of BADI.
● Classic BADI: A traditional enhancement technique in SAP that allows for
custom implementations without modifying the standard code. It relies on
interfaces and is widely used in older SAP systems.
● New Kernel BADI: An advanced version of BADI integrated into the kernel,
providing better performance and flexibility. It supports multiple
implementations and is designed for use in modern SAP environments.
User Exits.
• Definition: Modifications enhancing SAP functionalities within the SAP
namespace.
• Availability: Only available in the SAP SD module and presented as
subroutines.
• Sales Order User Exits: Most important ones are available in program
MV45AFZZ.
Table Functions:
• Additional Functionalities which is not supported in the CDS.
• Write SQL statements for the requirement.
• SQL Script functions and methodologies.
Table Function Technical Design
● Has optional input parameters.
● Has return parameters (multiple records).
● Needs Class and Methods to define. - Class: Public, Method: Static.
● Interface: IF_AMDP_MARKER_HDB.
## Basic View:
● - Constructed atop DDIC tables or views.
● - Interacts with the database to retrieve data.
● - Source: Table or view.
● - Syntax: @VDM.Viewtype: #BASIC
## Composite View:
● - Created atop the BASIC view.
● - Does not engage with the database to retrieve data.
● - Multiple fundamental views can serve as sources.
● - Source: BASIC view.
- Syntax: @VDM.Viewtype: #COMPOSITE
## Consumption View:
● - Constructed atop the COMPOSITE view.
● - Excludes direct interaction with the database or fundamental views.
● - Provides users with data in diverse formats, including U15, HTML, Excel, BO,
and Lumira.
● - Source: COMPOSITE view.
● - Syntax: @VDM.Viewtype: #CONSUMPTION
Data Categories:
● Fact:
● Represents Transaction Data.
● - Contains measures.
● - Should not be joined with Master data views.
● - @Analytics.dataCategory: #FACT.
- Cube:
● - Represents Transaction Data (similar to #FACT).
● - Can be joined with Master data views.
● - Consumption views are constructed atop the Cube.
● - @Analytics.dataCategory: #CUBE.
AMDP
ABAP Managed Database Procedures (AMDP) is a feature that enables the direct
implementation of database procedures within ABAP classes using SQLScript.
● AMDP offers several key features, including a technical design similar to Table
Functions, support for importing and exporting parameters, the ability to
return multiple values, and the option to invoke it from ABAP objects.
Authorisation check:
@Analytics.query: true means the query needs to hit the view, not a table.
IDOC is a standard data structure used in SAP for transferring data between
SAP systems and external systems. It facilitates seamless communication in
distributed environments.
IDOC Lifecycle:
. Creation: Triggered by an event, transaction, or program.
. Outbound Processing: IDOC is populated with data and sent to the external
system.
. Inbound Processing: Received by the target system and processed based on
configuration.
. Monitoring: IDOC status can be monitored using Tcodes WE02 and WE05.
Release Number:
● The IDOC’s release number indicates the SAP version compatibility.
● Ensures that the IDOC structure aligns with system version requirements.
IDOCs play a critical role in enabling integration and data exchange across SAP
modules and external applications, ensuring efficient business process automation.
Navigation in OData:
● Associations and Navigation Properties are used to define relationships
between different entity types.
● Example: An Order entity may have a relationship with an Item entity.
○ Association: Links the two entities.
○ Navigation Property: Allows navigation from Order to Items.
OData Annotations:
Annotations enhance the metadata and functionality of OData services:
● @UI.lineItem: Defines how data should be displayed in Fiori apps.
● @Consumption.filter: Enables filters on fields.
● @Analytics.query: Defines analytical queries for reporting.
Security Considerations:
● Implement authorization checks within DPC methods.
● Use SAP Gateway roles to manage service access.