Explore ABAP syntax in a nutshell & executable examples
How to Use
·
Cheat Sheets
·
Examples
ABAP cheat sheets[^1] ...
F1
on a keyword in your code, or by searching directly using the online or the system-internal version.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 in Use | 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 |
A Glimpse on AMDP | Touches on ABAP Managed Database Procedures (AMDP): AMDP Procedures and AMDP Functions (including CDS Table Functions) | zcl_demo_abap_amdp |
Program Flow Logic | Deals with control structures (IF , CASE ), loops (DO , WHILE ) and exception handling |
zcl_demo_abap_prog_flow_logic |
The executable examples are designed to be imported into the SAP BTP ABAP environment, but they are basically suitable for both on-premise systems and the SAP BTP ABAP environment (hence there are no ABAP reports included). Therefore, check the information in the following collapsible sections for your system environment and perform the required steps.
F9
to display the output in the ADT console.Prerequisites
ZCL_DEMO_ABAP*
, for example, so that you do not run into errors when you try to import the code. If someone has already imported the content into the system, you can simply check out that imported version and proceed to the step 3) Run the code.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 the target package. It is recommended that you assign the package to a transport request that is 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 choose abapGit Repositories
.
In the abapGit Repositories view, click the +
icon in the upper right corner of the ADT tab to link a new abapGit repository.
The Link abapGit Repository popup appears. Enter the following URL:
https://github.com/SAP-samples/abap-cheat-sheets.git
Choose Next
.
On the Branch and Package Selection screen, enter the name of the created package (for example, ZABAP_CHEAT_SHEETS
) in the Package
field.
Choose Next
.
On the Select Transport Request screen, select the created transport request that is suitable for the 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 appears that an object is already locked in a transport request, choose Finish
, too.
In the abapGit Repositories view, filter for your package. The repository appears in the abapGit Repositories view with the status Linked.
Right-click on 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) from 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, choose Finish
as well. The status in the abapGit Repositories view changes to Pull running.... Note that the pull run may take several minutes.
Once the cloning is complete, the status changes to Pulled Successfully
. You may need to refresh the abapGit Repositories
view to see the progress of the import. To do this, choose the Refresh
icon in the upper right corner of the view.
Refresh your project tree. For example, in ADT, right-click the package and choose Refresh
or F5
. The package should contain all the 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 choose CTRL+Shift+F3
).
Prerequisites
ZCL_DEMO_ABAP*
, for example, to avoid errors when you try to import the code. If someone has already imported the content into the system, you can simply check out that imported version and proceed to the step 3) Run the code.zabapgit_standalone
, and copy and paste this code into the program.Import Code
Use the standalone version of the abapGit report to import the demo examples of the ABAP cheat sheets by performing the following steps:
TEST_ABAP_CHEAT_SHEETS
as a target package suitable for demo content (for example, by using LOCAL
as the software component).New Online
button. If the button is not available, for example, if another repository is already open, choose the Repository List
button.Git Repository URL
:
https://github.com/SAP-samples/abap-cheat-sheets.git
Package
: Your demo package, for example, TEST_ABAP_CHEAT_SHEETS
Create Online Repo
.Pull
button. The import of the artifacts is triggered. This may take several minutes.Inactive Objects
popup is displayed, select all artifacts and choose Continue
(✔️).Refresh
or F5
. The package should contain all artifacts from the GitHub repository.Activate all inactive ABAP development objects
button from the (or choose CTRL+Shift+F3
).zcl_demo_abap_string_proc
. The classes are located in the Source Code Library
→ Classes
folder.F9
to run the class. Alternatively, choose Run
→ Run As
→ 2 ABAP Application (Console)
from the menu.💡 Note
- Check the notes on the context and the ABAP syntax used that are included as comments in the class.
- Due to the amount of output in the console, the examples include numbers (e.g. 1) ..., 2) ..., 3) ...) that represent the header of eaxh example code section. Also, in most cases, the variable name is displayed in the console. Therefore, to find the relevant output in the console more easily and quickly, simply search the console for the number (e.g. search for
3)
for the particular output) or variable name (CTRL+F
in the console), or use breakpoints in the code to check variables in the debugger.- You may want to clear the console by right-clicking in the console and choosing
Clear
before running another demo class to avoid confusing the output of multiple classes.
ZCL_DEMO_ABAP*
. Someone has already imported the content into the system and you can simply check out that imported version.ORDER BY
clause, or messages regarding using SELECT *
, the code deliberately avoids pragmas and pseudo comments in order to keep the code simple and to focus on the available ABAP syntax. See also the Disclaimer.For the system-internal version of the ABAP Keyword Documentation in your
ABAPDOCU
(opens the documentation directly) and ABAPHELP
(opens an input field with which you can search the documentation content, for example, you can search for a keyword such as SELECT
). Or, of course, choose F1
on a keyword in your code. If you are in the SAP GUI (e.g. in SE80
), the system-internal version opens. If you are in ADT, the documentation opens in the ABAP Language Help view.F1
on a keyword in your code, the documentation opens there.Links to the online version of the ABAP Keyword Documentation for:
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., see the example page (also available in the system-internal SAP GUI version as a node in the topic tree), which summarizes the executable examples. Of course, you can also find the example topics in the context of the individual ABAP Keyword Documentation topic. The example topics are marked with a ⚙️ icon:
This blog features videos about the ABAP Keyword Documentation in the SAP Help Portal, SAP GUI, and 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.
Please do not create pull requests. If you like to address issues or suggestions, please create an issue. However, 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.
[^1]: "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).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。