ABAP for Web Developers: A Practical Introduction

  • SAP ABAP
  • Learning
  • Backend

An introduction to SAP ABAP for PHP and JavaScript developers: the tools, internal tables, Open SQL, common performance traps and transports.

ABAP is the language used to extend SAP systems. If you come from PHP, JavaScript or Dart, it looks unusual at first: statements end with a full stop, keywords are long and the editor lives inside SAP. Underneath, the ideas are familiar. This is the introduction I would have liked when I started.

Where the code lives

There are no files in a folder. Programs, tables and classes are objects stored in the SAP system itself and edited through transactions: SE38 for programs, SE11 for the data dictionary, SE37 for function modules and SE80 as a general workbench. Many teams now use ABAP Development Tools in Eclipse, which will feel more like a normal IDE.

Custom objects start with Z or Y. That namespace keeps your work separate from SAP's standard code, which you should not modify directly.

Internal tables are your arrays

An internal table is an in-memory list of rows with a fixed structure, similar to an array of objects. A work area or structure is one row. Most ABAP programs follow the same shape: select rows into an internal table, loop, process, output.

SELECT vbeln, kunnr, netwr
  FROM vbak
  WHERE erdat >= @lv_from
  INTO TABLE @DATA(lt_orders).

LOOP AT lt_orders INTO DATA(ls_order).
  WRITE: / ls_order-vbeln, ls_order-kunnr, ls_order-netwr.
ENDLOOP.

Open SQL

ABAP's built-in SQL is called Open SQL, or ABAP SQL in recent releases. It is database-independent and checked by the compiler. Host variables are marked with @. One thing that surprises newcomers: SAP systems are divided into clients, and Open SQL filters by the current client automatically, so you do not add that condition yourself.

Three performance traps

  • A SELECT inside a LOOP runs one query per row. Select once into an internal table before the loop, or use a join.
  • FOR ALL ENTRIES IN with an empty driver table ignores the condition and returns every row. Always check the table is not empty first.
  • READ TABLE on a large standard table searches row by row. Use a sorted or hashed table when you look up by key many times.
IF lt_orders IS NOT INITIAL.
  SELECT vbeln, posnr, matnr, kwmeng
    FROM vbap
    FOR ALL ENTRIES IN @lt_orders
    WHERE vbeln = @lt_orders-vbeln
    INTO TABLE @DATA(lt_items).
ENDIF.

Use standard functions before writing your own

SAP provides BAPIs, standard function modules for business actions such as creating a sales order. They apply all the validations of the standard transaction. Writing directly to standard tables bypasses those checks and can corrupt data, so do not do it.

Deployment is a transport

Changes are recorded in a transport request and moved from the development system to quality and then production. There is no editing in production. It is slower than a git push, and it is the reason SAP landscapes stay stable.

How to start learning

Pick one report your business actually needs, find the tables behind the standard transaction and build a simple list with ALV. Reading existing programs teaches more than any course. For what the language taught me in return, read what SAP ABAP taught a Laravel developer, and for connecting it to web applications, SAP and Laravel integration patterns.

Common questions

What is ABAP used for?

ABAP is SAP's programming language. It is used to build custom reports, interfaces, enhancements and applications that run inside SAP systems.

What is an internal table in ABAP?

An internal table is an in-memory table of rows with a defined structure, used to hold and process data during a program's run, much like an array of records in other languages.

Why is FOR ALL ENTRIES risky in ABAP?

If the driver internal table is empty, the WHERE condition that refers to it is ignored and the query returns all rows. Always check that the table is not empty before using it.