- [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)
- [Dynamically Creating Data Types (RTTC) and Data Objects at Runtime Using Type Description Objects](#dynamically-creating-data-types-rttc-and-data-objects-at-runtime-using-type-description-objects)
- [Getting Type Description Objects](#getting-type-description-objects)
- [Creating Elementary Types and Data Objects Dynamically](#creating-elementary-types-and-data-objects-dynamically)
- [Creating Structured Types and Data Objects Dynamically](#creating-structured-types-and-data-objects-dynamically)
- [Creating Table Types and Internal Tables Dynamically](#creating-table-types-and-internal-tables-dynamically)
- [Creating Reference Types and Data Reference Variables Dynamically](#creating-reference-types-and-data-reference-variables-dynamically)
- [More Information](#more-information)
- [Executable Example](#executable-example)
@@ -1328,6 +1332,12 @@ ASSIGN dobj_c10 TO <casttype> CASTING TYPE HANDLE tdo_elem. "1234
- You can also use type description objects and the [`TYPE HANDLE` addition](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) to create anonymous data objects dynamically. For this and the absolute names, find more information below in the section about RTTS.
``` abap
"------------ CREATE DATA statement patterns ----------------
"CREATE DATA dref TYPE (typename).
"CREATE DATA dref TYPE TABLE OF (typename).
"CREATE DATA dref TYPE REF TO (typename).
"CREATE DATA dref TYPE HANDLE type_description_object.
"------------ Specifying a type name dynamically ------------
"Anonymous data objects are created using a type determined at
@@ -2782,7 +2792,7 @@ for more details.
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Getting Type Information at Runtime
### Getting Type Information at Runtime (RTTI)
With RTTI, you can determine data types at runtime using description methods in type description classes.
To get the type information, you can get a reference to a type description object of a type, that is, an instance of a type description class.
@@ -2800,7 +2810,7 @@ The type properties are represented by attributes that are accessible through th
The following code example demonstrates a range of RTTI attribute accesses and method calls. It includes retrieving type information at runtime for elementary and enumerated types, structures, internal tables, data references, classes, and interfaces. Find more information in the section below.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it.
The example is not set up to display output in the console. So, after activation, you may want to set a break point at the first position possible and choose *F9* in ADT to execute the class. You can then walk through the example in the debugger. This will allow you to double-click on the variables and check out the contents. The example is similar to the one below, however, this only focuses on the method calls without output preparation among others.
The example is not set up to display output in the console. So, after activation, you may want to set a break point at the first position possible and choose *F9* in ADT to execute the class. You can then walk through the example in the debugger. This will allow you to double-click on the variables and check out the contents. The example is similar to the one below, however, this only focuses on the method calls and attribute accesses without output preparation among others.
```abap
CLASS zcl_some_class DEFINITION
@@ -3807,167 +3817,312 @@ ENDTRY.
<p align="right"><a href="#top">⬆️ back to top</a></p>
### 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](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.
### Dynamically Creating Data Types (RTTC) and Data Objects at Runtime Using Type Description Objects
The focus of the following snippets is on using RTTC methods such as `get` to create type description objects. For more information, check the class documentation. It is recommended that you use the `get` method instead of the `create` method.
- They are instances of type description classes. See the hierarchy of type description classes above.
- As already shown in several code snippets above, you can use the static methods of these type description classes to create type description objects.
- You can create them from existing types or create new types.
- Attributes of type description objects determine the technical properties of the type.
- Type description objects are basically available for all types.
- `CREATE DATA` and `ASSIGN` statements include the `HANDLE` addition after which you can specify references to type description objects so as to create or assign data objects dynamically.
- The focus here is on creating anonymous data objects dynamically using `CREATE DATA` statements. Apart from using type description objects and the `HANDLE` addition, you can - as shown above - perform a dynamic creation of data objects using a type name specified dynamically (`CREATE DATA dref TYPE (some_type).`).
- After the [`HANDLE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) addition, a reference variable of the static type of class `CL_ABAP_DATADESCR` or its subclasses that points to a type description object are expected.
The following examples show snippets that have already been covered in several sections above.
The use the following methods to get type description objects:
- `cl_abap_typedescr=>describe_by_name` (based on an existing type name)
- `cl_abap_typedescr=>describe_by_data` (based on an existing data object)
- `...=>get*` (getting type description objects for elementary and other types)
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Dynamically Creating Data Objects at Runtime Using Type Description Objects
#### Creating Reference Types and Data Reference Variables Dynamically
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.`
- dynamically: `CREATE DATA dref TYPE (some_type).`
```abap
"A reference type and variable such as the following shall be created
"using type description objects.
TYPES ty_ref2string TYPE REF TO string.
DATA dref_string TYPE REF TO string.
Another way to dynamically create data objects with dynamic type specification is to use types created at runtime with RTTC methods.
The `CREATE DATA` statement provides the [`TYPE HANDLE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) addition after which you can specify type description objects. A reference variable of the static type of class `CL_ABAP_DATADESCR` or its subclasses that points to a type description object can be specified after `TYPE HANDLE`.
DATA dref_ref TYPE REF TO data.
``` abap
DATA dref_cr TYPE REF TO data.
"Creating the type dynamically (creating a type description object)
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -3976,6 +4131,8 @@ CREATE DATA dref_cr TYPE HANDLE tdo_ref.
- It is recommended that you also consult section [Dynamic Programming Techniques (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynamic_prog_technique_gdl.htm) in the ABAP Keyword Documentation since it provides important aspects that should be considered when dealing with dynamic programming in general (e. g. security aspects or runtime error prevention).
- There are even further dynamic programming techniques in the unrestricted ABAP language scope [Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm) such as the generation or execution of programs at runtime. They are not part of this cheat sheet. Find more details on the related syntax (e. g. `GENERATE SUBROUTINE POOL`, `READ REPORT` and `INSERT REPORT` in the ABAP Keyword Documentation for Standard ABAP: [Dynamic Program Development (F1 docu for Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_language_dynamic.htm)
<palign="right"><ahref="#top">⬆️ back to top</a></p>
Rules for the RAP BO provider and consumer implementation to ensure
consistency and reliability
- The [Authorization Checks](25_Authorization_Checks.md) cheat sheet includes high-level information and provides links on authorization control in RAP.
<palign="right"><ahref="#top">⬆️ back to top</a></p>
@@ -448,7 +448,7 @@ There are multiple ways to implement test doubles manually:
- If the DOC is a method in a class that allows inheritance (i.e. it is not defined as `FINAL`), you can inherit from the class and redefine methods for which you need a test double.
> **💡 Note**<br>
> Instead of manually creating test doubles, the [ABAP OO Test Double Framework](https://help.sap.com/docs/ABAP_PLATFORM_NEW/c238d694b825421f940829321ffa326a/804c251e9c19426cadd1395978d3f17b.html?locale=en-US) helps you create test doubles automatically.
> See information and an example about frameworks such as the [ABAP OO Test Double Framework](https://help.sap.com/docs/ABAP_PLATFORM_NEW/c238d694b825421f940829321ffa326a/804c251e9c19426cadd1395978d3f17b.html?locale=en-US) below that support you with creating the test doubles.
As an alternative to using the <code>IF_OO_ADT_CLASSRUN</code> interface for displaying output in the console, you can also use the <code>CL_DEMO_CLASSRUN</code> class, which offers more methods.
For more information, refer to <a href="https://blogs.sap.com/2023/10/24/abap-console-reloaded/">this blog</a>.
The following example makes use of the <code>CL_DEMO_CLASSRUN</code>. A structure and an internal table are displayed in the console. A structure component is a reference variable, which is automatically dereferenced. Plus, the <code>write_xml</code> method is shown, which displays XML data.
The following example makes use of the <code>CL_DEMO_CLASSRUN</code> class. A structure and an internal table are displayed in the console. A structure component is a reference variable, which is automatically dereferenced. Plus, the <code>write_xml</code> method is shown, which displays XML data.
<br><br>
``` abap
@@ -2508,8 +2508,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(zip) = NEW cl_abap_zip( ).
"Iteratively adding the ABAP cheat sheet Markdown documents to the zip file
LOOP AT tab REFERENCE INTO cs WHERE error = abap_false.
cs->file_name = cs->file_name.
LOOP AT tab REFERENCE INTO cs WHERE error = abap_false.
@@ -2588,7 +2587,6 @@ CLASS zcl_some_class IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(nl) = |\n|.
DATA(markdown_content) =
`# Lorem ipsum dolor sit amet \n` &&
`Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \n` &&
@@ -2640,7 +2638,7 @@ ENDCLASS.
<td> <code>XCO_CP_XLSX</code> </td>
<td>
The XCO library offers classes (`XCO_CP_XLSX` and others) and methods for reading and writing XLSX content. You can find more information [here](https://help.sap.com/docs/btp/sap-business-technology-platform/xlsx). The following example demonstrates a selection of methods and includes the following steps:
The XCO library offers classes such as `XCO_CP_XLSX` and methods for reading and writing XLSX content. You can find more information [here](https://help.sap.com/docs/btp/sap-business-technology-platform/xlsx). The following example demonstrates a selection of methods and includes the following steps:
- Importing existing XLSX content into your SAP BTP ABAP Environment system (not related to the XCO library; just to have content to work with in the self-contained example below)
- This is a simplified, nonsemantic, and explorative RAP example (not delving into RAP as such; just using various ABAP repository objects related to RAP) solely for importing XLSX content to work with in the example.
- [Explicit Authorization Checks Using AUTHORITY-CHECK Statements](#explicit-authorization-checks-using-authority-check-statements)
- [Implicit Authorization Checks Using CDS Access Control for Read Accesses](#implicit-authorization-checks-using-cds-access-control-for-read-accesses)
- [Executable Example](#executable-example)
- [Executable Example (SAP BTP ABAP Environment)](#executable-example-sap-btp-abap-environment)
- [Implementation Steps](#implementation-steps)
- [Example Class](#example-class)
- [Excursion: Authorization Control in RAP](#excursion-authorization-control-in-rap)
@@ -76,7 +76,7 @@ The following topic covers authorization-related terms and provides you with the
- `#CHECK`: A warning is issued if no access control object is present.
- `#MANDATORY`: An access control object must be present.
- `#NOT_ALLOWED`: An access control object must not be present. If one exists, it is disregarded.
- The authorization are based on authorization objects.
- The authorizations are based on authorization objects.
- Example CDS view entity with the `@AccessControl.authorizationCheck: #CHECK` annotation
```abap
@@ -114,7 +114,7 @@ The following topic covers authorization-related terms and provides you with the
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Executable Example
## Executable Example (SAP BTP ABAP Environment)
> **💡 Note**<br>
> - The example is intentionally simplified and nonsemantic, designed to explore basic authorization checks.
@@ -137,16 +137,16 @@ Expand the following collapsible section to view the implementation steps requir
<br>
- You have accessed you SAP BTP ABAP Environment in ADT.
- You have accessed your SAP BTP ABAP Environment in ADT.
- Create an authorization field
- In your target package, choose *New -> Other ABAP Repository Object*.
- Filter for *Authorization Object* and choose *Next* and walk through the wizard.
- Filter for *Authorization Field* and choose *Next* and walk through the wizard.
- As the name, use *ZAUTH_CTRY*.
- Specify the data element `LAND1`.
- Save and activate.
- Create an authorization object
- In your target package, choose *New -> Other ABAP Repository Object*.
- Filter for *Authorization Field* and choose *Next* and walk through the wizard.
- Filter for *Authorization Object* and choose *Next* and walk through the wizard.
- As the name, use *ZAUTH_OBJ*.
- In the *Authorizaton Fields* section, add the *ZAUTH_CTRY* field created above.
- Select the *Activity Field* checkbox for the *ACTVT* field.
@@ -221,7 +221,7 @@ For creating a CDS access control, proceed as follows:
- Filter for *Data definition* and choose *Next*.
- As the name, use *ZCDS_ACC_CTRL*.
- In a step in the wizard, select *Define Role with PFCG Aspect*.
- As entitiy, use *ZDEMO_ABAP_FLSCH_VE_AUTH*.
- As entity, use *ZDEMO_ABAP_FLSCH_VE_AUTH*.
- Adapt the code according to the code below. The authorization object and fields from above are used. The specifications including *ACTVT = '03'* mean that entries can be read (displayed) if the *countryfr* is *US*.
```abap
@@ -467,10 +467,10 @@ ENDCLASS.
## Excursion: Authorization Control in RAP
- This section focuses on authorization control in the ABAP RESTful Application Programming Model (RAP).
- This section focuses on [authorization control](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_auth_control_glosry.htm) in the ABAP RESTful Application Programming Model (RAP).
- The authorization control features safeguard your RAP business objects from unauthorized data access.
- You can define authorization control in the BDEF for each entity, which then needs to be implemented in the RAP handler methods of the ABAP behavior pool.
- In the BDEF, you can set authorization control for all RAP BO operations of a specific entity or for particular RAP BO operations.
- You can define authorization control in the [RAP behavior definition (BDEF)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_behavior_definition_glosry.htm) for each entity, which then needs to be implemented in the [RAP handler methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_handler_method_glosry.htm) of the [ABAP behavior pool (ABP)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbehavior_pool_glosry.htm).
- In the BDEF, you can set authorization control for all [RAP BO operations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_operation_glosry.htm) of a specific entity or for particular RAP BO operations.
- For read operations on RAP business objects, you can utilize the CDS access control, which is automatically applied in managed scenarios.
- For modify operations, dedicated authorization implementation options are available, such as the following:
- Global authorization restricts data access or the ability to perform certain operations for an entire RAP BO, regardless of individual instances. This can depend on user roles. For example, if a user is not allowed to delete following the authorization check, the method handling the delete operation in the ABAP behavior pool is not invoked. In doing so, it allows you to reject a request before it reaches any other method of the behavior handler classes.
ELSE|It's {syst_timeTIME=ISO}. Good night, {sy-uname}.|).
out->write(data=greetingsname=`greetings`).
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.