A | Advanced |
B | Business |
A | Application |
P | Programming |
ABAP Concepts:
- Transaction
- Programm
- Manage Business Process
- Screen
- Data Dictionary
- Database
- Subroutine
- Divide long programs to a subroutine
- GUI Status
- Custom Menus
ABAP Objects
Naming Conventions
- Customer objects prefixed with „Y“ or „Z“ (from A to X used by SAP)
- Object names denote functionality
- Variable names denote usage
- Never use literal values (SELECT * from VBAK WHERE AUART IN (‚ZSP0‘, ‚ZSP2‘).
- Interfacenames start with IF_* / ZIF_*
- Variablename: lv_<name> => local variable
Prefixes
lv_ | local variable |
ls_ | local structure |
ty_ | type (Datastructure) |
lt_ | local table |
A Framework Class
Global Class
Inheriting a global class
Remove final attribute from the class to inheriting
Change the visibility from the instance attribute to protected
To inheriting a class do:
CLASS <name> DEFINITION
INHERITING FROM <class_to_inheriting_from>.
Abstract Class
Define a base class as abstract
Sonstiges
lv_text = TEXT-t01 && | | && lv_text.
Space character in a text | && | | && |
TEXT-<xxx> | Textsymbol |
* | Comment out a line |
CLASS <name> DEFINITION ENDCLASS. | Interface |
CLASS <name> IMPLEMENTATION ENDCLASS. | Class object |
CLASS IMPLEMENTATION INHERITING FROM <class_name>. ENDCLASS. | Inheriting |
METHODES: show_details REDEFINITION. | Overwriting an inheriting methode |
super->show_details( ). | Call the methode in the superclass |
TRY. lcl_start=>run ( ) . CATCH cx_root INTO lcl_start=>mo_error. ENDTRY. | Unhandled exceptions cause short dumps |
1 | Paket |
2 | Unterpaket |
3 | Globale Klassen eines Unterpaketes |
4 | Programme (Reports) eines Unterpaketes |
5 | Program (Report) mit Klassen, Felder usw. |
Prüfen, aktivieren und ausführen
ABAP Unit / Test Classes
CLASS lcl_test DEFINITION
FOR TESTING
DURATION SHORT
RISK LEVEL harmless.
PRIVATE SECTION.
DATA: lo_test TYPE REF TO zcl_main "class under test
METHODES: setup, teardown "Fixture methodes
METHODES: test_method1 FOR TESTING "Test method
ENDCLASS.
FOR TESTING | mark as an unit test class |
DURATION | SHORT MEDIUM LONG |
RISK LEVEL | HARMLESS (no changes to data or settings) DANGEROUS (date may changed) CRITICAL (data or settings may be changed) |
CL_ABAP_UNIT_ASSERT | Evaluating test results |
Elementare Datentypen
c | Textfeld | Fixe länge |
N | Nummern Textfeld | Fixe länge |
D | Datumsfeld | Fixe länge |
T | Zeitfeld | Fixe länge |
X | Hexadezimal | Fixe länge |
P | Gepackte Zahl | Fixe länge |
I | Integer | Fixe länge |
F | Float | Fixe länge |
STRING | Text | Variable Länge |
XSTRING | Byte | Variable Länge |
Lokale Datenstruktur
TYPES: BEGIN OF ty_matdata,
matnr TYPE c LENGTH 15,
mattext TYPE c LENGTH 30,
matunit TYPE c LENGTH 3,
END OF ty_matdata.
Zuweisung / Nutzung der lokalen Struktur
data ls_matdata type ty_matdata.
ls_matdata-matnr = '1'.
Lokale Tabelle
data lt_material type TABLE OF ty_matdata.
Tabelle befüllen:
do 5 times.
* sy-index => runtime variable mit aktuellem index
ls_matdata-matnr = sy-index.
CONCATENATE 'Mein Material' ls_matdata-matnr into ls_matdata-mattext.
ls_matdata-matunit = 'ST'.
append ls_matdata to lt_material.
ENDDO.
Tabelle ausgeben:
loop at lt_material into ls_matdata.
* / => Zeilenumbruch
write / ls_matdata.
ENDLOOP.
Tabelle ausgeben mit FIELD-SYMBOLS: (Performence)
*&---------------------------------------------------------------------*
* FIELD-SYMBOLS
*&---------------------------------------------------------------------*
FIELD-SYMBOLS <fs_matdata> type any.
loop at lt_material ASSIGNING <fs_matdata>.
* / => Zeilenumbruch
write / <fs_matdata>.
ENDLOOP.
Wichtige Befehle
DO x TIME. <code> ENDDO. | |
CONCATENATE | |
APPEND | |
LOOP AT <table> INTO <record>. ENDLOOP. | |
WRITE | |
DATA <name> TYPE <Datentyp> | |
IF <Abfrage>. (=, >, <…) ELSEIF <Abfrage> ELSE. ENDIF. | |
CASE <Variable>. WHEN <Bedingung>. WHEN <Bedingung 2>. WHEN OTHERS. END CASE. |
Open SQL
SELECT * FROM <table> INTO TABLE <lt_name> | Einfache Select-Abfrage |
SELECT * FROM <table> INTO CORRESPONDING FIELDS OF TABLE <lt_name> | Select-Abfrage, welche nur die namensgleichen Felder berücksichtigt |
Nützliches
https://github.com/SAP/styleguides/blob/main/clean-abap/cheat-sheet/CleanABAPCheatSheetV1.4.1.pdf