Meine Notizen zu SAP ABAP

AAdvanced
BBusiness
AApplication
PProgramming

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
1Paket
2Unterpaket
3Globale Klassen eines Unterpaketes
4Programme (Reports) eines Unterpaketes
5Program (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 TESTINGmark as an unit test class
DURATIONSHORT
MEDIUM
LONG
RISK LEVELHARMLESS (no changes to data or settings)
DANGEROUS (date may changed)
CRITICAL (data or settings may be changed)
CL_ABAP_UNIT_ASSERTEvaluating test results

Elementare Datentypen

Elementare ABAP-Typen

cTextfeldFixe länge
NNummern TextfeldFixe länge
DDatumsfeldFixe länge
TZeitfeldFixe länge
XHexadezimalFixe länge
PGepackte ZahlFixe länge
IIntegerFixe länge
FFloatFixe länge
STRINGTextVariable Länge
XSTRINGByteVariable 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

GitHub: SAP Styleguides

https://github.com/SAP/styleguides/blob/main/clean-abap/cheat-sheet/CleanABAPCheatSheetV1.4.1.pdf

Meine Notizen zu SAP Transaktionen

Transaktioncode => Shortcut to a program and a screen

Ausführen:

eingabe <Transaktioncode>

Ausführen in einem neuen Fenster:

/o<Transaktioncode>

TransaktionsBeschreibung
SE80Object Navigator (Entwicklungsumgebung)
Object Navigator
SE38ABAP Editor
ABAP Editor
SM30Tabellenpflege (Pflegedialog)
Tabellenpflege
ST22ABAP-Dumpanalyse (Fehlersuche / Laufzeitfehler)
ABAP-Dumpanalyse
SE11Data Dictionary (Datenbank)
Data Dictionary
SE16NData Browser (Tabelleninhalt bearbeiten)
Data Browser
STMSSAP Transport Management System (Übersicht)
STMS
SE10Transportauftrag
Transportorganizer
SM50Workprozessübersicht
Workprozessübersicht SAP
SM51Liste der SAP-Systeme
Liste der SAP-Systeme
SE91Nachrichtenpflege
Nachrichtenpflege
SENUMNummernkreispflege
Nummernkreispflege
SE93Transaktionspflege
Transaktionspflege
ST05Performance-Trace
Performance-Trace

Shortcuts

F1SAP Hilfe
F3Zurück
Shift + F3Beenden
F8Ausführen
F12Abbrechen