From 0bf7327a171fba5f4d4849bfd68e60cdb1e174a2 Mon Sep 17 00:00:00 2001
From: danrega <16720986+danrega@users.noreply.github.com>
Date: Tue, 16 Jul 2024 16:23:54 +0200
Subject: [PATCH] Update
---
01_Internal_Tables.md | 2 +-
06_Dynamic_Programming.md | 10 ++--
07_String_Processing.md | 94 ++++++++++++++++++++------------
19_ABAP_for_Cloud_Development.md | 29 +++++++---
21_XML_JSON.md | 65 ++++++++++++++++------
22_Misc_ABAP_Classes.md | 11 ++++
README.md | 2 +-
7 files changed, 146 insertions(+), 67 deletions(-)
diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md
index e2d0b3a..782e802 100644
--- a/01_Internal_Tables.md
+++ b/01_Internal_Tables.md
@@ -1630,7 +1630,7 @@ READ TABLE it_so REFERENCE INTO DATA(dref) INDEX 2.
"Modification via dereferencing
-ref->b = 4.
+dref->b = 4.
"Table expressions
diff --git a/06_Dynamic_Programming.md b/06_Dynamic_Programming.md
index 1c8a7e2..599645b 100644
--- a/06_Dynamic_Programming.md
+++ b/06_Dynamic_Programming.md
@@ -33,8 +33,8 @@
- [Example: Exploring the RTTI Type Hierarchy](#example-exploring-the-rtti-type-hierarchy)
- [Excursion: Inline Declaration, CAST Operator, Method Chaining](#excursion-inline-declaration-cast-operator-method-chaining)
- [Absolute Names](#absolute-names)
- - [Dynamically Creating Data Types at Runtime](#dynamically-creating-data-types-at-runtime)
- - [Dynamically Creating Data Objects at Runtime](#dynamically-creating-data-objects-at-runtime)
+ - [Dynamically Creating Data Types at Runtime (Type Description Objects)](#dynamically-creating-data-types-at-runtime-type-description-objects)
+ - [Dynamically Creating Data Objects at Runtime Using Type Description Objects](#dynamically-creating-data-objects-at-runtime-using-type-description-objects)
- [More Information](#more-information)
- [Executable Example](#executable-example)
@@ -3195,9 +3195,9 @@ ENDTRY.
⬆️ back to top
-### Dynamically Creating Data Types at Runtime
+### Dynamically Creating Data Types at Runtime (Type Description Objects)
You can create data types at program runtime using methods of the type description classes of RTTS.
-These types are only valid locally in the program. They are also anonymous, i.e. they are only accessible through type description objects.
+These types are only valid locally in the program. They are also anonymous, i.e. they are only accessible through [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm).
As shown above, you can get a reference to a type description object of a type using the static methods of the class `CL_ABAP_TYPEDESCR`. You can use type description objects such as `type_descr_obj` of the example to create data objects dynamically with `CREATE DATA` statements and the `TYPE HANDLE` addition as shown further down.
```abap
"For example, a structured type
@@ -3315,7 +3315,7 @@ DATA(tdo_ref_4) = cl_abap_refdescr=>get_by_name( 'ZCL_DEMO_ABAP_DYNAMIC_PROG' ).
⬆️ back to top
-### Dynamically Creating Data Objects at Runtime
+### Dynamically Creating Data Objects at Runtime Using Type Description Objects
As shown above, anonymous data objects can be dynamically created using `CREATE DATA` statements in many ways by specifying the type ...
- statically: `CREATE DATA dref TYPE string.`
diff --git a/07_String_Processing.md b/07_String_Processing.md
index 7b55162..a9bf989 100644
--- a/07_String_Processing.md
+++ b/07_String_Processing.md
@@ -5,9 +5,12 @@
- [String Processing](#string-processing)
- [Introduction](#introduction)
- [Data Types for Character Strings](#data-types-for-character-strings)
+ - [Differences Between Text Strings (Variable Length) and Text Fields (Fixed Length)](#differences-between-text-strings-variable-length-and-text-fields-fixed-length)
- [Declaring Character-Like Data Objects](#declaring-character-like-data-objects)
- [Assigning Values](#assigning-values)
- [String Templates](#string-templates)
+ - [Control Characters in String Templates](#control-characters-in-string-templates)
+ - [Formatting Options in String Templates](#formatting-options-in-string-templates)
- [Determining the Length of Strings](#determining-the-length-of-strings)
- [Concatenating Strings](#concatenating-strings)
- [Splitting Strings](#splitting-strings)
@@ -86,16 +89,16 @@ In addition to these main data types for character strings, there are several ot
These data types are not covered further in this cheat sheet. The same is true for the [byte-like data types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbyte_like_data_typ_glosry.htm "Glossary Entry") `x` and `xstring` that are closely related to `c` and `string` but contain raw [byte strings](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbyte_string_glosry.htm).
-> **⚡ Differences between text strings (variable length) and text fields (fixed length)**
->- **Initial value**: The initial value of a text string is an
+### Differences Between Text Strings (Variable Length) and Text Fields (Fixed Length)
+- **Initial value**: The initial value of a text string is an
empty string of length 0. The initial value of text field is represented by blanks at each position.
->- **Internal representation**: Data objects of type `c` and `string` are both [elementary data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_object_glosry.htm "Glossary Entry").
+- **Internal representation**: Data objects of type `c` and `string` are both [elementary data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_object_glosry.htm "Glossary Entry").
However, while text fields occupy a block of memory according to their length, text strings are so-called [deep](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeep_glosry.htm "Glossary Entry") data objects. Internally, they are managed by a [reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm "Glossary Entry") that points to the actual character. This fact has restrictive consequences for the use of strings as components of structures, but can also improve the performance of assignments due to the concept of [sharing](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensharing_glosry.htm "Glossary Entry") of deep data objects.
->- **Length**: Theoretically, a text string can use up to 2 GB (one character occupies 2 bytes).
+- **Length**: Theoretically, a text string can use up to 2 GB (one character occupies 2 bytes).
The maximum length of a text field is 262143 characters.
->- **Trailing blanks**: For text strings, trailing blanks are preserved in all operations. For text fields, it depends on the [operand
+- **Trailing blanks**: For text strings, trailing blanks are preserved in all operations. For text fields, it depends on the [operand
position](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_position_glosry.htm "Glossary Entry") whether trailing blanks are respected or not. In most operand positions, trailing blanks are truncated when working with text fields, even when using [text field literals](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentext_field_literal_glosry.htm). For example, if a text field is assigned to a text string, the resulting target string will never contain trailing blanks. See the *Condensing Strings* section in this context.
->- **Flexibility**: Text strings are more flexible than text fields
+- **Flexibility**: Text strings are more flexible than text fields
because you can easily shorten or lengthen them without
worrying that, for example, parts of the character string will be
truncated during processing. On the other hand, when accessing substrings of a string, you have to make sure that the string is long enough, whereas with text fields you always know their length.
@@ -266,6 +269,7 @@ expression](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm
that is compiled at runtime. Therefore, a string template that contains only
literal text is treated as an expression, which has a performance impact. In such a case, it is preferable to use a text string literal with backquotes.
> - It is possible to dynamically specify formatting options. For more information, refer to the [Dynamic Formatting Option Specifications in String Templates](/06_Dynamic_Programming.md#dynamic-formatting-option-specifications-in-string-templates) section of the *Dynamic Programming* cheat sheet.
+> - Escape `\|{}` in string templates using `\`, i. e. `\\` means `\`.
Syntax examples:
``` abap
@@ -306,45 +310,62 @@ DATA(s10) = |Current UTC time stamp: { utclong_current( ) }|.
"HALLO!
DATA(s11) = |{ to_upper( s5 ) }|.
+
+"\ | { }
+DATA(s12) = |\\ \| \{ \}|.
```
+### Control Characters in String Templates
- String templates interpret certain character combinations as [control
characters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstring_templates_separators.htm).
- For example, `\n` is interpreted as a newline. A new line is
started.
-- String templates also support various [formatting
-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.
The following syntax examples demonstrate a selection:
```abap
-"Control characters
-s4 = |{ s1 }\n{ s2 }\nSee you.|. "\n is interpreted as a line feed
+"\n is interpreted as a line feed
+DATA(s1) = `Hello`.
+DATA(s2) = `World`.
+DATA(s3) = |{ s1 }\n{ s2 }\nHow are you\n?|.
-"Excursion: Class CL_ABAP_CHAR_UTILITIES provides attributes and methods as utilities for string processing.
-"See the class documentation
+*Hello
+*World
+*How are you
+*?
+
+"Excursion: The CL_ABAP_CHAR_UTILITIES class provides attributes and methods as utilities for string processing.
"The following examples demonstrate that attributes that contain control characters can be replaced by
"a representation of control characters in a string template.
ASSERT cl_abap_char_utilities=>newline = |\n|.
ASSERT cl_abap_char_utilities=>horizontal_tab = |\t|.
ASSERT cl_abap_char_utilities=>cr_lf = |\r\n|.
+```
-"Various formatting options
-"DATE: Defining the format of a date
+⬆️ back to top
+
+### Formatting Options in String Templates
+- String templates support various formatting options.
+- The following syntax examples demonstrate a selection. For information about all options, refer to [this topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcompute_string_format_options.htm) in the ABAP Keyword Documentation.
+
+```abap
+"---------------------- 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
-"TIME: Defining the format of a time
+"---------------------- 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
-"TIMESTAMP: Defining the format of a time stamp
+"---------------------- 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
@@ -352,28 +373,32 @@ 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
-"TIMEZONE: Defining the format of a time stamp using the rules for time zones
+"---------------------- 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
+"---------------------- CASE ----------------------
+"Lowercase and uppercase
s1 = |AbCdEfG|.
s2 = |{ s1 CASE = LOWER }|. "abcdefg
s2 = |{ s1 CASE = UPPER }|. "ABCDEFG
-"WIDTH/ALIGN
+"---------------------- WIDTH/ALIGN ----------------------
s1 = `##`.
s2 = |{ s1 WIDTH = 10 ALIGN = LEFT }<---|. "'## <---'
s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
-"PAD: Used to pad any surplus places in the result with the specified character.
+"---------------------- PAD ----------------------
+"Used to pad any surplus places in the result with the specified character.
s2 = |{ s1 WIDTH = 10 ALIGN = RIGHT PAD = `.` }<---|. "'........##<---'
-"DECIMALS
+"---------------------- DECIMALS ----------------------
s1 = |{ CONV decfloat34( - 1 / 3 ) DECIMALS = 3 }|. "'-0.333'
-"SIGN: Defining the format of the +/- sign when the string represented
+"---------------------- 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
@@ -388,11 +413,13 @@ 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.
+"---------------------- 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
+"---------------------- 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`.
@@ -405,7 +432,8 @@ 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;
+"---------------------- 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.456
@@ -424,7 +452,8 @@ 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
+"---------------------- 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
@@ -440,9 +469,6 @@ s1 = |{ '00001234' ALPHA = OUT }|. "1234
s1 = |{ '00001234' ALPHA = RAW }|. "00001234
```
-> **💡 Note**
-> Escape `\|{}` in string templates using `\`, i. e. `\\` means `\`.
-
⬆️ back to top
## Determining the Length of Strings
@@ -1240,7 +1266,7 @@ FIND FIRST OCCURRENCE OF `Z`
### String Function find
- Built-in search functions, such as `find`, are available for searching strings.
- They return a return value of type i and contain multiple (optional) parameters.
-- `FIND` covers the same functionality and more with the many addition options.
+- `FIND` covers the same functionality and more with the many addition options (e.g. searching in tables).
- For more information, see [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensearch_functions.htm)
Parameters of the `find` function:
@@ -1322,7 +1348,7 @@ ENDTRY.
- [`REPLACE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapreplace.htm) and [`REPLACE ... IN TABLE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapreplace_itab.htm) statements have a similar syntax as `FIND` and `FIND ... IN TABLE` statements. Refer to the ABAP Keyword Documentation for all possible additions. The following code snippets cover a selection.
- `sy-subrc` is set: 0 (search pattern or section was replaced by the specified content, result was not truncated on the right), 2 (search pattern or section was replaced, result was truncated on the right), 4 (search pattern was not found).
-- `REPLACE` statements can be used to directly replace strings (including substrings, which is not possible with the string function).
+- `REPLACE` statements can be used to directly replace strings (including substrings, which is not possible with the string function `replace` covered below).
``` abap
"Examples for pattern-based replacements in which data objects are searched for character strings
@@ -1564,7 +1590,7 @@ help you process strings effectively.
> Do not use [POSIX
regular
expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenposix_regex_glosry.htm "Glossary Entry")
-anymore, they are obsolete.
+anymore. They are obsolete.
⬆️ back to top
@@ -2074,7 +2100,7 @@ IF s8 NP `*c#D*`. ... "false; sy-fdpos: 2
⬆️ back to top
### Miscellaneous Classes for String Processing
-The following list (as also covered in the [Misc ABAP Classes cheat sheet](22_Misc_ABAP_Classes.md)) shows a selected set of classes that support string processing.
+As also covered in the [Misc ABAP Classes](22_Misc_ABAP_Classes.md) cheat sheet, the following list shows a selected set of classes that support string processing.
- `CL_ABAP_CHAR_UTILITIES`: As previously mentioned, this class provides utilities for string processing, such as attributes that represent new lines and horizontal tabs.
diff --git a/19_ABAP_for_Cloud_Development.md b/19_ABAP_for_Cloud_Development.md
index f9719d7..c25d0ea 100644
--- a/19_ABAP_for_Cloud_Development.md
+++ b/19_ABAP_for_Cloud_Development.md
@@ -65,7 +65,7 @@ It provides references to more detailed information on the topic.
- Although the source code provides an invalid data source, the dynamic ABAP SQL statement does not produce a syntax error during compilation. However, it would result in a runtime error because you cannot select from that data source. You can check the validity of dynamic specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
- The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
- When using APIs and types like `string_table`, ensure that they are released. The `IF_OO_ADT_CLASSRUN` interface is released, and you can implement it to run an ABAP class. In ADT, you can do this by choosing *F9*. However, the example class will not run because the class cannot be activated due to the syntax errors. To output the content of data objects, you can use `out->write( ... )` in the `main` method.
- - The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. It includes the invalid statement `MOVE ... TO` and others that are included for demonstration purposes (some alternatives are provided). Certain system fields should not be accessed. The pointless `WRITE` statement within the method implementation represents invalid classic ABAP UI-related statements. Executable programs (*reports*) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT, double-click the area to the left of the code line number.
+ - The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. It includes the invalid statement `MOVE ... TO` and others that are added for demonstration purposes (some alternatives are provided). Certain system fields should not be accessed. The pointless `WRITE` statement within the method implementation represents invalid classic ABAP UI-related statements. Executable programs (*reports*) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT, double-click the area to the left of the code line number.
```abap
CLASS zcl_some_class DEFINITION
@@ -92,16 +92,22 @@ It provides references to more detailed information on the topic.
SELECT carrid, connid FROM zdemo_abap_fli USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE @DATA(it3).
"(Not) released APIs
- "Getting a random integer
+ "Released API: Getting a random integer
DATA(random_num) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
- min = 1
- max = 100 )->get_next( ).
+ min = 1
+ max = 100 )->get_next( ).
- "Possible alternatives to the system fields used below
- DATA(sys_date) = cl_abap_context_info=>get_system_date( ).
- DATA(sys_time) = cl_abap_context_info=>get_system_time( ).
+ "Released APIs from the XCO library
+ "Retrieving the current user date
+ DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
+ )->as( xco_cp_time=>format->iso_8601_extended
+ )->value.
+ "Retrieving the current user time
+ DATA(user_time) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
+ )->as( xco_cp_time=>format->iso_8601_extended
+ )->value.
- "Querying whether the current database supports AMDP methods
+ "Not released API: Querying whether the current database supports AMDP methods
DATA(amdp_allowed) = xsdbool( cl_abap_dbfeatures=>use_features(
EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ) ).
@@ -109,23 +115,30 @@ It provides references to more detailed information on the topic.
DATA(num1) = 1.
DATA(num2) = 1.
DATA(num3) = 2.
+ "Invalid statement for an assignment
MOVE num3 TO num1.
+ "Using the assignment operator
num2 = num3.
DATA(it4) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
+ "Invalid statement for determining the number of lines in an internal table
DESCRIBE TABLE it4 LINES DATA(num_lines1).
DATA(num_lines2) = lines( it4 ).
DATA: ref1 TYPE REF TO i,
ref2 TYPE REF TO i.
+ "Deprecated statement for references
GET REFERENCE OF num1 INTO ref1.
+ "Using the REF operator instead
ref2 = REF #( num1 ).
+ "Various sy components should not be used in ABAP for Cloud Development
DATA(current_time) = sy-uzeit.
DATA(current_date) = sy-datum.
DATA str_itab TYPE string_table.
+ "Various invalid statements
READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO str_itab.
WRITE 'hi'.
BREAK-POINT.
diff --git a/21_XML_JSON.md b/21_XML_JSON.md
index 8c59762..b6f4d6f 100644
--- a/21_XML_JSON.md
+++ b/21_XML_JSON.md
@@ -9,7 +9,7 @@
- [sXML](#sxml)
- [XML Transformations](#xml-transformations)
- [CALL TRANSFORMATION Syntax](#call-transformation-syntax)
- - [Dealing with JSON](#dealing-with-json)
+ - [Working with JSON](#working-with-json)
- [Excursions](#excursions)
- [Converting string \<-\> xstring](#converting-string---xstring)
- [Compressing and Decompressing Binary Data](#compressing-and-decompressing-binary-data)
@@ -513,7 +513,7 @@ CALL TRANSFORMATION ... SOURCE ...
⬆️ back to top
-## Dealing with JSON
+## Working with JSON
- You can ..
- create and read JSON data in ABAP using the readers and writers in the sXML library. See the processing of XML data in the sXML section above. Parsing and rendering JSON data works in a similar way. However, instead of using XML readers/writers, you use JSON readers/writers.
- transform ABAP to and from JSON data using transformations. You can directly transform ABAP <-> JSON using identity transformation (ID). In this context, note the intermediate format asJSON (see the notes on asXML above).
@@ -542,30 +542,59 @@ CALL TRANSFORMATION id SOURCE XML json
RESULT hi = str_b.
"str_b: Hello
-"ABAP -> formatted JSON
-"In this example, an internal table is transformed to JSON.
-"A cast is included for the writer (if_sxml_writer) to access special methods.
-"See comments in the sXML section.
-DATA(str_table) = value string_table( ( `abc` ) ( `def` ) ( `ghi` ) ).
+"ABAP -> (un)formatted JSON
+"In this example, an internal table is transformed to JSON.
+TYPES: BEGIN OF demo_struc,
+ comp1 TYPE i,
+ comp2 TYPE string,
+ comp3 TYPE abap_boolean,
+ END OF demo_struc,
+ tab_type TYPE TABLE OF demo_struc WITH EMPTY KEY.
+DATA(it) = VALUE tab_type( ( comp1 = 1 comp2 = `abc` comp3 = abap_true )
+ ( comp1 = 2 comp2 = `def` comp3 = abap_false )
+ ( comp1 = 3 comp2 = `ghi` comp3 = abap_true ) ).
+
DATA(json_wr) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
-DATA(json_wr_cast) = CAST if_sxml_writer( json_wr ).
-"With the following method calls, the result is formatted.
-json_wr_cast->set_option( option = if_sxml_writer=>co_opt_linebreaks ).
-json_wr_cast->set_option( option = if_sxml_writer=>co_opt_indent ).
-
-CALL TRANSFORMATION id SOURCE itab = str_table
+CALL TRANSFORMATION id SOURCE itab = it
RESULT XML json_wr.
-DATA(json_formatted) = cl_abap_conv_codepage=>create_in( )->convert( json_wr->get_output( ) ).
+DATA(json_output_xstr) = json_wr->get_output( ).
+DATA(json_unformatted) = cl_abap_conv_codepage=>create_in( )->convert( json_output_xstr ).
+
+*{"ITAB":[{"COMP1":1,"COMP2":"abc","COMP3":"X"},{"COMP1":2,"COMP2":"def","COMP3":""},{"COMP1":3,"COMP2":"ghi","COMP3":"X"}]}
+
+"A cast is included for the writer (if_sxml_writer) to access special methods.
+"See comments in the sXML section.
+DATA(json_wr_formatting) = CAST if_sxml_writer( cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ) ).
+
+"With the following method calls, the result is formatted.
+json_wr_formatting->set_option( option = if_sxml_writer=>co_opt_linebreaks ).
+json_wr_formatting->set_option( option = if_sxml_writer=>co_opt_indent ).
+
+CALL TRANSFORMATION id SOURCE itab = it
+ RESULT XML json_wr_formatting.
+
+DATA(json_formatted) = cl_abap_conv_codepage=>create_in( )->convert( CAST cl_sxml_string_writer( json_wr_formatting )->get_output( ) ).
-*json_formatted:
*{
* "ITAB":
* [
-* "abc",
-* "def",
-* "ghi"
+* {
+* "COMP1":1,
+* "COMP2":"abc",
+* "COMP3":"X"
+* },
+* {
+* "COMP1":2,
+* "COMP2":"def",
+* "COMP3":""
+* },
+* {
+* "COMP1":3,
+* "COMP2":"ghi",
+* "COMP3":"X"
+* }
* ]
*}
```
diff --git a/22_Misc_ABAP_Classes.md b/22_Misc_ABAP_Classes.md
index 56a102c..5fcfce1 100644
--- a/22_Misc_ABAP_Classes.md
+++ b/22_Misc_ABAP_Classes.md
@@ -2301,6 +2301,14 @@ ENDTRY.
For creating a client object using an HTTP destination. The HTTP destination is provided based on an HTTP destination object.
The latter can be created, among others, based on a communication arrangement or a plain URL.
For more information, refer to the class documentation and the topic Integration and Connectivity.
+To check out the classes in an example, expand the collapsible section below.
+
+
+
+ Expand to view an example
+
+
+
- ⚠️ Notes on the example
- The following self-contained and oversimplified example is not a representative best practice example, nor does it cover a meaningful use case.
@@ -2532,6 +2540,9 @@ CLASS zcl_some_class IMPLEMENTATION.
ENDMETHOD.
ENDCLASS.
```
+
+
+
diff --git a/README.md b/README.md
index 081618f..027f078 100644
--- a/README.md
+++ b/README.md
@@ -152,7 +152,7 @@ https://github.com/SAP-samples/abap-cheat-sheets.git
- 2b) System supportig classic ABAP
+ 2b) System supporting classic ABAP
**Prerequisites**