Update
This commit is contained in:
@@ -84,7 +84,7 @@ FIELD-SYMBOLS: <fs_i> TYPE i,
|
||||
<fs_tab_type> TYPE LINE OF some_table_type,
|
||||
<fs_like> LIKE some_data_object.
|
||||
|
||||
"Examples for generic types
|
||||
"Examples for generic types (see more examples further down)
|
||||
FIELD-SYMBOLS <fs_c> TYPE c. "Text field with a generic length
|
||||
FIELD-SYMBOLS <fs_cseq> TYPE csequence. "Text-like (c, string)
|
||||
FIELD-SYMBOLS <fs_data> TYPE data. "Any data type
|
||||
@@ -104,7 +104,7 @@ ENDLOOP.
|
||||
>- There are plenty of options for generic ABAP types. A prominent one
|
||||
is `data` that stands for any data type. See more information in the
|
||||
topic [Generic ABAP
|
||||
Types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuilt_in_types_generic.htm).
|
||||
Types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuilt_in_types_generic.htm) and in a code snippet below.
|
||||
>- Field symbols cannot be declared in the declaration part of
|
||||
[classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_glosry.htm "Glossary Entry")
|
||||
and
|
||||
@@ -126,8 +126,8 @@ APPEND INITIAL LINE TO itab_fli.
|
||||
|
||||
"Declaring field symbols with complete types
|
||||
FIELD-SYMBOLS: <fs_i> TYPE i,
|
||||
<fs_struc> TYPE zdemo_abap_fli,
|
||||
<fs_tab> TYPE string_table.
|
||||
<fs_struc> TYPE zdemo_abap_fli,
|
||||
<fs_tab> TYPE string_table.
|
||||
|
||||
"Declaring field symbols with generic type
|
||||
FIELD-SYMBOLS <fs_gen> TYPE data.
|
||||
@@ -212,12 +212,167 @@ ENDLOOP.
|
||||
|
||||
"Inline declaration of a field symbol. The field symbol is implcitly typed
|
||||
"with the generic type data.
|
||||
"type automatically.
|
||||
LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs2>).
|
||||
<fs2>-carrid = ...
|
||||
<fs2>-connid = ...
|
||||
...
|
||||
ENDLOOP.
|
||||
|
||||
"----------- Generic typing -----------
|
||||
"- Generic types are available with which formal parameters of methods or field symbols
|
||||
" can be specified.
|
||||
"- 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.
|
||||
|
||||
"The following code snippet demonstrates generic types with field symbols.
|
||||
FIELD-SYMBOLS:
|
||||
"Any data type
|
||||
<data> TYPE data,
|
||||
<any> TYPE any,
|
||||
"Any data type can be assigned. Restrictions for formal parameters and 'data': no
|
||||
"numeric functions, no description functions, and no arithmetic expressions can be
|
||||
"passed to these parameters. However, you can bypass the restriction by applying the
|
||||
"CONV operator for the actual parameter.
|
||||
|
||||
"Character-like types
|
||||
<c> TYPE c, "Text field with a generic length
|
||||
<clike> TYPE clike, "Character-like (c, n, string, d, t and character-like flat structures)
|
||||
<csequence> TYPE csequence, "Text-like (c, string)
|
||||
<n> TYPE n, "Numeric text with generic length
|
||||
<x> TYPE x, "Byte field with generic length
|
||||
<xsequence> TYPE xsequence, "Byte-like (x, xstring)
|
||||
|
||||
"Numeric types
|
||||
<decfloat> TYPE decfloat, "decfloat16, decfloat34)
|
||||
<numeric> TYPE numeric, "Numeric ((b, s), i, int8, p, decfloat16, decfloat34, f)
|
||||
<p> TYPE p, "Packed number (generic length and number of decimal places)
|
||||
|
||||
"Internal table types
|
||||
<any_table> TYPE ANY TABLE, "Internal table with any table type
|
||||
<hashed_table> TYPE HASHED TABLE,
|
||||
<index_table> TYPE INDEX TABLE,
|
||||
<sorted_table> TYPE SORTED TABLE,
|
||||
<standard_table> TYPE STANDARD TABLE,
|
||||
<table> TYPE table, "Standard table
|
||||
|
||||
"Other types
|
||||
<simple> TYPE simple, "Elementary data type including enumerated types and
|
||||
"structured types with exclusively character-like flat components
|
||||
<object> TYPE REF TO object. "object can only be specified after REF TO; can point to any object
|
||||
|
||||
"Data objects to work with
|
||||
DATA: BEGIN OF s,
|
||||
c3 TYPE c LENGTH 3,
|
||||
c10 TYPE c LENGTH 10,
|
||||
n4 TYPE n LENGTH 4,
|
||||
str TYPE string,
|
||||
time TYPE t,
|
||||
date TYPE d,
|
||||
dec16 TYPE decfloat16,
|
||||
dec34 TYPE decfloat34,
|
||||
int TYPE i,
|
||||
pl4d2 TYPE p LENGTH 4 DECIMALS 2,
|
||||
tab_std TYPE STANDARD TABLE OF string WITH EMPTY KEY,
|
||||
tab_so TYPE SORTED TABLE OF string WITH NON-UNIQUE KEY table_line,
|
||||
tab_ha TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line,
|
||||
xl1 TYPE x LENGTH 1,
|
||||
xstr TYPE xstring,
|
||||
structure TYPE zdemo_abap_carr, "character-like flat structure
|
||||
oref TYPE REF TO object,
|
||||
END OF s.
|
||||
|
||||
"The following static ASSIGN statements demonstrate various assignments
|
||||
"Note:
|
||||
"- The statements commented out show impossible assignments.
|
||||
"- If a static assignment is not successful, sy-subrc is not set and no
|
||||
" memory area is assigned. Dynamic assignments, however, set the value.
|
||||
|
||||
"----- Any data type -----
|
||||
ASSIGN s-c3 TO <data>.
|
||||
ASSIGN s-time TO <data>.
|
||||
ASSIGN s-tab_std TO <data>.
|
||||
ASSIGN s-xstr TO <any>.
|
||||
ASSIGN s-pl4d2 TO <any>.
|
||||
ASSIGN s-date TO <any>.
|
||||
|
||||
"----- Character-like types -----
|
||||
ASSIGN s-c3 TO <c>.
|
||||
ASSIGN s-c10 TO <c>.
|
||||
"ASSIGN s-str TO <c>.
|
||||
|
||||
ASSIGN s-c10 TO <clike>.
|
||||
ASSIGN s-str TO <clike>.
|
||||
ASSIGN s-n4 TO <clike>.
|
||||
ASSIGN s-date TO <clike>.
|
||||
ASSIGN s-time TO <clike>.
|
||||
ASSIGN s-structure TO <clike>.
|
||||
|
||||
ASSIGN s-c10 TO <csequence>.
|
||||
ASSIGN s-str TO <csequence>.
|
||||
"ASSIGN s-n4 TO <csequence>.
|
||||
|
||||
ASSIGN s-n4 TO <n>.
|
||||
"ASSIGN s-int TO <n>.
|
||||
"ASSIGN s-time TO <n>.
|
||||
|
||||
ASSIGN s-xl1 TO <x>.
|
||||
"ASSIGN s-xstr TO <x>.
|
||||
|
||||
ASSIGN s-xl1 TO <xsequence>.
|
||||
ASSIGN s-xstr TO <xsequence>.
|
||||
|
||||
"----- Numeric types -----
|
||||
ASSIGN s-dec16 TO <numeric>.
|
||||
ASSIGN s-dec34 TO <numeric>.
|
||||
ASSIGN s-int TO <numeric>.
|
||||
ASSIGN s-pl4d2 TO <numeric>.
|
||||
"ASSIGN s-n4 TO <numeric>.
|
||||
|
||||
ASSIGN s-dec16 TO <decfloat>.
|
||||
ASSIGN s-dec34 TO <decfloat>.
|
||||
|
||||
ASSIGN s-pl4d2 TO <p>.
|
||||
"ASSIGN s-dec34 TO <p>.
|
||||
|
||||
"----- Internal table types -----
|
||||
ASSIGN s-tab_std TO <any_table>.
|
||||
ASSIGN s-tab_so TO <any_table>.
|
||||
ASSIGN s-tab_ha TO <any_table>.
|
||||
|
||||
ASSIGN s-tab_std TO <index_table>.
|
||||
ASSIGN s-tab_so TO <index_table>.
|
||||
"ASSIGN s-tab_ha TO <index_table>.
|
||||
|
||||
"ASSIGN s-tab_std TO <sorted_table>.
|
||||
ASSIGN s-tab_so TO <sorted_table>.
|
||||
"ASSIGN s-tab_ha TO <sorted_table>.
|
||||
|
||||
ASSIGN s-tab_std TO <standard_table>.
|
||||
ASSIGN s-tab_std TO <table>.
|
||||
"ASSIGN s-tab_so TO <standard_table>.
|
||||
"ASSIGN s-tab_so TO <table>.
|
||||
"ASSIGN s-tab_ha TO <standard_table>.
|
||||
"ASSIGN s-tab_ha TO <table>.
|
||||
|
||||
"ASSIGN s-tab_std TO <hashed_table>.
|
||||
"ASSIGN s-tab_so TO <hashed_table>.
|
||||
ASSIGN s-tab_ha TO <hashed_table>.
|
||||
|
||||
"----- Other types -----
|
||||
ASSIGN s-c10 TO <simple>.
|
||||
ASSIGN s-str TO <simple>.
|
||||
ASSIGN s-dec34 TO <simple>.
|
||||
ASSIGN s-date TO <simple>.
|
||||
ASSIGN s-structure TO <simple>.
|
||||
ASSIGN s-xl1 TO <simple>.
|
||||
"ASSIGN s-tab_ha TO <simple>.
|
||||
|
||||
ASSIGN s-oref TO <object>.
|
||||
s-oref = NEW zcl_demo_abap_objects( ).
|
||||
ASSIGN s-oref TO <object>.
|
||||
s-oref = cl_abap_random_int=>create( ).
|
||||
ASSIGN s-oref TO <object>.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
@@ -503,7 +658,7 @@ DATA(ref_bound) = COND #( WHEN ref_carr IS BOUND THEN ref_carr->carrid ELSE `is
|
||||
CLEAR ref_carr.
|
||||
|
||||
******************************************************
|
||||
"Excursion: Generic data references in older ABAP releases
|
||||
"Excursion: Generic data references and field symbols
|
||||
|
||||
"Non-generic type
|
||||
DATA ref_int TYPE REF TO i.
|
||||
@@ -524,14 +679,35 @@ ASSIGN ref_generic->* TO FIELD-SYMBOL(<fs_generic>).
|
||||
"An access as the following, as it is possible in modern ABAP, was not possible.
|
||||
ref_generic->* = 123.
|
||||
|
||||
"As shown in the example below, using dereferenced generic references is possible
|
||||
"in various places in modern ABAP.
|
||||
DATA ref_sel TYPE REF TO data.
|
||||
CREATE DATA ref_sel TYPE TABLE OF zdemo_abap_carr.
|
||||
|
||||
SELECT *
|
||||
"In modern ABAP, variables and field symbols of the generic types
|
||||
"'any' and 'data' can be used directly, for example, in LOOP and READ statements.
|
||||
DATA dref TYPE REF TO data.
|
||||
CREATE DATA dref TYPE TABLE OF zdemo_abap_carr.
|
||||
SELECT *
|
||||
FROM zdemo_abap_carr
|
||||
INTO TABLE @ref_sel->*.
|
||||
INTO TABLE @dref->*.
|
||||
|
||||
"Note: In case of a fully generic type, an explicit or implicit index operation
|
||||
"is not possible (indicated by the examples commented out).
|
||||
LOOP AT dref->* ASSIGNING FIELD-SYMBOL(<loop>).
|
||||
...
|
||||
ENDLOOP.
|
||||
"LOOP AT dref->* ASSIGNING FIELD-SYMBOL(<loop2>) FROM 1 TO 4.
|
||||
"ENDLOOP.
|
||||
|
||||
"The following examples use a dynamic key specification.
|
||||
"See more syntax examples below.
|
||||
READ TABLE dref->* ASSIGNING FIELD-SYMBOL(<read>) WITH KEY ('CARRID') = 'AA'.
|
||||
"READ TABLE dref->* INDEX 1 ASSIGNING FIELD-SYMBOL(<read2>).
|
||||
|
||||
"Table expressions
|
||||
DATA(line) = CONV zdemo_abap_carr( dref->*[ ('CARRID') = 'AA' ] ).
|
||||
dref->*[ ('CARRID') = 'AA' ] = VALUE zdemo_abap_carr( BASE dref->*[ ('CARRID') = 'AA' ] carrid = 'XY' ).
|
||||
dref->*[ ('CARRID') = 'XY' ]-('CARRID') = 'ZZ'.
|
||||
|
||||
"Table functions
|
||||
DATA(num_tab_lines) = lines( dref->* ).
|
||||
DATA(idx) = line_index( dref->*[ ('CARRID') = 'LH' ] ).
|
||||
```
|
||||
|
||||
**Examples using data references**
|
||||
@@ -685,8 +861,7 @@ ASSIGN ('ST') TO <fs>.
|
||||
"Note: The typing is performed with the generic type data.
|
||||
ASSIGN ('DOBJ') TO FIELD-SYMBOL(<fs_inline>).
|
||||
|
||||
"The statements set the sy-subrc value. No exception occurs in
|
||||
"case of an unsuccessful assignment.
|
||||
"The statements set the sy-subrc value.
|
||||
ASSIGN ('DOES_NOT_EXIST') TO <fs>.
|
||||
IF sy-subrc <> 0.
|
||||
...
|
||||
@@ -776,13 +951,17 @@ ASSIGN NEW zcl_demo_abap_objects( )->('PUBLIC_STRING') TO <fs>.
|
||||
"Note: For the static variant of the ASSIGN statement, i.e. if the memory area
|
||||
"to be assigned following the ASSIGN keyword is statically specified, the addition
|
||||
"ELSE UNASSIGN is implicitly set and cannot be used explicitly.
|
||||
DATA(hallo) = `Hello world`.
|
||||
DATA(hallo) = `Hallo world`.
|
||||
ASSIGN ('HALLO') TO FIELD-SYMBOL(<eu>) ELSE UNASSIGN.
|
||||
ASSERT sy-subrc = 0 AND <eu> IS ASSIGNED.
|
||||
ASSIGN ('DOES_NOT_EXIST') TO <eu> ELSE UNASSIGN.
|
||||
ASSERT sy-subrc = 4 AND <eu> IS NOT ASSIGNED.
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - The following `ASSIGN` statements set the `sy-subrc` value: dynamic assignments, dynamic component assignment, dynamic invokes, assignments of table expressions.
|
||||
> - The return code is not set for a static assignment and an assignment of the constructor operator `CAST`.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Dynamically Specifying Data Types/Creating (Data) Objects
|
||||
@@ -1242,7 +1421,7 @@ CLASS zcl_example_class IMPLEMENTATION.
|
||||
"- The following example is just ABAP code exploring dynamic programming
|
||||
" aspects. Note the disclaimer in the README of the cheat sheet repository.
|
||||
" It is an example that sets its focus on a dynamic SELECT statement and
|
||||
" processing internal tablecontent by dynamically accessing structure
|
||||
" processing internal table content by dynamically accessing structure
|
||||
" components.
|
||||
"- The ways mentioned above are way more powerful (e.g. in most cases also
|
||||
" nested and deep data objects can be displayed for demo purposes).
|
||||
@@ -1294,6 +1473,7 @@ CLASS zcl_example_class IMPLEMENTATION.
|
||||
APPEND VALUE #( name = <comp>-name len = strlen( <comp>-name ) ) TO it_comps.
|
||||
ENDLOOP.
|
||||
CATCH cx_sy_move_cast_error INTO DATA(error).
|
||||
out->write( |{ error->get_text( ) }| ).
|
||||
ENDTRY.
|
||||
|
||||
IF error IS INITIAL.
|
||||
|
||||
@@ -269,8 +269,8 @@ started.
|
||||
options](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcompute_string_format_options.htm).
|
||||
- Refer to the ABAP Keyword Documentation for all options.
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
The following syntax examples demonstrate a selection:
|
||||
```abap
|
||||
"Control characters
|
||||
s4 = |{ s1 }\n{ s2 }\nSee you.|. "\n is interpreted as a line feed
|
||||
|
||||
@@ -283,22 +283,39 @@ ASSERT cl_abap_char_utilities=>horizontal_tab = |\t|.
|
||||
ASSERT cl_abap_char_utilities=>cr_lf = |\r\n|.
|
||||
|
||||
"Various formatting options
|
||||
"Time and date
|
||||
"Formatting according to the user master data
|
||||
DATA(d) = |The date is { cl_abap_context_info=>get_system_date( ) DATE = USER }.|.
|
||||
"DATE: Defining the format of a date
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(d) = |The date is { cl_abap_context_info=>get_system_date( ) DATE = USER }.|. "The date is 01/01/2024.
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = RAW }|. "20240101
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ISO }|. "2024-01-01
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ENVIRONMENT }|. "01/01/2024
|
||||
|
||||
"Formatting in accordance with ISO 8601
|
||||
DATA(tm) = |The time is { cl_abap_context_info=>get_system_time( ) TIME = ISO }.|.
|
||||
"TIME: Defining the format of a time
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(tm) = |The time is { cl_abap_context_info=>get_system_time( ) TIME = ISO }.|. "The time is 14:37:24.
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = RAW }|. "143724
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = USER }|. "14:37:24
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = ENVIRONMENT }|. "14:37:24
|
||||
|
||||
"Formatting to UTC; date and time are represented in ISO 8601
|
||||
DATA(ts) = |Timestamp: { utclong_current( ) TIMESTAMP = SPACE }.|.
|
||||
"TIMESTAMP: Defining the format of a time stamp
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(ts) = |{ utclong_current( ) TIMESTAMP = SPACE }|. "2024-01-01 14:39:50.4069170
|
||||
ts = |{ utclong_current( ) TIMESTAMP = ISO }|. "2024-01-01T14:39:50,4071110
|
||||
ts = |{ utclong_current( ) TIMESTAMP = USER }|. "01/01/2024 14:39:50.4072010
|
||||
ts = |{ utclong_current( ) TIMESTAMP = ENVIRONMENT }|. "01/01/2024 14:39:50.4073230
|
||||
ts = |{ utclong_current( ) }|. "2024-01-01 14:39:50.4074060
|
||||
|
||||
"Lowercase and uppercase
|
||||
"TIMEZONE: Defining the format of a time stamp using the rules for time zones
|
||||
DATA(tz) = |{ utclong_current( ) TIMEZONE = 'UTC' }|. "2024-12-30 14:43:20.6534640
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'CET' COUNTRY = 'DE ' }|. "30.12.2024 15:43:20,6536320
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'EST' COUNTRY = 'US ' }|. "12/30/2024 09:43:20.6889180 AM
|
||||
|
||||
"CASE: Lowercase and uppercase
|
||||
s1 = |AbCdEfG|.
|
||||
s2 = |{ s1 CASE = LOWER }|. "abcdefg
|
||||
s2 = |{ s1 CASE = UPPER }|. "ABCDEFG
|
||||
|
||||
"Width and alignment
|
||||
"WIDTH/ALIGN
|
||||
s1 = `##`.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = LEFT }<---|. "'## <---'
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
|
||||
@@ -306,8 +323,74 @@ s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
|
||||
"PAD: Used to pad any surplus places in the result with the specified character.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = RIGHT PAD = `.` }<---|. "'........##<---'
|
||||
|
||||
"Numbers
|
||||
"DECIMALS
|
||||
s1 = |{ CONV decfloat34( - 1 / 3 ) DECIMALS = 3 }|. "'-0.333'
|
||||
|
||||
"SIGN: Defining the format of the +/- sign when the string represented
|
||||
"by the embedded expression represents a numeric value
|
||||
"- left without space, no +
|
||||
s1 = |{ +1 SIGN = LEFT }|. "1
|
||||
"- and + left without space
|
||||
s1 = |{ 1 SIGN = LEFTPLUS }|. "+1
|
||||
"- left without space, blank left for +
|
||||
s1 = |{ 1 SIGN = LEFTSPACE }|. " 1
|
||||
"- right without space, no +
|
||||
s1 = |{ -1 SIGN = RIGHT }|. "1-
|
||||
"- and + right without space
|
||||
s1 = |{ 1 SIGN = RIGHTPLUS }|. "1+
|
||||
"- left without space, blank right for +
|
||||
s1 = |{ +1 SIGN = RIGHTSPACE }|. "1
|
||||
|
||||
"ZERO: Defining the format of the numeric value zero.
|
||||
"Only to be specified if the embedded expression has a numeric data type.
|
||||
s1 = |'{ 0 ZERO = NO }' and '{ 0 ZERO = YES }'|. "'' and '0'
|
||||
|
||||
"XSD: Formatting is applied to an embedded expression (elementary data types) in asXML format that is
|
||||
"assigned to its data type. Check the information in the ABAP Keyword Documentation about the asXML
|
||||
"mapping of elementary ABAP types.
|
||||
DATA xstr TYPE xstring VALUE `41424150`.
|
||||
DATA dat type d value '20240101'.
|
||||
DATA tim type t value '123456'.
|
||||
DATA(utc) = utclong_current( ). "e.g. 2024-01-01 13:51:38.5708800
|
||||
|
||||
s1 = |{ xstr XSD = YES }|. "QUJBUA==
|
||||
s1 = |{ dat XSD = YES }|. "2024-01-01
|
||||
s1 = |{ tim XSD = YES }|. "12:34:56
|
||||
s1 = |{ utc XSD = YES }|. "2024-01-01T13:51:38.57088Z
|
||||
|
||||
"STYLE: Defining the style of decimal floating point numbers;
|
||||
"see the details in the ABAP Keyword Documentation.
|
||||
DATA(dcfl34) = CONV decfloat34( '-123.45600' ).
|
||||
s1 = |{ dcfl34 }|. "-123.456out->write( s1 ).
|
||||
"Creates the predefined format
|
||||
s1 = |{ dcfl34 STYLE = SIMPLE }|. "-123.456
|
||||
"+/- added to the right, removes trailing zeros
|
||||
s1 = |{ dcfl34 STYLE = SIGN_AS_POSTFIX }|. "123.456-
|
||||
"Retains trailing zeros
|
||||
s1 = |{ dcfl34 STYLE = SCALE_PRESERVING }|. "-123.45600
|
||||
"Scientific notation; at least a two digit exponent with a plus/minus sign
|
||||
s1 = |{ dcfl34 STYLE = SCIENTIFIC }|. "-1.23456E+02
|
||||
"Scientific notation; only one integer digit with the value 0
|
||||
s1 = |{ dcfl34 STYLE = SCIENTIFIC_WITH_LEADING_ZERO }|. "-0.123456E+03
|
||||
"Scientific notation; exponent has 3 digits for decfloat16 and 4 digits for decfloat34
|
||||
s1 = |{ dcfl34 STYLE = SCALE_PRESERVING_SCIENTIFIC }|. "-1.2345600E+0002
|
||||
"Technical format
|
||||
s1 = |{ dcfl34 STYLE = ENGINEERING }|. "-123.456E+00
|
||||
|
||||
"ALPHA: Adds or removes leading zeros from strings of digits; the data type
|
||||
"must be string, c, or n
|
||||
"Adding leading zeros
|
||||
"Additionally specifying WIDTH
|
||||
"Note: The specified length is only used if it is greater than
|
||||
"the length of provided string (without leading zeros)
|
||||
s1 = |{ '1234' ALPHA = IN WIDTH = 10 }|. "0000001234
|
||||
s1 = |{ '00000000000000000000000012' ALPHA = IN WIDTH = 10 }|. "0000000012
|
||||
"Fixed-length string provided, WIDTH not specified
|
||||
s1 = |{ ' 12' ALPHA = IN }|. "00012
|
||||
"Removing leading zeros
|
||||
s1 = |{ '00001234' ALPHA = OUT }|. "1234
|
||||
"Do not apply formatting
|
||||
s1 = |{ '00001234' ALPHA = RAW }|. "00001234
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
|
||||
@@ -152,7 +152,7 @@ The following points cover RAP-related terms such as *RAP business objects* and
|
||||
- The [global
|
||||
class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm "Glossary Entry")
|
||||
of a behavior pool does not implement the behavior itself. It is
|
||||
basically empty. The behavior implementation is coded in local
|
||||
(initially) empty apart from the declaration and implementation part skeletons. The behavior implementation is coded in local
|
||||
[RAP handler
|
||||
classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_handler_class_glosry.htm "Glossary Entry")
|
||||
and a [RAP saver
|
||||
@@ -211,7 +211,7 @@ the handler methods that are called are part of an ABAP behavior pool.
|
||||
|
||||
The global class of an ABP has the addition [`FOR BEHAVIOR OF bdef`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass_for_behavior_of.htm)
|
||||
to the definition while `bdef` stands for the name of the BDEF.
|
||||
This class is usually empty.
|
||||
This class is (initially) empty apart from the declaration and implementation part skeleton.
|
||||
|
||||
```abap
|
||||
CLASS zbp_demo_abap_rap_draft_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_draft_m.
|
||||
@@ -221,7 +221,7 @@ CLASS zbp_demo_abap_rap_draft_m IMPLEMENTATION.
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
The actual implementation is done in local classes in the CCIMP include. There,
|
||||
The actual implementation is done in local classes in the CCIMP include (*Local Types* tab in ADT) of the behavior pool. There,
|
||||
two kinds of local classes are to be defined and implemented that are
|
||||
related to the RAP BO's runtime: one or more [handler
|
||||
classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_handler_class_glosry.htm "Glossary Entry")
|
||||
@@ -305,8 +305,8 @@ METHODS some_action FOR MODIFY
|
||||
the method names except for some predefined names.
|
||||
- Each handler method must have at least one importing parameter. The
|
||||
addition `IMPORTING` is optional since it is used
|
||||
implicitly. In most cases, the whole instance or just the key values
|
||||
of an instance are imported.
|
||||
implicitly. In most cases, entire instances or just key values
|
||||
of instances are imported.
|
||||
- All handler methods have changing parameters that are usually not
|
||||
explicitly specified in the definition but implicitly used. The
|
||||
explicit specification of the `CHANGING` addition is not needed. In most cases, these are
|
||||
@@ -459,50 +459,39 @@ Examples for BDEF derived types:
|
||||
"Data objects with input derived types (entity = name of a root entity)
|
||||
|
||||
"For an EML create operation
|
||||
|
||||
DATA create_tab TYPE TABLE FOR CREATE entity.
|
||||
|
||||
"For an update operation
|
||||
|
||||
DATA update_tab TYPE TABLE FOR UPDATE entity.
|
||||
|
||||
"Type for create-by-association operations specifying the name of the entity
|
||||
"and the association
|
||||
|
||||
DATA cba_tab TYPE TABLE FOR CREATE entity\_child.
|
||||
|
||||
"For an action execution; the name of the action is preceded by a tilde
|
||||
|
||||
DATA action_imp TYPE TABLE FOR ACTION IMPORT entity~action1.
|
||||
|
||||
"Data objects with output derived types
|
||||
|
||||
"For a read operation
|
||||
|
||||
DATA read_tab TYPE TABLE FOR READ RESULT entity.
|
||||
|
||||
"For an action defined with a result
|
||||
|
||||
DATA action_res TYPE TABLE FOR ACTION RESULT entity~action2.
|
||||
|
||||
"Examples for structures and types
|
||||
|
||||
DATA create_wa TYPE STRUCTURE FOR CREATE entity.
|
||||
|
||||
"For permission retrieval
|
||||
|
||||
DATA perm_req TYPE STRUCTURE FOR PERMISSIONS REQUEST entity.
|
||||
|
||||
"For retrieving global features
|
||||
|
||||
DATA feat_req TYPE STRUCTURE FOR GLOBAL FEATURES RESULT entity.
|
||||
|
||||
"Type declaration using a BDEF derived type
|
||||
|
||||
TYPES der_typ TYPE TABLE FOR DELETE entity.
|
||||
|
||||
"Response parameters
|
||||
|
||||
DATA map TYPE RESPONSE FOR MAPPED entity.
|
||||
DATA fail TYPE RESPONSE FOR FAILED entity.
|
||||
DATA rep TYPE RESPONSE FOR REPORTED entity.
|
||||
@@ -594,7 +583,7 @@ Bullet points on selected `%` components:
|
||||
- [`%control`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_control.htm)
|
||||
- Component group that, in certain contexts and for example (it depends on the context what it contains), contains the names of all key
|
||||
and data fields of a RAP BO instance which indicate flags.
|
||||
- Used to get information on which fields are provided or set a
|
||||
- The use depends on the context. For example, it is used to get information on which fields are provided or set a
|
||||
flag for which fields are requested by RAP BO providers or RAP
|
||||
BO consumers respectively during the current EML request.
|
||||
- For this purpose, the value of each field in the
|
||||
@@ -1345,7 +1334,7 @@ The following restrictions apply to operations and/or statements in the individu
|
||||
|[bgRFC](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbgrfc_glosry.htm) (`CALL FUNCTION ... IN BACKGROUND UNIT`) <br><br>(unrestricted ABAP language scope)| -| -| X| |
|
||||
|[tRFC](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentrfc_2_glosry.htm), [qRFC](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenqrfc_glosry.htm) (`CALL FUNCTION ... IN BACKGROUND TASK`) <br><br>(unrestricted ABAP language scope)| -| -| - |Obsolete technologies. |
|
||||
|`PERFORM ON COMMIT`, `PERFORM ON ROLLBACK` <br><br>(unrestricted ABAP language scope)|(X) |(X) |X |Basically possible in all phases, but should be reserved for the late save. Note: The use of these statements indicates improper integration with RAP. It is especially important to check draft scenarios when calling legacy code and using these statements. Instead, ABAP EML or procedure calls that do not include a `COMMIT WORK` should be used. |
|
||||
|Transaction control `COMMIT WORK`, `ROLLBACK WORK` |X/-| X/-| X/- |When a transactional phase has been explicitly set by methods of the `CL_ABAP_TX` class, the transaction owner is allowed to execute a commit or rollback statement. In the contexts of RAP (that is, where RAP is the transaction owner, for example, in handler and saver methods), local consumption of [RAP business events](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_entity_event_glosry.htm), [bgPF](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbgpf_glosry.htm), and [classified APIs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassified_api_glosry.htm), commit or rollback statements are not allowed. |
|
||||
|Transaction control `COMMIT WORK`, `ROLLBACK WORK` |X/-| X/-| X/- |When a transactional phase has been explicitly set by methods of the `CL_ABAP_TX` class (find more information [here](https://help.sap.com/docs/abap-cloud/abap-concepts/controlled-sap-luw)), the transaction owner is allowed to execute a commit or rollback statement. In the contexts of RAP (that is, where RAP is the transaction owner, for example, in handler and saver methods), local consumption of [RAP business events](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_entity_event_glosry.htm), [bgPF](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbgpf_glosry.htm), and [classified APIs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassified_api_glosry.htm), commit or rollback statements are not allowed. |
|
||||
|[Dynpro](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_glosry.htm) processing (e.g. `SET SCREEN`, `CALL SCREEN`, `LEAVE SCREEN`, `CALL DIALOG`, `SUPPRESS DIALOG`, `MESSAGE` without `INTO`, `WRITE`, `STOP`) <br><br>(unrestricted ABAP language scope)|- |- |- |Not allowed in ABAP behavior implementations. Results in a runtime error. |
|
||||
|Transaction processing (`CALL TRANSACTION`, `LEAVE TRANSACTION`) <br><br>(unrestricted ABAP language scope)| -| -| - |Not allowed to prevent (unwanted) integration of other LUWs. |
|
||||
|Raising an exception (`RAISE EXCEPTION`) |-| -| - |It is not allowed to leave a RAP transaction this way. |
|
||||
@@ -1368,8 +1357,6 @@ The following restrictions apply to operations and/or statements in the individu
|
||||
Contract](https://help.sap.com/docs/ABAP_PLATFORM_NEW/fc4c71aa50014fd1b43721701471913d/3a402c5cf6a74bc1a1de080b2a7c6978.html):
|
||||
Rules for the RAP BO provider and consumer implementation to ensure
|
||||
consistency and reliability
|
||||
- Find more information about the `CL_ABAP_TX` class mentioned above in the SAP Help Portal documentation: [Controlled SAP LUW](https://help.sap.com/docs/abap-cloud/abap-concepts/controlled-sap-luw).
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
@@ -390,8 +390,8 @@ AMDP methods ...
|
||||
- must include the addition <code>OPTIONS READ-ONLY</code> in the
|
||||
declaration part.
|
||||
- must be implemented in SQLScript in any case.
|
||||
- cannot use the additions [`USING SCHEMA` (F1 for docu standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_5@5@)
|
||||
and [`SUPPRESS SYNTAX ERRORS` (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_3@3@)
|
||||
- cannot use the additions [`USING SCHEMA` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_5@5@)
|
||||
and [`SUPPRESS SYNTAX ERRORS` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_3@3@)
|
||||
in the method implementation part
|
||||
- cannot use [AMDP
|
||||
macros](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_macros.htm)
|
||||
@@ -399,7 +399,7 @@ AMDP methods ...
|
||||
- can only use your own entities and entities that are released for
|
||||
the restricted language version after <code>USING</code>.
|
||||
- cannot use
|
||||
[`CONNECTION` (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenamdp_db_connections.htm)
|
||||
[`CONNECTION` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenamdp_db_connections.htm)
|
||||
parameters.
|
||||
- cannot raise the
|
||||
`CX_AMDP_CONNECTION_ERROR` exception since
|
||||
|
||||
@@ -291,7 +291,7 @@ ENDIF.
|
||||
> - Control structures can be nested. It is recommended that you do not include more than 5 nested control structures since the code will
|
||||
> get really hard to understand. Better go for outsourcing functionality into methods to reduce nested control control structures.
|
||||
> - Keep the number of consecutive control structures low.
|
||||
> - If you are convinced that a specified logical expression must always be true, you might include a statement like `ASSERT 1 = 0` to go
|
||||
> - If you are convinced that a specified logical expression must always be true, you might include a statement like `ASSERT 1 = 0.` to go
|
||||
> sure - as implied in the example's `ELSE` statement above. However, an `ELSE` statement that is never executed might be a hint that
|
||||
> logical expressions might partly be redundant.
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ ENDCLASS.
|
||||
> - `SHORT`: execution time of only a few seconds is expected
|
||||
> - `MEDIUM`: execution time of about one minute is expected
|
||||
> - `LONG`: execution time of more than one minute is expected
|
||||
> - To create a class in ADT, type "test" in the "Test Classes" tab and choose `CTRL` and `SPACE` to display the templates suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
> - To create a class in ADT, type "test" in the "Test Classes" tab and choose `CTRL + SPACE` to display the templates suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
|
||||
To test protected or private methods, you must declare [friendship](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm) with the class to be tested (class under test).
|
||||
Example:
|
||||
@@ -225,7 +225,7 @@ ENDCLASS.
|
||||
- *given*: Preparing the test, e.g. creating an instance of the class under test and a local test double (to inject the test double into the class under test)
|
||||
- *when*: Calling the procedure to be tested
|
||||
- *then*: Checking and evaluating the test result using the static methods of the `CL_ABAP_UNIT_ASSERT` class
|
||||
- A selection of static methods of the class `CL_ABAP_UNIT_ASSERT` that can be used for the checks:
|
||||
- The following points cover a selection of static methods of the class `CL_ABAP_UNIT_ASSERT` that can be used for the checks:
|
||||
- `ASSERT_EQUALS`: Checks whether two data objects are the same.
|
||||
- `ASSERT_BOUND`: Checks whether a reference variable is bound.
|
||||
- `ASSERT_NOT_BOUND`: Negation of the one above.
|
||||
@@ -336,7 +336,7 @@ CLASS ltc_test_class DEFINITION
|
||||
DURATION SHORT.
|
||||
|
||||
PRIVATE SECTION.
|
||||
DATA: ref_cut TYPE REF TO cl_class_under_test.
|
||||
DATA ref_cut TYPE REF TO cl_class_under_test.
|
||||
|
||||
METHODS:
|
||||
"special methods
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
- [Complex Data Types](#complex-data-types)
|
||||
- [Reference Types](#reference-types)
|
||||
- [Declaring Data Types](#declaring-data-types)
|
||||
- [Generic Types](#generic-types)
|
||||
- [Data Objects](#data-objects)
|
||||
- [Declaring Data Objects](#declaring-data-objects)
|
||||
- [Assigning Values to Data Objects](#assigning-values-to-data-objects)
|
||||
@@ -113,7 +114,7 @@ For an overview, see the [ABAP Type Hierarchy](https://help.sap.com/doc/abapdocu
|
||||
- The typical syntax element is `... REF TO ...`.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> There are [generic ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_abap_type_glosry.htm). Generic data types are types that do not define all of the properties of a data object. They can only be used for the typing of [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) and [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm).
|
||||
> There are [generic ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_abap_type_glosry.htm). Generic data types are types that do not define all of the properties of a data object. They can only be used for the typing of [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) and [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm). See an example further down.
|
||||
The only generic types that can be used after `TYPE REF TO` are `data` for the generic typing of data references, and `object`, for the generic typing of object references.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
@@ -303,6 +304,170 @@ TYPES tr_like_table_ref LIKE TABLE OF REF TO itab_str.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Generic Types
|
||||
|
||||
- Generic types are available with which [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) of methods or [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm) can be specified.
|
||||
- At runtime, the actual data type is copied from the assigned [actual parameter](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenactual_parameter_glosry.htm) or
|
||||
memory area, i.e. they receive the complete data type only when an actual parameter
|
||||
is passed or a memory area is assigned.
|
||||
- More information:
|
||||
- [Generic ABAP Types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuilt_in_types_generic.htm)
|
||||
- [ABAP cheat sheet about dynamic programming](06_Dynamic_Programming.md) regarding field symbols and `ASSIGN` statements
|
||||
|
||||
The following code snippet demonstrates generic types with field symbols.
|
||||
|
||||
```abap
|
||||
FIELD-SYMBOLS:
|
||||
"Any data type
|
||||
<data> TYPE data,
|
||||
<any> TYPE any,
|
||||
"Any data type can be assigned. Restrictions for formal parameters and 'data': no
|
||||
"numeric functions, no description functions, and no arithmetic expressions can be
|
||||
"passed to these parameters. However, you can bypass the restriction by applying the
|
||||
"CONV operator for the actual parameter.
|
||||
|
||||
"Character-like types
|
||||
<c> TYPE c, "Text field with a generic length
|
||||
<clike> TYPE clike, "Character-like (c, n, string, d, t and character-like flat structures)
|
||||
<csequence> TYPE csequence, "Text-like (c, string)
|
||||
<n> TYPE n, "Numeric text with generic length
|
||||
<x> TYPE x, "Byte field with generic length
|
||||
<xsequence> TYPE xsequence, "Byte-like (x, xstring)
|
||||
|
||||
"Numeric types
|
||||
<decfloat> TYPE decfloat, "decfloat16, decfloat34)
|
||||
<numeric> TYPE numeric, "Numeric ((b, s), i, int8, p, decfloat16, decfloat34, f)
|
||||
<p> TYPE p, "Packed number (generic length and number of decimal places)
|
||||
|
||||
"Internal table types
|
||||
<any_table> TYPE ANY TABLE, "Internal table with any table type
|
||||
<hashed_table> TYPE HASHED TABLE,
|
||||
<index_table> TYPE INDEX TABLE,
|
||||
<sorted_table> TYPE SORTED TABLE,
|
||||
<standard_table> TYPE STANDARD TABLE,
|
||||
<table> TYPE table, "Standard table
|
||||
|
||||
"Other types
|
||||
<simple> TYPE simple, "Elementary data type including enumerated types and
|
||||
"structured types with exclusively character-like flat components
|
||||
<object> TYPE REF TO object. "object can only be specified after REF TO; can point to any object
|
||||
|
||||
"Data objects to work with
|
||||
DATA: BEGIN OF s,
|
||||
c3 TYPE c LENGTH 3,
|
||||
c10 TYPE c LENGTH 10,
|
||||
n4 TYPE n LENGTH 4,
|
||||
str TYPE string,
|
||||
time TYPE t,
|
||||
date TYPE d,
|
||||
dec16 TYPE decfloat16,
|
||||
dec34 TYPE decfloat34,
|
||||
int TYPE i,
|
||||
pl4d2 TYPE p LENGTH 4 DECIMALS 2,
|
||||
tab_std TYPE STANDARD TABLE OF string WITH EMPTY KEY,
|
||||
tab_so TYPE SORTED TABLE OF string WITH NON-UNIQUE KEY table_line,
|
||||
tab_ha TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line,
|
||||
xl1 TYPE x LENGTH 1,
|
||||
xstr TYPE xstring,
|
||||
structure TYPE zdemo_abap_carr, "character-like flat structure
|
||||
oref TYPE REF TO object,
|
||||
END OF s.
|
||||
|
||||
"The following static ASSIGN statements demonstrate various assignments
|
||||
"Note:
|
||||
"- The statements commented out show impossible assignments.
|
||||
"- If a static assignment is not successful, sy-subrc is not set and no
|
||||
" memory area is assigned. Dynamic assignments, however, set the value.
|
||||
|
||||
"----- Any data type -----
|
||||
ASSIGN s-c3 TO <data>.
|
||||
ASSIGN s-time TO <data>.
|
||||
ASSIGN s-tab_std TO <data>.
|
||||
ASSIGN s-xstr TO <any>.
|
||||
ASSIGN s-pl4d2 TO <any>.
|
||||
ASSIGN s-date TO <any>.
|
||||
|
||||
"----- Character-like types -----
|
||||
ASSIGN s-c3 TO <c>.
|
||||
ASSIGN s-c10 TO <c>.
|
||||
"ASSIGN s-str TO <c>.
|
||||
|
||||
ASSIGN s-c10 TO <clike>.
|
||||
ASSIGN s-str TO <clike>.
|
||||
ASSIGN s-n4 TO <clike>.
|
||||
ASSIGN s-date TO <clike>.
|
||||
ASSIGN s-time TO <clike>.
|
||||
ASSIGN s-structure TO <clike>.
|
||||
|
||||
ASSIGN s-c10 TO <csequence>.
|
||||
ASSIGN s-str TO <csequence>.
|
||||
"ASSIGN s-n4 TO <csequence>.
|
||||
|
||||
ASSIGN s-n4 TO <n>.
|
||||
"ASSIGN s-int TO <n>.
|
||||
"ASSIGN s-time TO <n>.
|
||||
|
||||
ASSIGN s-xl1 TO <x>.
|
||||
"ASSIGN s-xstr TO <x>.
|
||||
|
||||
ASSIGN s-xl1 TO <xsequence>.
|
||||
ASSIGN s-xstr TO <xsequence>.
|
||||
|
||||
"----- Numeric types -----
|
||||
ASSIGN s-dec16 TO <numeric>.
|
||||
ASSIGN s-dec34 TO <numeric>.
|
||||
ASSIGN s-int TO <numeric>.
|
||||
ASSIGN s-pl4d2 TO <numeric>.
|
||||
"ASSIGN s-n4 TO <numeric>.
|
||||
|
||||
ASSIGN s-dec16 TO <decfloat>.
|
||||
ASSIGN s-dec34 TO <decfloat>.
|
||||
|
||||
ASSIGN s-pl4d2 TO <p>.
|
||||
"ASSIGN s-dec34 TO <p>.
|
||||
|
||||
"----- Internal table types -----
|
||||
ASSIGN s-tab_std TO <any_table>.
|
||||
ASSIGN s-tab_so TO <any_table>.
|
||||
ASSIGN s-tab_ha TO <any_table>.
|
||||
|
||||
ASSIGN s-tab_std TO <index_table>.
|
||||
ASSIGN s-tab_so TO <index_table>.
|
||||
"ASSIGN s-tab_ha TO <index_table>.
|
||||
|
||||
"ASSIGN s-tab_std TO <sorted_table>.
|
||||
ASSIGN s-tab_so TO <sorted_table>.
|
||||
"ASSIGN s-tab_ha TO <sorted_table>.
|
||||
|
||||
ASSIGN s-tab_std TO <standard_table>.
|
||||
ASSIGN s-tab_std TO <table>.
|
||||
"ASSIGN s-tab_so TO <standard_table>.
|
||||
"ASSIGN s-tab_so TO <table>.
|
||||
"ASSIGN s-tab_ha TO <standard_table>.
|
||||
"ASSIGN s-tab_ha TO <table>.
|
||||
|
||||
"ASSIGN s-tab_std TO <hashed_table>.
|
||||
"ASSIGN s-tab_so TO <hashed_table>.
|
||||
ASSIGN s-tab_ha TO <hashed_table>.
|
||||
|
||||
"----- Other types -----
|
||||
ASSIGN s-c10 TO <simple>.
|
||||
ASSIGN s-str TO <simple>.
|
||||
ASSIGN s-dec34 TO <simple>.
|
||||
ASSIGN s-date TO <simple>.
|
||||
ASSIGN s-structure TO <simple>.
|
||||
ASSIGN s-xl1 TO <simple>.
|
||||
"ASSIGN s-tab_ha TO <simple>.
|
||||
|
||||
ASSIGN s-oref TO <object>.
|
||||
s-oref = NEW zcl_demo_abap_objects( ).
|
||||
ASSIGN s-oref TO <object>.
|
||||
s-oref = cl_abap_random_int=>create( ).
|
||||
ASSIGN s-oref TO <object>.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Data Objects
|
||||
|
||||
### Declaring Data Objects
|
||||
@@ -583,7 +748,7 @@ An [inline declaration](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-
|
||||
> - In an assignment, if the data object is declared inline on the left side, there are many options for what can be placed on the right side as shown in the previous section. The data type of the variable is determined by the operand type. It must be possible to derive this type completely statically.
|
||||
> - For more information about the possible declaration positions, see [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeclaration_positions.htm).
|
||||
> - You can use the [`FINAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm) declaration operator to create [immutable variables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenimmutable_variable_glosry.htm), as shown below.
|
||||
> - [Programming guidelines for inline declarations (F1 for Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendeclaration_inline_guidl.htm)
|
||||
> - [Programming guidelines for inline declarations (F1 documentation for Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendeclaration_inline_guidl.htm)
|
||||
|
||||
|
||||
```abap
|
||||
|
||||
@@ -364,11 +364,11 @@ If the program is not terminated immediately and the SAP LUW has ended, another
|
||||
The log shows the value 1 for the transaction state after the update task is executed and the update function modules are called.
|
||||
- **Synchronous update** with `COMMIT WORK AND WAIT`: Immediately after the `COMMIT WORK AND WAIT` statement, a `SELECT` statement is executed to retrieve all the entries in the database table. In this case, there should be one entry instead of four to demonstrate the synchronous update. The current number of records is displayed in a message.
|
||||
- **Local update** using a `SET UPDATE TASK LOCAL` statement: Once the local update is enabled, it does not matter whether you choose `COMMIT WORK` or `COMMIT WORK AND WAIT` in the next step. It will be a synchronous update, so the number of current database table entries displayed in the message will be 1 in both cases. The log will show the value 1 for the transaction state after the `SET UPDATE TASK LOCAL` statement has been executed.
|
||||
- **Rolling back changes**: Although update function modules and subroutines are registered, none of them affect the database. All changes are rolled back. Result: The database table is not deleted, no new entry is created. The original content of the database table should be displayed.
|
||||
- **Rolling back changes**: Although update function modules or subroutines are registered, none of them affect the database. All changes are rolled back. Result: The database table is not deleted, no new entry is created. The original content of the database table should be displayed.
|
||||
- **Causing a failure in the current SAP LUW**: An update function module intentionally includes a statement that causes a runtime error if not caught (zero division). All changes are rolled back implicitly. If the local update is active, you should be informed of the problem directly. The program is terminated. In this case, you can check the database table entries that remain unchanged. You can also use transaction ST22 to display the runtime error that occurred. In the case of a non-local update, you should receive a mail in the Business Workplace informing you of the problem in the SAP LUW. The original content of the database table should be displayed on the next screen. In this case, you can also check transaction ST22 for the runtime error.
|
||||
- **Terminating the program with an error message** of type A: This option only indicates that if such a message is generated, the program is terminated and all changes are implicitly rolled back. In this case, you may want to check the database table entries that remain unchanged.
|
||||
- **Using subroutines**:
|
||||
- Note that subroutines are considered obsolete and should no longer be used. This is to demonstrate the effect as a bundling technique in an SAP LUW. Selecting this option triggers the registration of subroutines for commit (to delete the database table entry, insert a newly created entry, insert entries in the log table) and rollback (this subroutine does nothing specific; it is just to demonstrate that the subroutine is called in the event of a rollback).
|
||||
- Note that subroutines are considered obsolete and should no longer be used. This is to demonstrate the effect as a bundling technique in an SAP LUW. Selecting this option triggers the registration of subroutines for commit (to delete the database table entry, insert a newly created entry, insert entries in the log table) and rollback (the subroutine in the example does not do anything specific; it is just to demonstrate that the subroutine is called in the event of a rollback).
|
||||
- When you select the commit options, the subroutines registered with `ON COMMIT` are executed in the current work process.
|
||||
- Choosing `COMMIT WORK` or `COMMIT WORK AND WAIT` has the same effect: When these statements are called and a `SELECT` statement follows, the number of database table entries is 1 in both cases.
|
||||
- If the rollback option is selected, the subroutine registered with `ON ROLLBACK` is executed in the current work process.
|
||||
|
||||
@@ -27,6 +27,7 @@ This cheat sheet provides a high-level overview of working with XML and JSON in
|
||||
> **💡 Note**<br>
|
||||
> - The cheat sheet snippets and the executable example cover simple cases. Find more executable examples of the ABAP Keyword Documentation following the links in the [More Information](#more-information) section.
|
||||
> - For more detailed information, such as documentation on ST syntax, what asXML is, etc., also see the links in the [More Information](#more-information) section.
|
||||
> - In addition to the options covered in the cheat sheet, there are other ways to work with XML/JSON (for example, the `/ui2/cl_json` class).
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
@@ -42,7 +43,7 @@ This cheat sheet provides a high-level overview of working with XML and JSON in
|
||||
- Advantages: Easy access to the individual parts of an XML document possible, DTDs (Document Type Definitions) are possible
|
||||
- Disadvantages: High memory consumption of the DOM (if the complete DOM is created)
|
||||
|
||||
The following code snippets demonstrate a selection of iXML methods for handling XML data.
|
||||
The following code snippets demonstrate a selection of iXML methods for handling XML data. Note that the snippets use classes available for [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm). Find documentation on the classes for [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm) [here (F1 documentation for Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_ixml_lib.htm).
|
||||
|
||||
Creating XML data using iXML:
|
||||
|
||||
@@ -449,7 +450,7 @@ ENDTRY.
|
||||
|
||||
**Specifying the source of the transformation**
|
||||
|
||||
There are multiple options. Check the executable example to see them in action.
|
||||
There are multiple options. Check the executable example to explore them.
|
||||
|
||||
```abap
|
||||
"**************** Transforming XML data ****************
|
||||
@@ -664,7 +665,7 @@ DATA(conv_string) = cl_abap_conv_codepage=>create_in( )->convert( conv_xstring )
|
||||
"conv_string: <TXT>ABAP</TXT>
|
||||
|
||||
"As an alternative, you can use methods of the XCO library. More methods are available
|
||||
"in this context. Check the CTRL + Space after '->'
|
||||
"in this context. Check the options when choosing CTRL + Space after '->'
|
||||
"string -> xstring
|
||||
DATA(conv_xstring_xco) = xco_cp=>string( xml_string
|
||||
)->as_xstring( xco_cp_character=>code_page->utf_8
|
||||
@@ -728,7 +729,6 @@ DATA(is_equal) = COND #( WHEN len_xstr = len_xstr_decomp
|
||||
- [`CALL TRANSFORMATION`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcall_transformation.htm)
|
||||
- [`CALL TRANSFORMATION` Examples](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencall_transformation_abexas.htm)
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Executable Example
|
||||
|
||||
@@ -30,7 +30,7 @@ ABAP cheat sheets[^1] ...
|
||||
- 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](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_btp_abap_env_glosry.htm) (*main* branch) or on-premise ABAP system ([classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm); the repository branches other than *main*) using [abapGit](https://abapgit.org/) 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.
|
||||
- are enriched by links to glossary entries and chapters of the **ABAP Keyword Documentation** (the *F1 help*) and more for you to deep dive into the respective ABAP topics and get more comprehensive information.
|
||||
|
||||
<details>
|
||||
<summary>💡 Note</summary>
|
||||
@@ -64,7 +64,7 @@ ABAP cheat sheets[^1] ...
|
||||
|[Internal Tables](01_Internal_Tables.md)| Creating, filling, reading from, sorting, modifying internal tables | [zcl_demo_abap_internal_tables](./src/zcl_demo_abap_internal_tables.clas.abap) |
|
||||
|[Structures](02_Structures.md)| Some basics when working with structures | [zcl_demo_abap_structures](./src/zcl_demo_abap_structures.clas.abap) |
|
||||
|[ABAP SQL](03_ABAP_SQL.md)| Reading from database tables using `SELECT`, changing data in database tables using `INSERT`, `UPDATE`, `MODIFY` and `DELETE` | [zcl_demo_abap_sql](./src/zcl_demo_abap_sql.clas.abap) |
|
||||
|[ABAP Object Orientation](04_ABAP_Object_Orientation.md)| Working with objects and components, concepts like inheritance, interfaces, and more | [zcl_demo_abap_objects](./src/zcl_demo_abap_objects.clas.abap) |
|
||||
|[ABAP Object Orientation](04_ABAP_Object_Orientation.md)| Working with objects and components, concepts such as inheritance, interfaces, and more | [zcl_demo_abap_objects](./src/zcl_demo_abap_objects.clas.abap) |
|
||||
|[Constructor Expressions](05_Constructor_Expressions.md)| Covers constructor expressions with operators such as `VALUE`, `CORRESPONDING`, `NEW`, `CONV`, `EXACT`, `REF`, `CAST`, `COND`, `SWITCH`, `FILTER`, `REDUCE`, iteration expressions with `FOR`, `LET` expressions | [zcl_demo_abap_constructor_expr](./src/zcl_demo_abap_constructor_expr.clas.abap) |
|
||||
|[Dynamic Programming](06_Dynamic_Programming.md)| Covers 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](./src/zcl_demo_abap_dynamic_prog.clas.abap) |
|
||||
|[String Processing](07_String_Processing.md)| Creating strings and assigning values, chaining strings, string templates, concatenating, splitting, modifying strings, searching and replacing, regular expressions | [zcl_demo_abap_string_proc](./src/zcl_demo_abap_string_proc.clas.abap) |
|
||||
@@ -206,7 +206,7 @@ Use the standalone version of the abapGit report to import the demo examples of
|
||||
## ⚡ Known Issues
|
||||
- Only one user on the system can import this repository because all object names must be globally unique. Before importing the code, you should perform a system-wide search for classes named *ZCL_DEMO_ABAP**, for example. If someone has already imported the content into the system, you can simply check out that imported code.
|
||||
- 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](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpragma_glosry.htm) and [pseudo comments](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpseudo_comment_glosry.htm) in order to focus on the available ABAP syntax. See also the [Disclaimer](#%EF%B8%8F-disclaimer).
|
||||
- Regarding the examples to be imported into on-premise ABAP systems, note the following: The cheat sheet documents cover ABAP syntax regardless of the ABAP release to avoid scattering information and to have the information in one place. Therefore, the lower the release, the fewer syntax options and examples are available. For example, the RAP examples in particular require at least ABAP version 7.56.
|
||||
- Regarding the examples to be imported into on-premise ABAP systems, note the following: The cheat sheet documents cover ABAP syntax regardless of the ABAP release to avoid scattering information and to have the information in one place. Therefore, the lower the release, the fewer syntax options and examples are available. For example, the RAP examples in particular require at least ABAP version 7.56. The code examples in the classic ABAP branches do not necessarily reflect all (described) syntax variations and options that are available in classic ABAP and in the particular ABAP release.
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user