Table of Contents
Dear friend, welcome to the world of ABAP programming! As an experienced SAP architect, I‘m excited to take you on a deep dive into application development with ABAP.
Over the next few minutes, we‘ll unpack what makes ABAP tick along with techniques to build custom enterprise apps.
Let‘s get started!
Why Learn ABAP?
Before jumping into ABAP syntax and concepts, it‘s reasonable to ask – why ABAP?
Well, ABAP remains the heart of SAP. It powers over 400,000 enterprise installations worldwide.
A 2021 survey by StackOverflow also showed ABAP as one of the top paying technologies globally with an average salary of $93,000!
As this Forrester data shows, ABAP is still going strong:
With critical SAP processes relying on custom ABAP programs, it is a crucial skill for every SAP consultant.
I‘m not exaggerating when I say mastering ABAP can turbocharge your career!
ABAP Programming Model
The core of ABAP lies in programs which encapsulate business logic.
Here is how a simple ABAP program looks like:
REPORT zmy_program.
START-OF-SELECTION.
"Business logic goes here
END-OF-SELECTION.
As you may have noticed, ABAP uses keywords extensively to define program blocks and logical units. We‘ll explore many such constructs through this guide.
Now within programs, you organize code into reusable elements like – functions, forms, modules and macros.
Let‘s take a quick look at each:
Functions are like methods in OOP terminology. They encapsulate business logic for specific tasks:
FUNCTION post_invoice.
...logic for posting invoice
ENDFUNCTION.
Forms contain logical units of code not divided into modular units:
FORM validate_data.
...input validation logic
ENDFORM
Modules contain code for standard SAP dialog interactions:
MODULE init_screen.
...logic to init dialog screen
ENDMODULE.
And Macros are templates inserted during preprocessing:
DEFINE make_heading.
END-DEFINE.
make_heading ‘Post Invoice‘.
Now that you have a high-level view, let‘s dig deeper into core concepts…
Data Types and Variables
Like with any programming, you need variables and data types to store information.
Here is an overview of available basic types in ABAP:
So for example, you define variables like:
DATA name TYPE string LENGTH 50.
DATA age TYPE i.
DATA total type p LENGTH 8 DECIMALS 2.
Easy enough right?
In addition, complex types like structures, internal tables and classes allow modelling real-world entities:
TYPES: BEGIN OF employee_type,
id TYPE i,
name TYPE string,
date_hired TYPE dats
END OF employee_type.
DATA employee TYPE employee_type.
Now let‘s explore some ABAP operators…
Operators
Operators allow manipulating variables and parameters.
Here are commonly used operators:
+ - Addition and Subtraction
* / Multiplication and Division
MOD - Modulus
= EQ - Check Equality
> LT - Compare size
& - String Concatenation
You use them in expressions like:
salary = hours_worked * pay_rate.
full_name = first_name && last_name.
Additionally, parentheses ( )
control order of operations like in math:
tax_amount = (gross_salary – deductions) * tax_rate.
So that handles the basics! Now let‘s explore powerful techniques for business logic processing…
Internal Tables
A key aspect of data handling in ABAP is using internal tables.
These represent arrays of data stored in memory for fast access. Think in-memory databases!
Here is how you would create an internal table:
TYPES: BEGIN OF line_type,
id TYPE i,
text TYPE string,
END OF line_type.
DATA records TYPE STANDARD TABLE OF line_type.
This defines:
- A row structure (
line_type
structure) - An internal table
records
based on this structure
We can then easily populate and read rows:
APPEND INITIAL LINE TO records ASSIGNING field.
field-id = 1.
field-text = ‘First Row‘.
LOOP AT records INTO row.
WRITE: / row-id, row-text.
ENDLOOP.
With thousands of rows possible in memory, it unlocks blazing fast processing!
There are 3 categories of internal tables in ABAP:
Type | Description |
---|---|
STANDARD | Generic array based on row type |
SORTED | Rows sorted by key – binary search |
HASHED | Rows hashed for faster access |
Each optimized for different data access patterns.
Let me know in the comments if you want me to elaborate more on any specific type!
Now let‘s explore database interaction at the heart of business applications…
Native SQL and OpenSQL
ABAP relies on external databases like SAP HANA to persist data.
The OpenSQL interface provides simple CRUD access to database tables without coding SQL yourself.
For example:
OPEN CURSOR flight_cursor FOR
SELECT * FROM spfli.
READ CURSOR flight_cursor INTO wa_flight.
This retrieves flight data into internal table using cursor.
However, for complex scenarios – Native SQL gives you direct access:
SELECT *
FROM spfli
INTO TABLE itab
WHERE carrid = ‘AA‘.
As you can see, ABAP + SAP HANA delivers best-in-class data access abilities!
Now let‘s shift our focus to UI programming…
User Interfaces with Dynpros
ABAP offers two ways for building UIs – classical dynpros and web-based WDAP.
Classical Dynpros consists of Screens and GUI Status defined using Domains and Data Elements from ABAP Dictionary.
Here is the flow:
PBO – Process Before Output -> Display Screen
PAI – Process After Input -> Read User Input
A sample dynpro screen would be:
PROCESS BEFORE OUTPUT.
MODULE set_screen_fields.
PROCESS AFTER INPUT.
MODULE read_screen_inputs.
The logic modules handle validating inputs, populating outputs etc.
For web UIs,Web Dynpro ABAP (WDAP) adopts a modern component-based approach.
It separates view and controller using UI elements and windows/views.
<wd:viewController>
<wd:view>
<wd:TextField value="{name}"/>.
</wd:view>
</wd:viewController>
As you can see, ABAP supports creating both traditional and modern UIs!
Now let‘s explore popular reporting techniques…
ABAP Reporting
Reporting is arguably the most common ABAP activity.
So how do reports work?
Well every report is an ABAP program starting with REPORT
command.
REPORT z_flight_display.
START-OF-SELECTION.
"Get data
WRITE: flight_data.
The key events are:
- Get required data in
START-OF-SELECTION
- Display output using
WRITE
or other commands
For tabular outputs, the SALV library makes it extremely easy!
DATA: alv TYPE REF TO cl_salv_table.
alv = cl_salv_table=>factory( table = flight_data ).
alv->display( ).
This instantly generates an ALV grid for the internal table!
With over 100 ALV parameters, the displaying possibilities are endless 🙂
Now let‘s explore some integration techniques…
Exchanging Data
A key aspect of SAP systems is exchanging data.
Here are some popular exchange mechanisms in ABAP:
BDC allows batched recording and simulation of data transfer scenarios. Useful for uploading CSV-like data.
IDocs enable document-based exchange with external systems like EDI.
Here is an outbound IDoc send in ABAP:
DATA: control TYPE bapicontrol,
idoc_data TYPE bapiret2.
control-idoc_control = ‘MYIDOC01‘.
CALL FUNCTION ‘MASTER_IDOC_DISTRIBUTE‘
EXPORTING
control = control
master_idoc = idoc_data.
BAPIs provide standard interfaces to access SAP data model and processes:
CALL FUNCTION ‘BAPI_SALESORDER_CHANGE‘
...
TABLES
salesorder = sales_order.
See how BAPIs enable updating critical data like sales orders via APIs!
I‘ve just scratched the surface here – each technology has a lot more to explore. Ping me if you need any help!
Now let‘s look at SAP enhancement options…
Enhancing Standard SAP Functionality
A common use case is enhancing standard SAP programs without modifying source code.
This is achieved using:
Customer Exits – Activated after SAP release
User Exits – Activated during development
Here is an example user exit:
FORM USEREXIT_DO_SOMETHING USING par1 TYPE any.
... "Custom logic
ENDFORM.
This gets triggered from standard SAP code to enable customization.
Similarly, Business Add-Ins (BAdIs) also allow enhancing SAP applications without modification.
For example:
INTERFACE lif_badi_01.
METHODS: do_something.
ENDINTERFACE.
CLASS lcl_enhancement DEFINITION.
INTERFACES lif_badi_01.
...
ENDCLASS.
As you can see, highly flexible and non-intrusive ways to customize systems!
We have covered a lot of ground so far. Now let‘s shift gears and explore OOPs concepts…
Object-Oriented ABAP
So far we focused on procedural constructs. However, ABAP also incorporates object-oriented concepts since Release 4.5.
Let‘s look at core OOP terminology:
Classes encapsulate data and methods:
CLASS lcl_flight DEFINITION.
PUBLIC SECTION.
METHODS: display_details.
DATA: carrid TYPE s_carr_id.
PRIVATE SECTION.
ENDCLASS.
Interfaces define method signatures classes must implement:
INTERFACE lif_display_data.
METHODS: show_details.
ENDINTERFACE.
Inheritance enables specializing existing classes:
CLASS lcl_airplane DEFINITION INHERITING FROM lcl_flight.
With these pillars + concepts like polymorphism and patterns, ABAP provides enterprise-grade OOP support!
We have explored quite a lot so far. Now let me share some closing thoughts…
Closing Notes
I hope walking through core ABAP concepts has shed light on what makes it tick!
Here are the key takeaways:
- ABAP is the beating heart of SAP systems powering business logic
- Mastering development unlocks huge career opportunities
- Programming model relies on reusable elements like functions
- Tables, internal tables and SQL for data storage and access
- Dynpros and Web Dynpro for building traditional + modern UIs
- Strong integration and reporting capabilities
- Enhancement options without source code changes
- Robust object-oriented support
Obviously we could go much deeper on each topic. I encourage you to use help documents for detailed reference.
It might feel overwhelming initially – so take it slow with hands-on practice.
Trust me, with time, everything gels well together!
If you have any other questions or need help with specific concepts – please ask below!
Now over to you my friend! Go-forth and build awesome enterprise apps.
Happy ABAPing! 🚀