1 Star 0 Fork 0

ward.peng/abap-cheat-sheets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

ABAP Keyword Documentation

ABAP Cheat Sheets

Explore ABAP syntax in a nutshell & executable examples

How to Use · Cheat Sheets · Examples




REUSE status

ABAP cheat sheets[^1] ...

  • 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 fully comprehensive as far as the described syntax and concepts are concerned. If you need more details, you can always consult the ABAP Keyword Documentation, for example, by choosing F1 on a keyword in your code, or by searching directly using the online or the system-internal version.
  • Unless otherwise stated in the cheat sheets and examples, the content of this repository are relevant for these ABAP language versions:
  • Check the Known Issues and Disclaimer.
  • The cheat sheets provide links to glossary entries and topics in the ABAP Keyword Documentation. Note that in most case, these links refer to the ABAP for Cloud Development version.

🏗️ How to Use

  1. ABAP syntax info: Get info in a nutshell on ABAP syntax and concepts related to various ABAP topics in the ABAP cheat sheets.
  2. 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.

📝 ABAP Cheat Sheets Overview

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

🎬 Getting Started with the Examples

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.

1) General info
  • Some DDIC artifacts, such as database tables, are part of the repository. They are used by the examples to ensure self-contained examples. All artifacts must be imported for all examples to work.
  • All examples are designed to display some output in the ADT console. Once successfully imported, you can run the examples in ADT by choosing F9 to display the output in the ADT console.
  • The examples include descriptions and comments in the code to provide explanations and set the context.
2a) SAP BTP ABAP environment

Prerequisites

  • You have access to an SAP BTP ABAP Environment instance (see here for additional information).
  • You have downloaded and installed the ABAP Development Tools (ADT). Make sure that you are using the latest version, as indicated on the installation page.
  • Before importing the code, you have performed a system-wide search for classes named 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.
  • You have created an ABAP cloud project in ADT that allows you to access your SAP BTP ABAP Environment instance (see here for more information). Your login 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:

  1. 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.

  2. Add the package to the Favorite Packages in the Project Explorer view in ADT.

  3. To add the abapGit Repositories view to the ABAP perspective, choose WindowShow ViewOther... from the menu bar and choose abapGit Repositories.

  4. In the abapGit Repositories view, click the + icon in the upper right corner of the ADT tab to link a new abapGit repository.
    ADT

  5. The Link abapGit Repository popup appears. Enter the following URL:

https://github.com/SAP-samples/abap-cheat-sheets.git
  1. Choose Next.

  2. On the Branch and Package Selection screen, enter the name of the created package (for example, ZABAP_CHEAT_SHEETS) in the Package field.

  3. Choose Next.

  4. 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.

  5. In the abapGit Repositories view, filter for your package. The repository appears in the abapGit Repositories view with the status Linked.

  6. Right-click on the new abapGit repository and choose Pull... to start the cloning of the repository contents.

  7. On the Branch and Package Selection screen, choose Next.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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).

2b) Application Server ABAP On-Premise

Prerequisites

  • It is assumed that you are running the latest ABAP release. The content has also been tested with release 7.56. Note that the RAP examples require at least ABAP version 7.56.
  • Before importing the code, you have performed a system-wide search for classes named 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.
  • You have downloaded and installed the ABAP Development Tools (ADT). Make sure that you are using the latest 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 login language is English.
  • You have downloaded and installed the standalone version of the abapGit report. Make sure you are using the latest 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.

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:

  1. In your ABAP project, create a package, such as TEST_ABAP_CHEAT_SHEETS as a target package suitable for demo content (for example, by using LOCAL as the software component).
  2. Add the package to the Favorite Packages in the Project Explorer view in ADT.
  3. Run the standalone version of the abapGit report.
  4. Choose the New Online button. If the button is not available, for example, if another repository is already open, choose the Repository List button.
  5. 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

  6. Leave the other fields unchanged and choose Create Online Repo.
  7. The Repository screen displays the available ABAP artifacts to be imported into your ABAP system.
  8. Choose the Pull button. The import of the artifacts is triggered. This may take several minutes.
  9. If the Inactive Objects popup is displayed, select all artifacts and choose Continue (✔️).
  10. When the cloning is complete, refresh your project tree. For example, in ADT, right-click on the package and choose Refresh or F5. The package should contain all artifacts from the GitHub repository.
  11. 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 choose CTRL+Shift+F3).
3) Run the code
  • Open the package you created containing the imported ABAP artifacts in the ABAP Development Tools (ADT).
  • Open one of the ABAP cheat sheet example classes listed in the ABAP Cheat Sheets Overview section, for example, zcl_demo_abap_string_proc. The classes are located in the Source Code LibraryClasses folder.
  • Choose F9 to run the class. Alternatively, choose RunRun As2 ABAP Application (Console) from the menu.
  • Check the console output.

💡 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.

⚡ Known Issues

  • Only one user on the system can import this repository because all object names must be globally unique. If you get an error that the objects already exist when you try to import, search the system for classes named ZCL_DEMO_ABAP*. Someone has already imported the content into the system and you can simply check out that imported version.
  • Since the repository contains self-contained examples, i.e. they work with demo database tables included in the repository (note that these tables are populated during method executions), all demo artifacts must be imported for all examples to work.
  • When importing into an on-premise system, note the following: The demos cover ABAP syntax regardless of the ABAP release to avoid scattering information and to get the information in one go. Therefore, there may be syntax that is not yet available in the ABAP version of your on-premise system. In this case, you may want to comment out the affected code sections and/or ignore the affected artifacts if an activation fails. Note that the RAP examples in particular require at least ABAP version 7.56.
  • Regarding possible code check warnings, e.g. for the many strings in the code, not using an 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.

🛈 Further Information

  • For the system-internal version of the ABAP Keyword Documentation in your

    • ... on-premise system: Access the documentation in the SAP GUI via the transactions 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.
    • ... SAP BTP ABAP environment: In ADT, the documentation is in the ABAP Language Help view, where you can also search. If you choose F1 on a keyword in your code, the documentation opens there.
  • Links to the online version of the ABAP Keyword Documentation for:

    • Standard ABAP: Unrestricted ABAP language scope, e.g. for developments in an on-premise ABAP system → Online version of the documentation (latest version). To access the online documentation for a specific ABAP version, e.g. 7.54, you can select the version from the drop-down list here (latest is preselected). The ABAP link under Development will take you to the documentation of choice.
    • 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., 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.

⚠️ Disclaimer

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.

📟 How to Obtain Support

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.

📜 License

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).

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

abap-cheat-sheets 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wardpeng/abap-cheat-sheets.git
git@gitee.com:wardpeng/abap-cheat-sheets.git
wardpeng
abap-cheat-sheets
abap-cheat-sheets
main

搜索帮助