\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{louis\_lee} \pdfinfo{ /Title (abap-programing.pdf) /Creator (Cheatography) /Author (louis\_lee) /Subject (ABAP Programing Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{111582} \definecolor{LightBackground}{HTML}{F7F7FB} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{ABAP Programing Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{louis\_lee} via \textcolor{DarkBackground}{\uline{cheatography.com/210062/cs/45284/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}louis\_lee \\ \uline{cheatography.com/louis-lee} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 19th December, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Define technical properties of all data objects that have these data types, such as the maximum length of a text field. \newline % Row Count 3 (+ 3) \{\{fa-star\}\}Are descriptions only, with no data memory attached except for administrative information. \newline % Row Count 6 (+ 3) \{\{fa-star\}\}Can occur in ABAP programs as bound data types, that is, the type is a property of a data object, or as a standalone data type, that is, the data type is defined independently. \newline % Row Count 10 (+ 4) \{\{fa-star\}\}Can be defined locally in an ABAP program or globally in classes, interfaces and in the ABAP Dictionary (DDIC).% Row Count 13 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}Data types declared in interfaces and in the public visibility section of global classes are also globally visibile. Global classes and interfaces as such are global types to refer to. In classic ABAP, you may stumble on the option to create global data types in type pools, which is not possible in ABAP for Cloud Development. However, the predefined type pool abap can be used in ABAP for Cloud Development.\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Reference Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Describe data objects that contain references to other objects (data objects and instances of classes), which are known as reference variables. \newline % Row Count 3 (+ 3) There are two kinds of references: {\emph{Data references}} (references to data objects) and {\emph{object references}} (references to objects as instances of classes). \newline % Row Count 7 (+ 4) A reference type must be defined either in the ABAP program or in the ABAP Dictionary. There are no built-in reference types in ABAP. \newline % Row Count 10 (+ 3) The typical syntax element is ... REF TO ....% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Type Conversions, Compatibility and Assignments}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A value assignment means that the value of a data object is transferred to a target data object. If the data types of the source and target are compatible, the content is copied unchanged. If they are incompatible and a suitable conversion rule exists, the content is converted. The following cases must be distinguished with regard to the data type: \newline % Row Count 8 (+ 8) \{\{fa-star\}\}The source and target data types are compatible, i.e. all technical type properties match. The content is transferred from the source to the target without being converted. \newline % Row Count 12 (+ 4) \{\{fa-star\}\}The source and target data types are incompatible, but can be converted. The content of the source is converted according to the conversion rules and then transferred to the target. Two data types are convertible if a conversion rule exists for them. An exception is raised if the content of the source cannot be handled according to the conversion rules. \newline % Row Count 20 (+ 8) \{\{fa-star\}\}If the data objects are neither compatible nor convertible, no assignment can take place. If the syntax check detects this state, a syntax error is raised, otherwise an uncatchable exception is raised when the program is executed. \newline % Row Count 25 (+ 5) \{\{fa-book\}\}Notes: \newline % Row Count 26 (+ 1) \textasciitilde{}The operands of many ABAP statements are assigned internally according to the assignment rules.\textasciitilde{}\{\{nl\}\} \newline % Row Count 29 (+ 3) \textasciitilde{}Typically, assignements are made using the assignment operator =. If necessary and applicable, the type is converted implicitly. However, you can also use the conversion operator CONV to convert types explicitly.\textasciitilde{}\{\{nl\}\} \newline % Row Count 34 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Type Conversions, Compatibility and Assignments (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}For lossless assignments, the lossless operator EXACT can be used to perform checks before the conversion is performed to ensure that only valid values are assigned and that no values are lost in assignments.\textasciitilde{}\{\{nl\}\} \newline % Row Count 5 (+ 5) \textasciitilde{}In general, no checks are performed on assignments between compatible data objects. If a data object already contains an invalid value, for example, an invalid date or time in a date or time field, it is passed a valid value when the assignment is made to a compatible data object.\textasciitilde{}\{\{nl\}\} \newline % Row Count 11 (+ 6) \textasciitilde{}The applies\_to\_data method of the RTTI class cl\_abap\_datadescr can be used to check type compatibility.\textasciitilde{}% Row Count 14 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Non-Admissible Values of Literals}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Note recent syntax warnings when using literals that represent invalid values for target types. The following example demonstrates the assignment of literals using admissible and non-admissible values. You can copy and paste the code into a demo class in your SAP BTP ABAP Environment to explore the syntax warnings.% Row Count 7 (+ 7) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{DATA char3 TYPE c LENGTH 3. \newline \newline "Value is admissable and convertible \newline char3 = 'abc'. \newline \newline "Non-admissable value assigned to the target (type c length 6) \newline char3 = 'defghi'. \newline \newline DATA date TYPE d. \newline \newline "Value is admissable and convertible \newline date = '20250101'. \newline \newline "Non-admissable value assigned to the target \newline "Type i \newline date = 20250101. \newline "More characters than type d \newline date = '20250101234'. \newline "Fewer characters than type d \newline date = '202511'.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Structured Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}The type name is preceded by BEGIN OF (which marks the beginning of the structured type definition) and END OF (the end of the definition). \newline % Row Count 4 (+ 4) \{\{fa-star\}\}The components - at least one must be defined - are listed in between. \newline % Row Count 6 (+ 2) \{\{fa-star\}\}Such structured type definitions are usually grouped together in a chained statement, i.e. TYPES is followed by a colon, and the components are separated by commas. \newline % Row Count 10 (+ 4) \{\{fa-star\}\}The simplest structures and structured types have elementary components. \newline % Row Count 12 (+ 2) \{\{fa-star\}\}As mentioned above, the components can be of any type, i.e. they can be of structured types themselves, internal table types, or reference types. \newline % Row Count 16 (+ 4) \{\{fa-star\}\}You can use the TYPE and LIKE additions for the types of the components. You can use the LINE OF addition to refer to a table type or an internal table.% Row Count 20 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}Outside of classes, you can also refer to DDIC types using LIKE (... comp11 LIKE ddic\_type, ...). If you actually want to refer to an existing data object, but due to typing errors you inadvertently specify a name that exists as DDIC type, errors may be unavoidable.\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Demo Example Data Type And Data Object}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{popup="https://github.com/SAP-samples/abap-cheat-sheets/blob/main/src/zcl\_demo\_abap\_dtype\_dobj.clas.abap"\}\}Demo\{\{/popup\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Anonymous Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Using the instance operator NEW and CREATE DATA statements, you can create anonymous data objects, such as anonymous structures. The NEW addition of the INTO clause of an ABAP SQL SELECT statement also creates an anonymous data object. As outlined below, you can access the components or the entire data objects by dereferencing.% Row Count 7 (+ 7) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Populating Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}You can copy the content of a structure to another using the assignment {\bf{operator =}}. In general, note that special conversion and comparison rules apply to value assignments involving structures. \newline % Row Count 5 (+ 5) \{\{fa-star\}\}Using the {\bf{VALUE Operator}}:The VALUE operator can be used to construct the content of complex data objects such as structures or internal tables. \newline % Row Count 9 (+ 4) \{\{fa-star\}\}Using the {\bf{NEW Operator}}:Using the instance operator NEW, you can create anonymous data objects, such as anonymous structures. You can access the components or the entire data objects by dereferencing. \newline % Row Count 14 (+ 5) \{\{fa-star\}\}You can use statements with {\bf{MOVE-CORRESPONDING and the CORRESPONDING operator}} to assign values to structure components, especially when assigning values from a source structure to a target structure which have incompatible types and/or differently named components.% Row Count 20 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}The CL\_ABAP\_CORRESPONDING system class is available for making assignments. \textasciitilde{} \newline \textasciitilde{}The INTO clause of ABAP SQL statements has the CORRESPONDING addition. There, the following basic rule applies, which affects the value assignment: Without the CORRESPONDING ... addition, column names do not matter, only the position. With the CORRESPONDING ... addition, the position of the columns does not matter, only the name. \textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Including Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}INCLUDE TYPE and INCLUDE STRUCTURE statements are used in the context of local structures. \newline % Row Count 3 (+ 3) \{\{fa-star\}\}Structured data objects and types created with ... BEGIN OF... END OF ... can use this syntax to include components of another structure, whether it is a locally defined or global structure, without creating substructures. \newline % Row Count 8 (+ 5) \{\{fa-star\}\}INCLUDE TYPE can be used to include a structured type. \newline % Row Count 10 (+ 2) \{\{fa-star\}\}You can use INCLUDE STRUCTURE to include a structure. \newline % Row Count 12 (+ 2) \textasciitilde{}They are not additions of ... BEGIN OF ... END OF ... but individual ABAP statements.\textasciitilde{} \newline % Row Count 14 (+ 2) \textasciitilde{}If you use a chained statement with a colon to declare the structure, the inclusion of other structures with these statements interrupts the chained statement, that is, the components of the included structures are included as direct components of the superstructure.\textasciitilde{} \newline % Row Count 20 (+ 6) \textasciitilde{}By using the optional AS addition and specifying a name, the included components can be addressed by this common name as if they were actually components of a substructure.\textasciitilde{} \newline % Row Count 24 (+ 4) \textasciitilde{}The optional RENAMING WITH SUFFIX addition, followed by a name, gives the included components a suffix name to avoid naming conflicts with other components.\textasciitilde{}% Row Count 28 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Demo ABAP Structure}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{popup="https://github.com/SAP-samples/abap-cheat-sheets/blob/main/src/zcl\_demo\_abap\_structures.clas.abap"\}\}Executable Example\{\{/popup\}\}% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Generic Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Generic types are available with which formal parameters of methods or field symbols can be specified. \newline % Row Count 3 (+ 3) \{\{fa-star\}\}At runtime, the actual data type is copied from the assigned actual parameter or memory area, i.e. they receive the complete data type only when an actual parameter is passed or a memory area is assigned.% Row Count 8 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}The TYPE REF TO addition types as a reference variable. A generic type cannot be specified after REF TO. A typing with TYPE REF TO data and TYPE REF TO object is considered as completely typing.\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Elementary data types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Elementary (or scalar) data types are based directly on a set of built-in ABAP types. \newline % Row Count 2 (+ 2) {\emph{Numeric types}}: Integers (b, s, i, int8), decimal floating point numbers (decfloat16, decfloat34), binary floating point numbers (f), and packed numbers (p) \newline % Row Count 6 (+ 4) {\emph{Character-like types}}: text fields (c) and numeric text fields (n) \newline % Row Count 8 (+ 2) {\emph{Byte-like type}}: byte fields (x) \newline % Row Count 9 (+ 1) {\emph{Character-like date and time types}}: date fields (d) and time fields (t) \newline % Row Count 11 (+ 2) {\emph{Time stamp}} type for time stamp fields (utclong). \newline % Row Count 13 (+ 2) {\emph{Character-like type for text strings}} (string) \newline % Row Count 14 (+ 1) {\emph{Byte-like type for byte strings}} (xstring)% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}The data types c, n, x, and p are incomplete, i.e., generic data types, with respect to their length. The type definition syntax has a special addition for this (LENGTH). In addition, p is also generic with respect to the number of decimal places (DECIMALS addition). See more about generic types in the following sections.\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Types/Data Objects at Runtime}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Using Runtime Type Services (RTTS) you can ... \newline % Row Count 1 (+ 1) \{\{fa-star\}\}get type information on data objects, data types or instances at runtime (Runtime Type Identification (RTTI)). \newline % Row Count 4 (+ 3) \{\{fa-star\}\}define and create new data types as type description objects at runtime (Runtime Type Creation (RTTC)).% Row Count 7 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ABAP Enumerated Types and Objects}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}ABAP supports the concept of enumerations. \newline % Row Count 2 (+ 2) \{\{fa-star\}\}Enumerations are a mixture of types and constants. \newline % Row Count 4 (+ 2) \{\{fa-star\}\}An enumerated type specifies a value set in addition to the actual type properties. \newline % Row Count 6 (+ 2) \{\{fa-star\}\}Enumerated objects - data objects with an enumerated type - are mainly used to check allowed values. This usually restricts the actual parameters passed to methods to the enumerated values defined in the class. Enumerated variables are variable enumerated objects. They can only contain the associated enumerated values. \newline % Row Count 13 (+ 7) \{\{fa-star\}\}CDS enumerated types are also available.% Row Count 15 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{To create a structure (i.e. a structured data object) in an ABAP program, you can use the DATA keyword. \newline % Row Count 3 (+ 3) It works in the same way as the TYPES statement above. \newline % Row Count 5 (+ 2) Unlike the TYPES statement, you can use the VALUE addition to set default values.% Row Count 7 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}The keywords CLASS-DATA and CONSTANTS can also be used to create structures. In principle, they represent special cases of the general statement shown above. \textasciitilde{} \newline \textasciitilde{}Structures can also be created inline using DATA(...) or FINAL(...).\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Structures ... \newline % Row Count 1 (+ 1) \{\{fa-star\}\}are data objects with structured data types (which is a complex data type because it is composed of other data types). \newline % Row Count 4 (+ 3) \{\{fa-star\}\}consist of a sequence of components of any data type, that is, the components of a structure can be, for example, elementary data objects, structures themselves, internal tables or references. \newline % Row Count 9 (+ 5) \{\{fa-star\}\}are used to combine different data objects that belong together. A typical example is an address. It has several components, such as name, street, city, and so on, that belong together. \newline % Row Count 13 (+ 4) play an important role in the context of internal tables and database tables. Structured types serve as line types for these tables. Most internal tables across ABAP programs may have structured line types. For database tables, there is no alternative to structured line types. \newline % Row Count 19 (+ 6) \{\{fa-star\}\}can be created locally in an ABAP program and globally.% Row Count 21 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Variants of Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Flat structures contain only elementary types that have a fixed length, that is, there are no internal tables, reference types or strings as components. Nesting does not matter in this context. Even a nested structure is considered flat unless a substructure contains a deep component. \newline % Row Count 6 (+ 6) DATA: BEGIN OF struc, \newline % Row Count 7 (+ 1) comp1 TYPE i, \newline % Row Count 8 (+ 1) comp2 TYPE c LENGTH 15, \newline % Row Count 9 (+ 1) comp3 TYPE p LENGTH 8 DECIMALS 2, \newline % Row Count 10 (+ 1) ..., \newline % Row Count 11 (+ 1) END OF struc. \newline % Row Count 12 (+ 1) \{\{fa-star\}\}Nested structures: At least one component of a structure is a substructure, that is, it refers to another structure. The following example has multiple substructures. \newline % Row Count 16 (+ 4) DATA: BEGIN OF address\_n, \newline % Row Count 17 (+ 1) BEGIN OF name, \newline % Row Count 18 (+ 1) title   TYPE string VALUE `Mr.`, \newline % Row Count 19 (+ 1) prename TYPE string VALUE `Duncan`, \newline % Row Count 20 (+ 1) surname TYPE string VALUE `Pea`, \newline % Row Count 21 (+ 1) END OF name, \newline % Row Count 22 (+ 1) BEGIN OF street, \newline % Row Count 23 (+ 1) name TYPE string VALUE `Vegetable Lane`, \newline % Row Count 25 (+ 2) num TYPE string VALUE `11`, \newline % Row Count 26 (+ 1) END OF street, \newline % Row Count 27 (+ 1) BEGIN OF city, \newline % Row Count 28 (+ 1) zipcode TYPE string VALUE `349875`, \newline % Row Count 29 (+ 1) name    TYPE string VALUE `Botanica`, \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Variants of Structures (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ END OF city, \newline % Row Count 1 (+ 1) END OF address\_n. \newline % Row Count 2 (+ 1) \{\{fa-star\}\}Deep structures: Contains at least one internal table, reference type, or string as a component. \newline % Row Count 5 (+ 3) DATA: BEGIN OF address\_d, \newline % Row Count 6 (+ 1) name    TYPE string VALUE `Mr. Duncan Pea`, \newline % Row Count 8 (+ 2) street  TYPE string VALUE `Vegetable Lane 11`, \newline % Row Count 10 (+ 2) city   TYPE string VALUE `349875 Botanica`, \newline % Row Count 12 (+ 2) details TYPE TABLE OF some\_table WITH EMPTY KEY, \newline % Row Count 14 (+ 2) END OF address\_d.% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciitilde{}The data types of DDIC types are all flat (not nested) structures. Exception: Components of type string can be contained.\textasciitilde{} \newline \textasciitilde{}Work areas of ABAP SQL statements cannot contain any deep components other than strings among others.\textasciitilde{} \newline \textasciitilde{}Especially for assignments and comparisons of deep structures, the compatibility of the source and target structure must be taken into account.\textasciitilde{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{sy Structure}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The sy (or syst) structure is a built-in data object. \newline % Row Count 2 (+ 2) The components of the structure represent ABAP system fields. \newline % Row Count 4 (+ 2) These fields, filled by the ABAP runtime framework, can be used to query system information and more. \newline % Row Count 7 (+ 3) Typically, they should only be read, and not overwritten. \newline % Row Count 9 (+ 2) Prominent system fields are the following \newline % Row Count 10 (+ 1) ~sy-subrc: Return code of many ABAP statements; typically, the value 0 indicates success \newline % Row Count 12 (+ 2) ~sy-tabix: Row index of internal tables \newline % Row Count 13 (+ 1) ~sy-index: Loop pass index \newline % Row Count 14 (+ 1) These ones and others can be used in ABAP for Cloud Development. However, most of the fields should not be used in ABAP for Cloud Development (indicated by a syntax warning) because they refer to Standard ABAP contexts (e.g. classic dynpros and lists), or their values are not relevant in a cloud context.% Row Count 21 (+ 7) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Clearing Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You can reset individual components to their initial values and clear the entire structure using the CLEAR keyword. Note that FREE statements also deletes the content, but they also release the initially allocated memory. space.% Row Count 5 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Complex Data Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Are composed of other types. \newline % Row Count 1 (+ 1) {\emph{Structured types}}: Represent a sequence of arbitrary data types (i.e., they can be elementary, reference, or complex data types). The typical syntax element for the local definition of a structure is ... BEGIN OF ... END OF .... \newline % Row Count 6 (+ 5) {\emph{Table types}}: Consist of a sequence of any number of lines of the same data type. It can be any elementary type, reference type, or complex data type. The type definition includes other properties such as the table category (defines how tables can be accessed) and table key (to identify the table lines). The typical syntax element is ... TABLE OF .... \newline % Row Count 14 (+ 8) {\emph{Enumerated types}}: Specify a set of values in addition to the actual type properties. The typical syntax element is ... BEGIN OF ENUM ... END OF ENUM .... \newline % Row Count 18 (+ 4) {\emph{Mesh types}}: Special structured type that contains only table types with structured line types as components that can be linked using mesh associations. The typical syntax element is ... BEGIN OF MESH ... END OF MESH .... \newline % Row Count 23 (+ 5) {\emph{BDEF derived types}}: RAP-specific structured and table types. The typical syntax elements are ... TYPE STRUCTURE FOR ... and ... TYPE TABLE FOR .... More information can be found here and in the ABAP cheat sheet on ABAP EML.% Row Count 28 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data objects}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Are objects (or instances) of a data type (similar to objects/instances of classes in ABAP Objects). \newline % Row Count 3 (+ 3) \{\{fa-star\}\}Occupy memory space and exist in different forms, for example, numeric or textual data can be contained in data objects. \newline % Row Count 6 (+ 3) \{\{fa-star\}\}The type of data that a data object can receive is determined by its data type. \newline % Row Count 8 (+ 2) \{\{fa-star\}\}Like data types, their existence and visibility depend on the declaration context. \newline % Row Count 10 (+ 2) \{\{fa-star\}\}Are usually used in ABAP statements by specifying them in the operand position.% Row Count 12 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Ranges Tables}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Internal tables that have the predefined columns SIGN, OPTION, LOW, and HIGH \newline % Row Count 2 (+ 2) \{\{fa-star\}\}Declared with the TYPE RANGE OF addition in DATA and TYPES statements \newline % Row Count 4 (+ 2) \{\{fa-star\}\}Used to store range conditions that can be evaluated in expressions using the IN operator (each row in the table represents a separate comparison)% Row Count 8 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Typed Literals in ABAP SQL}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Literal whose data types is defined by specifying a built-in dictionary type explicitly. \newline % Row Count 2 (+ 2) \{\{fa-star\}\}Available for most but not all ABAP Dictionary data types. \newline % Row Count 4 (+ 2) \{\{fa-star\}\}Can be used in ABAP SQL and in ABAP CDS. \newline % Row Count 6 (+ 2) \{\{fa-star\}\}Advantages of typed literals over untyped literals \newline % Row Count 8 (+ 2) \{\{fa-star\}\}Allow type-safe use of literals \newline % Row Count 9 (+ 1) \{\{fa-star\}\}Eliminate the need for (implicit type) conversions and casts, which can lead to surprising or erroneous results; also consider the conversion costs in terms of performance (typed literals are passed to the database and evaluated there without ABAP-specific type conversions). \newline % Row Count 15 (+ 6) \{\{fa-star\}\}For better readability (you can immediately see what type is being used)% Row Count 17 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Globally Available Structures and Structured Types}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Apart from the local declaration of a structured type, you can create such a type, for example, as global DDIC structure in the ABAP Dictionary. Such a DDIC structure defines a globally available structured type (DDIC type).\{\{nl\}\} \newline % Row Count 5 (+ 5) \{\{fa-star\}\}There are other structured types available globally, which may be the structured types most commonly used in ABAP programs:\{\{nl\}\} \newline % Row Count 8 (+ 3) {\bf{Database tables}} defined in the ABAP Dictionary can be used as data types just like DDIC structures in an ABAP program. This means that when you create a structure in your ABAP program, for example, you can simply use the name of a database table to address the line type of the table. The structure you created will then have the same structured type as the database table. Typically, you use the database tables to create structures of such a type, or internal tables of such a structured line type, to process data read from the database table in structures or internal tables.\{\{nl\}\} \newline % Row Count 20 (+ 12) {\bf{Various CDS entities}} are globally available structured types. For example, a CDS view entity represents a structured data type and can be used as such in ABAP programs (but not in the ABAP Dictionary).\{\{nl\}\} \newline % Row Count 25 (+ 5) {\bf{Structures and structured data types}} can be defined in the public visibility section of global classes or in global interfaces and then used globally.% Row Count 29 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Structures by Inline Declaration}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}This is particularly useful for declaring data objects at the operand positions where you actually need them. \newline % Row Count 3 (+ 3) \{\{fa-star\}\}In this way, you can avoid an extra declaration of the structure in different contexts. \newline % Row Count 5 (+ 2) \{\{fa-star\}\}You can use the declaration operator using DATA(...). The FINAL declaration operator is used to create immutable variables. \newline % Row Count 8 (+ 3) \{\{fa-star\}\}You can also create structures using the VALUE operator (and also fill them as shown below). Without specifying component values in the parentheses, you create an initial structure.% Row Count 12 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Accessing (Components of) Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-star\}\}Structures can be accessed as a whole. You can also address the individual components of structures at the appropriate operand positions. \newline % Row Count 3 (+ 3) \{\{fa-star\}\}To address the components, use the structure component selector -. \newline % Row Count 5 (+ 2) \{\{fa-star\}\}For variables with reference to a structured data object, the object component selector -\textgreater{} can be used: ...dref-\textgreater{}comp .... The following syntax also works, but is less convenient: ... dref-\textgreater{}*-comp .... \newline % Row Count 10 (+ 5) \{\{fa-star\}\}ADT and the ABAP Editor provide code completion for structure components after the component selectors.% Row Count 13 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Processing Structures}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{popup="https://github.com/SAP-samples/abap-cheat-sheets/blob/main/02\_Structures.md\#structures-in-abap-sql-statements"\}\}Structures in ABAP SQL Statements\{\{/popup\}\} \newline % Row Count 4 (+ 4) \{\{popup="https://github.com/SAP-samples/abap-cheat-sheets/blob/main/02\_Structures.md\#structures-in-statements-for-processing-internal-tables"\}\}Structures in Statements for Processing Internal Tables\{\{/popup\}\}% Row Count 9 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Boxed Components}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{In structures, boxed components represent nested structures managed by an internal reference. \newline % Row Count 2 (+ 2) Currently, static boxes are supported as boxed components, enabling initial value sharing. Find more information here. \newline % Row Count 5 (+ 3) When used: \newline % Row Count 6 (+ 1) ~Optimize memory consumption for structures used repeatedly, such as in internal tables with nested structures. Without boxed components, memory increases line by line, even if the nested structure is initial. With boxed components, memory does not increase when nested structures are initial, and only reads are performed. \newline % Row Count 13 (+ 7) ~Enhance runtime performance since assignments for components with active initial value sharing require only the internal reference, not additional data to be copied. \newline % Row Count 17 (+ 4) Boxed components allocate memory when there is write access to at least one component or when a field symbol is assigned or data reference points to at least one component.% Row Count 21 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}