Explore ABAP syntax in a nutshell & executable examples
How to Use
Β·
Cheat Sheets
Β·
Examples
ABAP cheat sheets1 ...
- provide a collection of information on selected ABAP topics in a nutshell for your reference.
- focus on ABAP syntax.
- include code snippets.
- are supported by easy-to-consume demonstration examples that you can import into your SAP BTP ABAP environment or on-premise ABAP system using abapGit to run and check out ABAP syntax in action in simple contexts.
- are enriched by links to glossary entries and chapters of the ABAP Keyword Documentation (the F1 help) for you to deep dive into the respective ABAP topics and get more comprehensive information.
π‘ Note
- Since the ABAP cheat sheets provide information in a nutshell, they do not claim to be exhaustive as far as the described syntax and concepts are concerned. If you want to go more into the details, just consult the ABAP Keyword Documentation, for example, by choosing
F1
for a keyword in your code or directly researching via the online version or the system-internal version. - If not stated otherwise in the cheat sheets and examples, the content of this repository is relevant for these ABAP language versions:
- ABAP for Cloud Development: Restricted ABAP language scope for developments in the SAP BTP ABAP environment β Online version of the documentation
- Standard ABAP: Unrestricted ABAP language scope, for example, for developments in an on-premise ABAP system β Online version of the documentation (latest version)
- Check the Known Issues and Disclaimer.
- In the cheat sheets, links are available to glossary entries and topics of the ABAP Keyword Documentation. Note that these links refer to the ABAP for Cloud Development version in most cases.
- ABAP syntax info: Get info in a nutshell on ABAP syntax and concepts related to various ABAP topics in the ABAP cheat sheets.
- Demo examples: Import the ABAP development objects of this repository into your system using abapGit as described here and run the demo classes by choosing
F9
in the ABAP Development Tools (ADT) for checking out the ABAP syntax in action.
Cheat Sheet | Topics Covered | Demo Example |
---|---|---|
Working with Internal Tables | Creating, filling, reading from, sorting, modifying internal tables | zcl_demo_abap_internal_tables |
Working with Structures | Creating structures and structured types, variants of structures, accessing components of structures, filling structures, clearing structures, structures in use in the context of tables | zcl_demo_abap_structures |
ABAP SQL: Working with Persisted Data in Database Tables | Reading from database tables using SELECT , changing data in database tables using INSERT , UPDATE , MODIFY and DELETE |
zcl_demo_abap_sql |
ABAP Object Orientation | Working with objects and components, concepts like inheritance, interfaces, and more | zcl_demo_abap_objects |
Working with Constructor Expressions | Operators VALUE , CORRESPONDING , NEW , CONV , EXACT , REF , CAST , COND , SWITCH , FILTER , REDUCE , iteration expressions with FOR , LET expressions |
zcl_demo_abap_constructor_expr |
Dynamic Programming | Touches on field symbols and data references as supporting elements for dynamic programming, dynamic ABAP syntax components, runtime type services (RTTS), i. e. runtime type identification (RTTI) and runtime type creation (RTTC) | zcl_demo_abap_dynamic_prog |
String Processing | Creating strings and assigning values, chaining strings, string templates, concatenating, splitting, modifying strings, searching and replacing, regular expressions | zcl_demo_abap_string_proc |
ABAP for RAP: Entity Manipulation Language (ABAP EML) | Setting EML in the context of RAP, standard (create, read, update, delete) and non-standard operations (actions) |
|
Excursion Down to Bits and Bytes | Touches on the technical background of data types and data objects | - |
ABAP SQL: Working with Hierarchies | Summarizes the functions ABAP SQL offers together with ABAP CDS for working with hierarchical data that is stored in database tables | - |
ABAP SQL: Grouping Internal Tables | Touches on the GROUP BY clause in ABAP SQL |
zcl_demo_abap_sql_group_by |
The executable examples are especially targeted at being imported into the SAP BTP ABAP environment, however, they are basically fit for both on-premise systems and the SAP BTP ABAP environment (that's why there are no ABAP programs included). Hence, check the info in the following collapsible sections for your system environment and carry out the prerequisite steps.
1) General info
- A few DDIC artifacts, for example, database tables, are part of the repository. They are used by the examples to ensure self-contained examples. For all examples to work, all artifacts must be imported.
- All examples are designed to display some output in the ADT console. Once successfully imported, you can execute the examples in ADT by choosing
F9
to display the output in the ADT console. - The examples include descriptions and comments in the code for providing explanations and setting the context.
2a) SAP BTP ABAP environment
Prerequisites
- Before importing the code, you have made a system-wide search for, for example, classes named
ZCL_DEMO_ABAP*
so as not to run into issues when you try to import the code. If someone has already imported the content in the system, you can simply check out that imported version and proceed with the step 3) Run the code. - You have access to an SAP BTP ABAP Environment instance (see here for additional information).
- You have downloaded and installed ABAP Development Tools (ADT). Make sure that you use the most recent version as indicated on the installation page.
- You have created an ABAP cloud project in ADT that allows you to access your SAP BTP ABAP Environment instance (see here for additional information). Your logon language is English.
- You have installed the abapGit plug-in for ADT from the update site.
Import Code
Use the abapGit plug-in to install the ABAP Cheat Sheets by carrying out the following steps:
-
In your ABAP cloud project, create a package, for example,
ZABAP_CHEAT_SHEETS
as target package. It is recommended that you assign the package to a transport request suitable for demo content. -
Add the package to the Favorite Packages in the Project Explorer view in ADT.
-
To add the abapGit Repositories view to the ABAP perspective, choose
Window
βShow View
βOther...
from the menu bar and chooseabapGit Repositories
. -
On the abapGit Repositories view, click the
+
icon in the top right corner of the ADT tab to link a new abapGit repository. -
The Link abapGit Repository pop-up is displayed. Insert the following URL:
https://github.com/SAP-samples/abap-cheat-sheets.git
-
Choose
Next
. -
On the Branch and Package Selection screen, insert the name of the created package (e. g.
ZABAP_CHEAT_SHEETS
) in thePackage
field. -
Choose
Next
. -
On the Select Transport Request screen, select the created transport request suitable for demo content and choose
Finish
to link the Git repository to your ABAP cloud project. If the created package is already assigned to a transport request for the demo content and a message that an object is already locked in a transport request is displayed, chooseFinish
, too. -
In the abapGit Repositories view, filter for your package. The repository appears in the abapGit Repositories view with status Linked.
-
Right-click the new abapGit repository and choose
Pull...
to start the cloning of the repository contents. -
On the Branch and Package Selection screen, choose
Next
. -
If the Locally Modified Object screen is displayed, select the objects (for example, the package to automatically select all artifacts) in the list and choose
Next
. -
On the next screen, select a transport request and choose
Finish
. Same as above, if an object already locked message is displayed, chooseFinish
, too. The status in the abapGit Repositories view changes to Pull running.... Note that the pull run may take a few minutes. -
Once the cloning has finished, the status is set to
Pulled Successfully
. You might need to refresh theabapGit Repositories
view to see the progress of the import. To do so, choose the icon for refreshing (Refresh
) in the top right corner of the view. -
Refresh your project tree. E. g. in ADT, right-click the package and choose
Refresh
orF5
. The package should contain all artifacts from the GitHub repository. -
Make sure that all artifacts are active. To activate all inactive development objects, choose the
Activate all inactive ABAP development objects
button from the menu (or chooseCTRL+Shift+F3
).
2b) Application Server ABAP On-Premise
Prerequisites
- The assumption is that you are on the latest ABAP release. The content was also tested with release 7.56.
- Before importing the code, you have made a system-wide search for, for example, classes named
ZCL_DEMO_ABAP*
so as not to run into issues when you try to import the code. If someone has already imported the content in the system, you can simply check out that imported version and proceed with the step 3) Run the code. - You have downloaded and installed ABAP Development Tools (ADT). Make sure that you use the most recent version as indicated on the installation page.
- You have created an ABAP Project in ADT that allows you to access your Application Server as mentioned above. Your logon language is English.
- You have downloaded and installed the standalone version of the abapGit report. Make sure that you use the most recent version as indicated on the installation page. You can create a report, for example,
zabapgit_standalone
and copy and paste this code into the program. - You have installed the certificate files for github.com, see abapGit Documentation.
Import Code
Use the standalone version of the abapGit report to import the demo examples of the ABAP Cheat Sheets by carrying out the following steps:
- In your ABAP project, create a package, for example,
TEST_ABAP_CHEAT_SHEETS
as target package suitable for demo content (e. g. by usingLOCAL
as software component). - Add the package to the Favorite Packages in the Project Explorer view in ADT.
- Run the standalone version of the abapGit report.
- Choose the
New Online
button. If the button is not available, for example, if another repository is already opened, choose theRepository List
button. - On the New Online Repository screen, make the following entries:
-
Git Repository URL
:https://github.com/SAP-samples/abap-cheat-sheets.git
-
Package
: Your demo package, for example,TEST_ABAP_CHEAT_SHEETS
-
- Leave the other fields unchanged and choose
Create Online Repo
. - On the Repository screen, you will see the available ABAP artifacts to be imported into your ABAP system.
- Choose the
Pull
button. The import of the artifacts is triggered. It might take some minutes. - If the
Inactive Objects
pop-up is displayed, select all artifacts and chooseContinue
(βοΈ). - Once the cloning has finished, refresh your project tree. E. g. in ADT, right-click the package and choose
Refresh
orF5
. The package should contain all artifacts from the GitHub repository. - Make sure that all artifacts are active. To activate all inactive development objects, choose the
Activate all inactive ABAP development objects
button from the (or chooseCTRL+Shift+F3
).
3) Run the code
- Open your created package containing the imported ABAP artifacts in the ABAP Development Tools (ADT).
- Open an ABAP cheat sheet example class as listed in the ABAP Cheat Sheets Overview section, for example,
zcl_demo_abap_string_proc
. The classes are contained in folderSource Code Library
βClasses
. - Choose
F9
to run the class. Alternatively, chooseRun
βRun As
β2 ABAP Application (Console)
from the menu. - Check the console output.
π‘ Note
- Check notes on the context and the ABAP syntax used included in the class as comments.
- Due to the amount of output in the console, the examples include numbers (e. g. 1) ..., 2) ..., 3) ...) representing the header of the individual example code sections. Plus, the variable name is displayed in the console in most cases. Hence, to easier and faster find the relevant output in the console, just search in the console for the number (e. g. search for
3)
for the particular output) or variable name (STRG+F
in the console) or use break points in the code to check variables in the debugger.- You might want to clear the console by making a right-click within the console and choosing
Clear
before running another demo class so as not to confuse the output of multiple classes.
- Only one user on the system may import this repository as all object names must be globally unique. If you receive an error that the objects already exist when trying to import, search the system for classes named
ZCL_DEMO_ABAP*
. Someone has already imported the content in the system and you can simply check out that imported version. - Since the repository contains self-contained examples, i. e. they work, for example, with demo database tables included in the repository (note that these tables are filled in the course of method executions), all demo artifacts must be imported so that all examples work.
- For the import into an on-premise system, note the following: The demos cover ABAP syntax irrespective of the ABAP release so as not to scatter information and to have the info in one go. Hence, there may be syntax that is not yet available with the ABAP version of your on-premise system. In that case, you might want to comment out affected code sections if an activation fails.
- Regarding potential code check warnings, for example, for the many strings in the code, not using an
ORDER BY
clause or messages regarding usingSELECT *
, the code purposely renounces pragmas and pseudo comments to keep the code fairly simple and to focus on the available ABAP syntax. See also the Disclaimer.
-
Regarding the system-internal version of the ABAP Keyword Documentation in your
- ... on-premise system: Access the documentation in SAP GUI via the transactions
ABAPDOCU
(opens the documentation directly) andABAPHELP
(opens an input field with which you can search the documentation content, for example, you can search for a keyword likeSELECT
). Or, certainly, in your code, chooseF1
for a keyword. If you are in SAP GUI (e. g. inSE80
), the system-internal version is opened. If you are in ADT, the documentation is opened in the ABAP Language Help view. - ... SAP BTP ABAP environment: In ADT, you find the documentation in the ABAP Language Help view where you can also search. When choosing
F1
for a keyword in your code, the documentation is opened there accordingly.
- ... on-premise system: Access the documentation in SAP GUI via the transactions
-
Links to the online version of the ABAP Keyword Documentation for:
- Standard ABAP: Unrestricted ABAP language scope, for example, for developments in an on-premise ABAP system β Online version of the documentation (latest version)
- ABAP for Cloud Development: Restricted ABAP language scope for developments in the SAP BTP ABAP environment β Online version of the documentation
-
Regarding demonstration examples of the ABAP Keyword Documentation in your on-premise system: Have you ever checked out the package
SABAPDEMOS
? This package contains all the examples used in the ABAP Keyword Documentation. To get the context, program names etc., check out the example page (which is also available in the system-internal SAP GUI version as node in the topic tree) summarizing executable examples. Certainly, you also find the example topics in the context of the individual ABAP Keyword Documentation topic. The example topics have a βοΈ sign: -
See this blog for videos about the ABAP Keyword Documentation on the Help Portal, in SAP GUI and in ADT.
The code examples presented in this repository are only syntax examples and are not intended for direct use in a production system environment. The code examples are primarily intended to provide a better explanation and visualization of the syntax and semantics of ABAP statements and not to solve concrete programming tasks. For production application programs, a dedicated solution should therefore always be worked out for each individual case. SAP does not guarantee either the correctness or the completeness of the code. In addition, SAP takes no legal responsibility or liability for possible errors or their consequences, which occur through the use of the example programs.
This project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases.
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.
Footnotes
-
"A written [...] aid (such as a sheet of notes) that can be referred to for help in understanding or remembering something complex" (Definition for "cheat sheet" in Merriam-Webster Dictionary). β©