0% found this document useful (0 votes)
4 views

louis-lee_abap-programing.bw

This ABAP Programming Cheat Sheet provides an overview of data types, reference types, type conversions, and assignments in ABAP programming. It covers the creation of structures, including nested structures and the use of runtime type services, as well as the handling of elementary data types and enumerated types. The document serves as a quick reference for various programming concepts and syntax in ABAP.

Uploaded by

serigne ndiaye
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

louis-lee_abap-programing.bw

This ABAP Programming Cheat Sheet provides an overview of data types, reference types, type conversions, and assignments in ABAP programming. It covers the creation of structures, including nested structures and the use of runtime type services, as well as the handling of elementary data types and enumerated types. The document serves as a quick reference for various programming concepts and syntax in ABAP.

Uploaded by

serigne ndiaye
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ABAP Programing Cheat Sheet

by louis_lee via cheatography.com/210062/cs/45284/

Data Types Reference Types Type Conver​sions, Compat​ibility and


Assign​ments (cont)
 Define technical properties of all data Describe data objects that contain
objects that have these data types, such as references to other objects (data objects  The source and target data types are
the maximum length of a text field. and instances of classes), which are known compat​ible, i.e. all technical type properties
 Are descri​ptions only, with no data as reference variables. match. The content is transf​erred from the
memory attached except for admini​str​ative There are two kinds of refere​nces: Data source to the target without being
inform​ation. references (refer​ences to data objects) and converted.
 Can occur in ABAP programs as bound object references (refer​ences to objects as  The source and target data types are
data types, that is, the type is a property of a instances of classes). incomp​atible, but can be converted. The
data object, or as a standalone data type, A reference type must be defined either in content of the source is converted
that is, the data type is defined indepe​nde​‐ the ABAP program or in the ABAP Dictio​‐ according to the conversion rules and then
ntly. nary. There are no built-in reference types transf​erred to the target. Two data types are
 Can be defined locally in an ABAP in ABAP. conver​tible if a conversion rule exists for
program or globally in classes, interfaces The typical syntax element is ... REF TO .... them. An exception is raised if the content
and in the ABAP Dictionary (DDIC). of the source cannot be handled according
Type Conver​sions, Compat​ibility and to the conversion rules.
Data types declared in interfaces and in the
Assign​ments  If the data objects are neither compatible
public visibility section of global classes are
nor conver​tible, no assignment can take
A value assignment means that the value of
also globally visibile. Global classes and place. If the syntax check detects this state,
a data object is transf​erred to a target data
interfaces as such are global types to refer a syntax error is raised, otherwise an
object. If the data types of the source and
to. In classic ABAP, you may stumble on the uncatc​hable exception is raised when the
target are compat​ible, the content is copied
program is executed.
option to create global data types in type unchanged. If they are incomp​atible and a
 Notes:
pools, which is not possible in ABAP for suitable conversion rule exists, the content
is converted. The following cases must be
Cloud Develo​pment. However, the
distin​guished with regard to the data type:
predefined type pool abap can be used in
ABAP for Cloud Develo​pment.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 1 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Type Conver​sions, Compat​ibility and Type Conver​sions, Compat​ibility and Creating Structured Types
Assign​ments (cont) Assign​ments (cont)
 The type name is preceded by BEGIN
The operands of many ABAP statements The applie​s_t​o_data method of the RTTI OF (which marks the beginning of the
structured type defini​tion) and END OF (the
are assigned internally according to the class cl_aba​p_d​ata​descr can be used to
end of the defini​tion).
assignment rules. check type compat​ibi​lity.
 The components - at least one must be
defined - are listed in between.
Typically, assign​ements are made using the Non-Ad​mis​sible Values of Literals
 Such structured type defini​tions are
assignment operator =. If necessary and Note recent syntax warnings when using usually grouped together in a chained
applic​able, the type is converted implic​itly. literals that represent invalid values for statement, i.e. TYPES is followed by a
target types. The following example colon, and the components are separated
However, you can also use the conversion
demons​trates the assignment of literals by commas.
operator CONV to convert types explic​itly.
using admissible and non-ad​mis​sible  The simplest structures and structured
values. You can copy and paste the code types have elementary compon​ents.
For lossless assign​ments, the lossless
into a demo class in your SAP BTP ABAP  As mentioned above, the components
operator EXACT can be used to perform Enviro​nment to explore the syntax can be of any type, i.e. they can be of
checks before the conversion is performed warnings. structured types themse​lves, internal table
to ensure that only valid values are DATA char3 TYPE c LENGTH 3. types, or reference types.
assigned and that no values are lost in  You can use the TYPE and LIKE
"​Value is admissable and conver​tible additions for the types of the compon​ents.
assign​ments.
char3 = 'abc'. You can use the LINE OF addition to refer
to a table type or an internal table.
In general, no checks are performed on
"​Non​-ad​mis​sable value assigned to the
assign​ments between compatible data Outside of classes, you can also refer to
target (type c length 6)
objects. If a data object already contains an DDIC types using LIKE (... comp11 LIKE
char3 = 'defghi'.
invalid value, for example, an invalid date or ddic_type, ...). If you actually want to refer to

time in a date or time field, it is passed a DATA date TYPE d. an existing data object, but due to typing

valid value when the assignment is made to errors you inadve​rtently specify a name that
"​Value is admissable and conver​tible exists as DDIC type, errors may be unavoi​‐
a compatible data object.
date = '20250​101'.
dable.

"​Non​-ad​mis​sable value assigned to the


target
"Type i
date = 20250101.
"More characters than type d
date = '20250​101​234'.
"​Fewer characters than type d
date = '202511'.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 2 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Demo Example Data Type And Data Object Populating Structures (cont) Including Structures

 Using the NEW Operator:Using the  INCLUDE TYPE and INCLUDE


Demo
instance operator NEW, you can create STRUCTURE statements are used in the
anonymous data objects, such as context of local struct​ures.
Creating Anonymous Structures
anonymous struct​ures. You can access the  Structured data objects and types
Using the instance operator NEW and
components or the entire data objects by created with ... BEGIN OF... END OF ... can
CREATE DATA statem​ents, you can create
derefe​ren​cing. use this syntax to include components of
anonymous data objects, such as
 You can use statements with MOVE-C​‐ another structure, whether it is a locally
anonymous struct​ures. The NEW addition
ORR​ESP​ONDING and the CORRES​‐ defined or global structure, without creating
of the INTO clause of an ABAP SQL
PONDING operator to assign values to substr​uct​ures.
SELECT statement also creates an
structure compon​ents, especially when  INCLUDE TYPE can be used to include
anonymous data object. As outlined below,
assigning values from a source structure to a structured type.
you can access the components or the
a target structure which have incomp​atible  You can use INCLUDE STRUCTURE to
entire data objects by derefe​ren​cing.
types and/or differ​ently named compon​ents. include a structure.
They are not additions of ... BEGIN OF ...
Populating Structures The CL_ABA​P_C​ORR​ESP​ONDING system
END OF ... but individual ABAP statem​ents.
class is available for making assign​ments.
 You can copy the content of a structure
If you use a chained statement with a colon
to another using the assignment operator =. The INTO clause of ABAP SQL statements
to declare the structure, the inclusion of
In general, note that special conversion and has the CORRES​PONDING addition.
comparison rules apply to value assign​‐ other structures with these statements
There, the following basic rule applies,
ments involving struct​ures. interrupts the chained statement, that is, the
which affects the value assign​ment: Without
 Using the VALUE Operator:The VALUE components of the included structures are
the CORRES​PONDING ... addition, column
operator can be used to construct the
included as direct components of the
names do not matter, only the position. With
content of complex data objects such as
supers​tru​cture.
structures or internal tables. the CORRES​PONDING ... addition, the
position of the columns does not matter,
only the name.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 3 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Including Structures (cont) Elementary data types Creating Types/Data Objects at Runtime

By using the optional AS addition and Elementary (or scalar) data types are based Using Runtime Type Services (RTTS) you
directly on a set of built-in ABAP types. can ...
specifying a name, the included
Numeric types: Integers (b, s, i, int8),  get type inform​ation on data objects, data
components can be addressed by this
decimal floating point numbers (decfl​oat16, types or instances at runtime (Runtime
common name as if they were actually
decflo​at34), binary floating point numbers Type Identi​fic​ation (RTTI)).
components of a substr​ucture. (f), and packed numbers (p)  define and create new data types as type
The optional RENAMING WITH SUFFIX Charac​ter​-like types: text fields (c) and descri​ption objects at runtime (Runtime
addition, followed by a name, gives the numeric text fields (n) Type Creation (RTTC)).
Byte-like type: byte fields (x)
included components a suffix name to avoid
Charac​ter​-like date and time types: date ABAP Enumerated Types and Objects
naming conflicts with other compon​ents.
fields (d) and time fields (t)
 ABAP supports the concept of enumer​‐
Time stamp type for time stamp fields
Demo ABAP Structure ations.
(utclong).
 Enumer​ations are a mixture of types and
Executable Example Charac​ter​-like type for text strings (string)
constants.
Byte-like type for byte strings (xstring)
 An enumerated type specifies a value set
Generic Types
The data types c, n, x, and p are incomp​‐ in addition to the actual type proper​ties.
 Generic types are available with which  Enumerated objects - data objects with
lete, i.e., generic data types, with respect to
formal parameters of methods or field an enumerated type - are mainly used to
their length. The type definition syntax has
symbols can be specified. check allowed values. This usually restricts
 At runtime, the actual data type is copied a special addition for this (LENGTH). In
the actual parameters passed to methods to
from the assigned actual parameter or addition, p is also generic with respect to the enumerated values defined in the class.
memory area, i.e. they receive the complete the number of decimal places (DECIMALS Enumerated variables are variable
data type only when an actual parameter is enumerated objects. They can only contain
addition). See more about generic types in
passed or a memory area is assigned. the associated enumerated values.
the following sections.
 CDS enumerated types are also
The TYPE REF TO addition types as a
available.
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.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 4 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Creating Structures Structures (cont) Variants of Structures (cont)

To create a structure (i.e. a structured data  are used to combine different data comp2 TYPE c LENGTH 15,
object) in an ABAP program, you can use objects that belong together. A typical comp3 TYPE p LENGTH 8 DECIMALS 2,
the DATA keyword. example is an address. It has several ...,
It works in the same way as the TYPES compon​ents, such as name, street, city, END OF struc.
statement above. and so on, that belong together.  Nested struct​ures: At least one
Unlike the TYPES statement, you can use play an important role in the context of component of a structure is a substr​ucture,
the VALUE addition to set default values. internal tables and database tables. that is, it refers to another structure. The
Structured types serve as line types for following example has multiple substr​uct​‐
The keywords CLASS-DATA and
these tables. Most internal tables across ures.
CONSTANTS can also be used to create
ABAP programs may have structured line DATA: BEGIN OF address_n,
struct​ures. In principle, they represent types. For database tables, there is no BEGIN OF name,
special cases of the general statement altern​ative to structured line types. title TYPE string VALUE Mr.,
shown above.  can be created locally in an ABAP prename TYPE string VALUE Duncan,
program and globally. surname TYPE string VALUE Pea,
Structures can also be created inline using
END OF name,
DATA(...) or FINAL(...).
Variants of Structures BEGIN OF street,
 Flat structures contain only elementary name TYPE string VALUE Vegetable La
Structures
types that have a fixed length, that is, there ne,
Structures ...
are no internal tables, reference types or num TYPE string VALUE 11,
 are data objects with structured data
strings as compon​ents. Nesting does not END OF street,
types (which is a complex data type
matter in this context. Even a nested BEGIN OF city,
because it is composed of other data
structure is considered flat unless a substr​‐ zipcode TYPE string VALUE 349875,
types).
ucture contains a deep component. name ​ TYPE string VALUE Botanica,
 consist of a sequence of components of
DATA: BEGIN OF struc,
any data type, that is, the components of a
comp1 TYPE i,
structure can be, for example, elementary
data objects, structures themse​lves, internal
tables or refere​nces.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 5 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Variants of Structures (cont) sy Structure Clearing Structures

END OF city, The sy (or syst) structure is a built-in data You can reset individual components to
END OF address_n. object. their initial values and clear the entire
 Deep struct​ures: Contains at least one The components of the structure represent structure using the CLEAR keyword. Note
internal table, reference type, or string as a ABAP system fields. that FREE statements also deletes the
component. These fields, filled by the ABAP runtime content, but they also release the initially
DATA: BEGIN OF address_d, framework, can be used to query system allocated memory. space.
name TYPE string VALUE Mr. Duncan inform​ation and more.
Pea, Typically, they should only be read, and not Complex Data Types
street TYPE string VALUE Vegetable La overwr​itten.
Are composed of other types.
Prominent system fields are the following
ne 11, Structured types: Represent a sequence of
city TYPE string VALUE 349875 Botani ​sy-​subrc: Return code of many ABAP
arbitrary data types (i.e., they can be
statem​ents; typically, the value 0 indicates
ca, elemen​tary, reference, or complex data
success
details TYPE TABLE OF some_table WITH types). The typical syntax element for the
​sy-​tabix: Row index of internal tables
EMPTY KEY, local definition of a structure is ... BEGIN
​sy-​index: Loop pass index
END OF address_d. OF ... END OF ....
These ones and others can be used in
Table types: Consist of a sequence of any
The data types of DDIC types are all flat ABAP for Cloud Develo​pment. However,
number of lines of the same data type. It
(not nested) struct​ures. Exception: most of the fields should not be used in
can be any elementary type, reference type,
Components of type string can be ABAP for Cloud Develo​pment (indicated by
or complex data type. The type definition
a syntax warning) because they refer to
contained. includes other properties such as the table
Standard ABAP contexts (e.g. classic
Work areas of ABAP SQL statements category (defines how tables can be
dynpros and lists), or their values are not
accessed) and table key (to identify the
cannot contain any deep components other
relevant in a cloud context.
table lines). The typical syntax element is ...
than strings among others.
TABLE OF ....
Especially for assign​ments and compar​‐
isons of deep struct​ures, the compat​ibility of
the source and target structure must be
taken into account.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 6 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Complex Data Types (cont) Data objects (cont) Typed Literals in ABAP SQL (cont)

Enumerated types: Specify a set of values  The type of data that a data object can  Advantages of typed literals over untyped
in addition to the actual type proper​ties. The receive is determined by its data type. literals
typical syntax element is ... BEGIN OF  Like data types, their existence and  Allow type-safe use of literals
ENUM ... END OF ENUM .... visibility depend on the declar​ation context.  Eliminate the need for (implicit type)
Mesh types: Special structured type that  Are usually used in ABAP statements by conver​sions and casts, which can lead to
contains only table types with structured line specifying them in the operand position. surprising or erroneous results; also
types as components that can be linked consider the conversion costs in terms of
using mesh associ​ations. The typical syntax Ranges Tables perfor​mance (typed literals are passed to
element is ... BEGIN OF MESH ... END OF the database and evaluated there without
 Internal tables that have the predefined
MESH .... ABAP-s​pecific type conver​sions).
columns SIGN, OPTION, LOW, and HIGH
BDEF derived types: RAP-sp​ecific  For better readab​ility (you can immedi​‐
 Declared with the TYPE RANGE OF
structured and table types. The typical ately see what type is being used)
addition in DATA and TYPES statements
syntax elements are ... TYPE STRUCTURE
 Used to store range conditions that can
FOR ... and ... TYPE TABLE FOR .... More Globally Available Structures and
be evaluated in expres​sions using the IN
inform​ation can be found here and in the Structured Types
operator (each row in the table represents a
ABAP cheat sheet on ABAP EML.
separate compar​ison)  Apart from the local declar​ation of a
structured type, you can create such a type,
Data objects
Typed Literals in ABAP SQL for example, as global DDIC structure in the
 Are objects (or instances) of a data type ABAP Dictio​nary. Such a DDIC structure
Literal whose data types is defined by
(similar to object​s/i​nst​ances of classes in defines a globally available structured type
specifying a built-in dictionary type explic​‐
ABAP Objects). (DDIC type).
itly.
 Occupy memory space and exist in
 Available for most but not all ABAP
different forms, for example, numeric or  There are other structured types
Dictionary data types.
textual data can be contained in data available globally, which may be the
 Can be used in ABAP SQL and in ABAP
objects. structured types most commonly used in
CDS.
ABAP programs:

Database tables defined in the ABAP


Dictionary can be used as data types just
like DDIC structures in an ABAP program.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 7 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Globally Available Structures and Creating Structures by Inline Declar​ation Accessing (Compo​nents of) Structures
Structured Types (cont) (cont)
 This is partic​ularly useful for declaring
This means that when you create a data objects at the operand positions where  For variables with reference to a
structure in your ABAP program, for you actually need them. structured data object, the object
example, you can simply use the name of a  In this way, you can avoid an extra component selector -> can be used: ...dre​f-
database table to address the line type of declar​ation of the structure in different >comp .... The following syntax also works,
the table. The structure you created will contexts. but is less conven​ient: ... dref->​*-comp ....
then have the same structured type as the  You can use the declar​ation operator  ADT and the ABAP Editor provide code
database table. Typically, you use the using DATA(...). The FINAL declar​ation completion for structure components after
database tables to create structures of such operator is used to create immutable the component selectors.
a type, or internal tables of such a variables.
structured line type, to process data read  You can also create structures using the Processing Structures
from the database table in structures or VALUE operator (and also fill them as
Structures in ABAP SQL Statements
internal tables. shown below). Without specifying
Structures in Statements for Processing
. Various CDS entities are globally available component values in the parent​heses, you
Internal Tables
structured types. For example, a CDS view create an initial structure.
entity represents a structured data type and
Boxed Components
can be used as such in ABAP programs Accessing (Compo​nents of) Structures
In struct​ures, boxed components represent
(but not in the ABAP Dictionary).
 Structures can be accessed as a whole.
nested structures managed by an internal
You can also address the individual
reference.
Structures and structured data types can be
components of structures at the approp​riate
Currently, static boxes are supported as
defined in the public visibility section of
operand positions.
boxed compon​ents, enabling initial value
global classes or in global interfaces and
 To address the compon​ents, use the
sharing. Find more inform​ation here.
then used globally.
structure component selector -.
When used:

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 8 of 9. http://crosswordcheats.com
ABAP Programing Cheat Sheet
by louis_lee via cheatography.com/210062/cs/45284/

Boxed Components (cont)

​Opt​imize memory consum​ption for


structures used repeat​edly, such as in
internal tables with nested struct​ures.
Without boxed compon​ents, memory
increases line by line, even if the nested
structure is initial. With boxed compon​ents,
memory does not increase when nested
structures are initial, and only reads are
performed.
​Enhance runtime perfor​mance since
assign​ments for components with active
initial value sharing require only the internal
reference, not additional data to be copied.
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.

By louis_lee Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/louis-lee/ Last updated 19th December, 2024. Learn to solve cryptic crosswords!
Page 9 of 9. http://crosswordcheats.com

You might also like