From ABAP mindset to Python mindset without pretending your SAP experience does not matter
Chapter Goal
The Shift
In ABAP, the SAP system gives you a lot of structure. You have tables, data elements, domains, function modules, classes, packages, transports, and built-in reporting tools like ALV.
In Python, you build more of that structure yourself. That can feel strange at first, but it also means you can create small tools, reports, dashboards, automations, and cloud-ready apps without waiting for every piece to live inside the SAP system.
Important: This chapter is not asking you to abandon ABAP thinking. It is helping you translate it. Your ABAP experience is an advantage.
Concept Map: ABAP to Python
ABAP Concept
Python Concept
Plain-English Translation
Internal table
List of dictionaries, pandas DataFrame
A collection of rows
Work area
Dictionary or object
One row or one structured record
SELECT from database table
SQL query through a database connector
Read records from a database
ALV grid
Bokeh DataTable, HTML table, Streamlit table
Interactive output for users
Function module
Function, module, package, API call
Reusable logic or a reusable service
Transport request
Git commit / deployment pipeline
A controlled way to move changes
Internal Tables vs Python Lists
ABAP developers often start with internal tables because almost everything in reporting eventually becomes a table of records. Python can represent table-like data in different ways. The simplest is a list of dictionaries.
ABAP
DATA: lt_materials TYPE TABLE OF mara,
ls_material TYPE mara.
ls_material-matnr = '10000001'.
ls_material-mtart = 'FERT'.
APPEND ls_material TO lt_materials.
A Python list of dictionaries is flexible and easy to understand. Later, when we want filtering, grouping, exporting, or charting, we will often convert this kind of data into a pandas DataFrame.
Work Area vs Dictionary
A work area usually represents one record. A Python dictionary can serve the same purpose.
material = {
"matnr": "10000001",
"maktx": "Demo Material"
}
ABAP Mindset: Think of a dictionary as a lightweight structure where each field has a name and a value.
SELECT Statements: You Have More Than One Python Path
The first version of this chapter jumped from ABAP SELECT statements straight to APIs. That is a valid modern path, but it is not the only path. Many developers first need to understand how Python reads data from familiar places: databases, CSV files, Excel files, and then APIs.
Better mental model: ABAP usually reads data from SAP tables. Python reads data from wherever the data lives.
Path A: ABAP SELECT vs Python SELECT from PostgreSQL
If you are not ready to think in APIs yet, start with a relational database. The idea is familiar: connect, run SQL, receive rows, display or process the result.
ABAP
DATA: lt_materials TYPE TABLE OF mara.
SELECT matnr, mtart, matkl
FROM mara
INTO TABLE @lt_materials
UP TO 100 ROWS.
In production environments, your team may prefer a specific driver or SQLAlchemy, but this is enough to understand the basic idea.
The connection is the database session. The cursor is the object that sends the SQL and receives the result. The rows are your internal table equivalent.
Path B: ABAP SELECT vs Python SELECT with pandas
For reporting work, pandas is often more convenient because it gives you a table-like object called a DataFrame. This feels closer to working with an internal table that also has built-in analysis functions.
ABAP
SELECT matnr, mtart, matkl
FROM mara
INTO TABLE @DATA(lt_materials)
UP TO 100 ROWS.
Python Translation: A pandas DataFrame is not exactly an internal table, but for reporting and analysis, it will often feel like your most natural bridge from ABAP.
Path C: Reading CSV or Excel Instead of a Database
Many useful Python tools start with exported data. Maybe someone gives you a CSV file, an Excel workbook, or a flat file from another system. You can still build something valuable without connecting directly to SAP or another database.
CSV
import pandas as pd
df = pd.read_csv("materials.csv")
print(df.head())
Excel
import pandas as pd
df = pd.read_excel("materials.xlsx")
print(df.head())
Filter
fert = df[df["mtart"] == "FERT"]
print(fert)
You can practice Python reporting without dealing with credentials, firewalls, SAP authorizations, or network access. That makes CSV and Excel perfect for early projects.
Path D: SELECT vs API
Once you are comfortable with files and databases, APIs become easier to understand. Instead of selecting from a table, you request data from an endpoint.
ABAP
SELECT matnr, mtart, matkl
FROM mara
INTO TABLE @DATA(lt_materials)
UP TO 100 ROWS.
Python + API
import requests
url = "https://example.com/api/materials"
response = requests.get(url)
response.raise_for_status()
materials = response.json()
for material in materials:
print(material["matnr"])
With an API, you usually do not control the SQL. The service decides what data is available, how it is filtered, and how it is returned. Your Python program becomes the consumer of that service.
Looping Through Data
Looping is one of the easiest concepts to translate.
ABAP
LOOP AT lt_materials INTO DATA(ls_material).
WRITE: / ls_material-matnr,
ls_material-mtart.
ENDLOOP.
Python
for material in materials:
print(material["matnr"], material["mtart"])
Common mistake: Python indentation matters. In ABAP, keywords close your blocks. In Python, indentation defines the block.
IF Conditions
Conditional logic is also very similar once you get used to Python syntax.
if material["mtart"] == "FERT":
print("Finished product")
else:
print("Other material")
Functions: FORM, Function Module, or Method?
Python functions are small reusable blocks of logic. Do not make this more complicated than it needs to be at first.
ABAP
FORM format_material USING iv_matnr TYPE matnr
CHANGING cv_text TYPE string.
cv_text = |Material: { iv_matnr }|.
ENDFORM.
Python
def format_material(matnr):
return f"Material: {matnr}"
text = format_material("10000001")
print(text)
Python Translation: Start with functions. Later, when your project grows, you can move into modules, classes, and packages.
ALV vs Bokeh
ABAP developers love ALV because it gives users a usable table quickly. Python does not have ALV, but it has several ways to create interactive output. For this book, our first ALV-like path will use Bokeh.
Bokeh can create interactive browser-based output without requiring a full web application at the beginning. That makes it a friendly bridge from classic report output to modern dashboard output.
Mini Exercise: Translate This in Your Head
Before going to the first full project, try to mentally translate this ABAP pattern:
SELECT matnr, mtart
FROM mara
INTO TABLE @DATA(lt_materials)
WHERE mtart = 'FERT'.
LOOP AT lt_materials INTO DATA(ls_material).
WRITE: / ls_material-matnr.
ENDLOOP.
import pandas as pd
df = pd.read_csv("materials.csv")
fert_materials = df[df["mtart"] == "FERT"]
for _, material in fert_materials.iterrows():
print(material["matnr"])
Checkpoint: You do not need to memorize every package yet. You only need to understand the shape of the translation: read data, store it in a table-like structure, filter it, loop through it, and display it.
Chapter 1 Checkpoint
You understand that Python can read from databases, files, and APIs.
You can compare an ABAP internal table to a Python list of dictionaries or pandas DataFrame.
You can compare a work area to a dictionary.
You understand why pandas will be useful for SAP-style reporting.
You understand why Bokeh is a good first replacement for simple ALV-style output.
Next: In Chapter 2, we build the first useful project: an ABAP-style material table report rebuilt in Python with pandas and Bokeh.
Think Like Python: A Guide for ABAP Developers — Chapter 1