100 KiB
Misc ABAP Classes
- Misc ABAP Classes
- Excursion: Available Classes in ABAP Cloud
- Creating UUIDs
- Displaying Output in the ADT Console
- RAP
- Transactional Consistency
- Numbers and Calculations
- String Processing
- Time and Date
- Runtime Type Services (RTTS)
- Assignments
- Information about Non-Initial Structure Components
- Comparing Content of Compatible Internal Tables
- Dynamic Programming
- Context Information
- XML/JSON
- ABAP Repository Information
- Call Stack
- Sending Emails
- Tenant Information
- Exception Classes
- Parallel Processing
- Application Log
- Running Code in the Background
- Locking
- Calling Services
- Generating ABAP Repository Objects
This ABAP cheat sheet contains a selection of available ABAP classes, serving as a quick introduction, along with code snippets to explore the functionality in action.
💡 Note
- The cheat sheet is not a comprehensive overview, and the code snippets do not claim to be comprehensive as far as options, methods, or parameters are concerned. It is intended to give you a rough overview, for you to get an idea. It is an invitation to a more in-depth exploration.
- For more information and where available, refer to the class documentation (for example, choose F2 when the cursor is on the class name in ADT), the ABAP Keyword Documentation, and the SAP Help Portal documentation.
- In the cheat sheet, the focus is on a selected set of classes that are available in ABAP for Cloud Development.
- Disclaimer
Excursion: Available Classes in ABAP Cloud
If available to you, you have accessed an SAP BTP ABAP Environment using the ABAP development tools for Eclipse (ADT). Access to SAP-provided repository objects is restricted to objects that have been released for ABAP for Cloud Development (released APIs). You can find the released repository objects in the Project Explorer view in ADT under Released Objects. The classes are located in the Source Code Library folder:
You can also programmatically get the released obects. You can use specific XCO classes or a CDS view, as shown in the example code snippet below.
SELECT ReleasedObjectType, ReleasedObjectName, ReleaseState
FROM i_apisforclouddevelopment
WHERE releasestate = 'RELEASED'
AND ReleasedObjectType = 'CLAS'
ORDER BY ReleasedObjectName
INTO TABLE @DATA(released_classes).
Creating UUIDs
| Class | Details/Code Snippet |
CL_SYSTEM_UUID |
Creating and and converting system UUIDs with various algorithms
|
Displaying Output in the ADT Console
| Class | Details/Code Snippet |
CL_DEMO_CLASSRUN |
As an alternative to using the IF_OO_ADT_CLASSRUN interface for displaying output in the console, you can also use the CL_DEMO_CLASSRUN class, which offers more methods.
For more information, refer to this blog.
The following example makes use of the CL_DEMO_CLASSRUN. A structure and an internal table are displayed in the console. A structure component is a reference variable, which is automatically dereferenced. Plus, the write_xml method is shown, which displays XML data.
|
RAP
| Class | Details/Code Snippet |
CL_ABAP_BEHV_AUX |
A utility class for retrieving information about RAP handler implementations, such as the current context of RAP handler/saver methods, the handler kind, and the current RAP transactional phase (e.g., RAP interaction phase.
|
CL_ABAP_BEHAVIOR_HANDLER |
Used for RAP handler classes that inherit from class CL_ABAP_BEHAVIOR_HANDLER.
|
CL_ABAP_BEHAVIOR_SAVER |
Used as base class from which a RAP saver class in an ABAP behavior pool (ABP) inherits. The RAP saver class must be defined in the CCIMP include of an ABP.
|
CL_ABAP_BEHAVIOR_SAVER_FAILED |
|
CL_ABAP_BEHAVIOR_EVENT_HANDLER |
It is used as base class from which a RAP event handler class in its CCIMP include inherits. Its purpose is to locally consume RAP business events.
More information: ABAP for RAP Business Events.
|
Transactional Consistency
| Class | Details/Code Snippet |
CL_ABAP_TX |
|
Numbers and Calculations
| Class | Details/Code Snippet |
CL_ABAP_MATH |
For operations with (decimal) floating point numbers and for providing constants for minimum and maximum values.
|
CL_ABAP_DECFLOAT |
For handling decimal floating point numbers.
|
CL_ABAP_BIGINT |
For calculations with integers of any size (e.g. to avoid the risk of an arithmetic overflow). Find more information in
this blog, and check out the different methods available.
|
CL_ABAP_RATIONAL |
For calculations with rational numbers without precision loss and rounding errors.
|
CL_ABAP_RANDOM* |
For generating arbitrary numbers for different numeric types:
CL_ABAP_RANDOM_INT (type i),
CL_ABAP_RANDOM_INT8 (int8),
CL_ABAP_RANDOM_FLOAT (f),
CL_ABAP_RANDOM_PACKED (p),
CL_ABAP_RANDOM_PACKED_DEC1 - CL_ABAP_RANDOM_PACKED_DEC14 (p with 1 to 14 decimal places),
CL_ABAP_RANDOM_DECFLOAT16 (decfloat16),
CL_ABAP_RANDOM_DECFLOAT34 (decfloat34)
|
String Processing
| Class | Details/Code Snippet |
CL_ABAP_GZIP* |
For (de)compressing character strings and byte strings using GZIP:
CL_ABAP_GZIP,
CL_ABAP_GZIP_BINARY_STREAM,
CL_ABAP_GZIP_TEXT_STREAM,
CL_ABAP_UNGZIP_BINARY_STREAM,
CL_ABAP_UNGZIP_TEXT_STREAM
|
CL_ABAP_CHAR_UTILITIES |
Provides utilities for string processing, such as attributes that represent new lines and horizontal tabs.
|
CL_ABAP_STRING_UTILITIES |
For processing text strings, such as handling trailing blanks in character strings (i.e. data objects of type string).
|
CL_ABAP_CONV_CODEPAGE |
For handling code pages, converting strings to the binary representation of different code pages and vice versa.
|
CL_ABAP_REGEX CL_ABAP_MATCHER |
|
XCO_CP |
Offers various options to process strings using the XCO Library; see a selection in the code snippet
|
Time and Date
💡 Note
In ABAP for Cloud Development, do not use the date and time-related system fields such assy-datumandsy-uzeit, and others. User-related time and date values (such assy-timloandsy-datlo) can be retrieved using the XCO library. For code snippets, see the Date, Time, and Time Stamp cheat sheet.
| Class | Details/Code Snippet |
CL_ABAP_UTCLONG |
For handling time stamps in time stamp fields (data objects with type utclong).
|
CL_ABAP_TSTMP |
For calculating and converting time stamps in packed numbers (types timestamp and timestampl)
|
XCO_CP_TIME |
Class of the XCO time library that provides abstractions for getting and working with date and time information. Find more details here.
|
Runtime Type Services (RTTS)
| Class | Details/Code Snippet |
CL_ABAP_TYPEDESCR |
RTTS represent a hierarchy of type description classes containing methods for:
Apart from CL_ABAP_TYPEDESCR
|
|--CL_ABAP_DATADESCR
| |
| |--CL_ABAP_ELEMDESCR
| | |
| | |--CL_ABAP_ENUMDESCR
| |
| |--CL_ABAP_REFDESCR
| |--CL_ABAP_COMPLEXDESCR
| |
| |--CL_ABAP_STRUCTDESCR
| |--CL_ABAP_TABLEDESCR
|
|--CL_ABAP_OBJECTDESCR
|
|--CL_ABAP_CLASSDESCR
|--CL_ABAP_INTFDESCR
|
Assignments
| Class | Details/Code Snippet |
CL_ABAP_CORRESPONDING |
For assignments of components between structures or between internal tables with dynamically specified mapping rules. For more information, you can refer to the ABAP Keyword Documentation.
The example shows simple assignments with structures.
|
Information about Non-Initial Structure Components
| Class | Details/Code Snippet |
CL_ABAP_STRUCT_UTILITIES |
Provides methods to get information about filled components in structures allowing an efficient processing of non-initial components of a structure.
|
Comparing Content of Compatible Internal Tables
| Class | Details/Code Snippet |
CL_ABAP_DIFF |
Using the methods diff and diff_with_line_ref of the CL_ABAP_DIFF class, you can compare the content of two compatible index tables. The returning parameter is an internal table showing how the content of one internal table can be modified to match another one. diff_with_line_ref also returns a reference to the original table lines. Various importing parameters are available to adjust the comparison. Find more information in the class documentation and in the ABAP Keyword Documentation.
|
Dynamic Programming
| Class | Details/Code Snippet |
CL_ABAP_DYN_PRG |
For validating input for dynamic specifications.
|
Context Information
| Class | Details/Code Snippet |
CL_ABAP_CONTEXT_INFO |
Provides context information relevant to the current ABAP session.
|
XML/JSON
| Class | Details |
CL_IXML_* CL_SXML_* |
|
XCO_CP_JSON |
Handling JSON data using the XCO library
|
ABAP Repository Information
| Class | Details/Code Snippet |
XCO_CP_ABAPXCO_CP_ABAP_REPOSITORY |
|
Call Stack
| Class | Details/Code Snippet |
XCO_CPXCO_CP_CALL_STACK |
Getting the current ABAP call stack programmatically. See more information here.
|
Sending Emails
| Class | Details/Code Snippet |
CL_BCS_MAIL_MESSAGE |
|
Tenant Information
| Class | Details/Code Snippet |
XCO_CPXCO_CP_TENANT |
For obtaining various information about the currently active tenant.
|
Exception Classes
| Class | Details/Code Snippet |
CX_* |
Exception classes are special classes, usually starting with the name CX_*, that serve as the basis for catchable exceptions. When an exception is raised, an object of such an exception class is created. There are several predefined exception classes. Find more information in the cheat sheet about program flow logic.
|
Parallel Processing
| Class | Details/Code Snippet |
CL_ABAP_PARALLEL |
For performing the parallel processing for instances of ABAP Objects. The following example class is intended to be a self-contained example that tries to visualize the functionality of the CL_ABAP_PARALLEL class. For more information, refer to the class documentation.
|
Application Log
| Class | Details/Code Snippet |
CL_BALI_LOG |
For creating and reading application logs. Refer to this documentation for more information and code snippets.
|
Running Code in the Background
| Class | Details/Code Snippet |
CL_BGMC_PROCESS_FACTORY |
|
Locking
| Class | Details/Code Snippet |
CL_ABAP_LOCK_OBJECT_FACTORY |
For activating lock objects. Note that you can also use the DEQUEUE_ALL method to remove all locks in the current SAP LUW.
The following example code snippet uses artifacts from the ABAP cheat sheet repository.
|
Calling Services
| Class | Details/Code Snippet |
CL_WEB_HTTP_CLIENT_MANAGERCL_HTTP_DESTINATION_PROVIDER |
|
Generating ABAP Repository Objects
| Class | Details/Code Snippet |
XCO_CP_GENERATION |
For creating, updating and deleting ABAP repository objects. More information: Generation APIs The rudimentary snippet is taken from the executable example of the ABAP for Cloud Development cheat sheet. |
