ABAP Cloud - Data Types
What does it actually look like when using data elements in ABAP Cloud? In this article we look at alternatives in the definition.
Table of contents
In this article we will discuss the use of data types, how you can use them for table definitions and how you can add other elements.
Introduction
So far we have accessed SAP data elements as standard and used them for interfaces and table definitions. With ABAP Cloud, some data elements are released, but if we look through the individual elements, we will quickly notice that most of them are of a technical nature.
So how do you deal with missing data elements in ABAP Cloud? In the following sections, we will show you various ways to get your typing.
Reason
Why aren't all data elements released anymore? Basically, SAP only releases elements that the customer is to use in ABAP Cloud development. Data elements are part of the definition of the table, which we no longer have direct access to, since we are primarily supposed to use Core Data Services here. On the other hand, some data elements contain "strange" conversion exits that we no longer want to see in Fiori. Conversion exits are used in the SAP GUI environment and are no longer needed in ABAP Cloud, since we use Fiori as the frontend. We would also like to say that smaller conversion exits will remain.
If we look into the future of ABAP Cloud, we will then use CDS types and enums to create and type our table entities. Data elements will therefore have a certain shelf life for the transition period, but will slowly die out in the future.
Usage - Released
Let's take a look at table T001, the corresponding Core Data Service here is I_CompanyCode. The element BUKRS is released for use as a data element. This means we can continue to use it as normal.
Here, the data elements of master and transaction data are usually released, since we as users mostly need these as secondary keys in the tables and when accessing them. You can use the elements freely in your development.
Usage - classes and logic
If, for example, we want to define a field of type BUTXT, we cannot do this in our code because the element is not released. However, we can use the elements of the Core Data Service when we create structures and types in the class. To do this, we define a type that we can reuse and a structure in which we combine different types.
TYPES td_company_text TYPE I_CompanyCode-CompanyCodeName.
TYPES: BEGIN OF ts_data,
companycode TYPE I_CompanyCode-CompanyCode,
text_direct TYPE I_CompanyCode-CompanyCodeName,
text_type TYPE td_company_text,
END OF ts_data.
TYPES tt_data TYPE STANDARD TABLE OF ts_data WITH EMPTY KEY.
In the next step we read the data from the table and fill our structure.
DATA lt_withtype TYPE tt_data.
SELECT FROM I_CompanyCode
FIELDS CompanyCode,
CompanyCodeName AS text_direct,
CompanyCodeName AS text_type
INTO TABLE @lt_withtype
UP TO 10 ROWS.
Finally, we check a row from the table and look at the types in the debugger. The direct use of the CDS field, as well as the creation of a type, work without any problems. This ensures that the correct data types are available within the processing logic.
Usage - Database
However, if we want to use the data type to define a database, the first method no longer works. Here we have to specify a data element and cannot access the field reference of the Core Data Service. In such a case we have two methods available to us, let's take a look at the company (RCOMP).
Standard
In the standard scenario all elements are on TIER-3 and cannot be used by us on TIER-1. The data elements cannot be used to define a table either.
Wrapper
In the first scenario we create a wrapper object which we then make available for TIER-1. We can do this using "Duplicate" copy the data element from the standard into our TIER-2 package.
Once the copy is complete, all properties and the domain from the original element have been adopted, as have the texts.
So that we can now use the element in TIER-1, we must create a C1 contract and release the element. Use the "Properties" view to you will find the corresponding dialog to create the release.
Copy
In the second scenario, we copy all elements to TIER-1 and use them directly without release. Here we also have the option of using the domain. To do this, we copy the standard again; in this case, the target package is our TIER-1 component.
After copying, however, we receive an error message for the new domain. The use of table T880 is not permitted. Since the table is not released, we have to remove the table and can then activate the domain.
In the next step we can then copy the data element. The target is again the same package as our domain.
In this case we get a somewhat cryptic error message. To do this we first have to expand the additional attributes and find the parameter there. This attribute is used in GUI development to pre-populate fields on the dynpro if the corresponding user settings are available.
After deleting the parameter, we can now replace the domain with our own and activate the data element.
Usage
The data elements can then be used as usual. However, you should note that with the second variant the data element can only be used in the SWC. In the first variant we create a C1 contract and can use the element in every software component. However, since the object is TIER-2, we recommend the second variant with a contract, so that the element can be used and we have no technical debt in the system.
TYPES: BEGIN OF ts_data_element,
companycode TYPE I_CompanyCode-CompanyCode,
rcomp_release TYPE zfi_rcomp_released,
rcomp_dtel TYPE zfi_rcomp_dtel,
END OF ts_data_element.
TYPES tt_data_element TYPE STANDARD TABLE OF ts_data_element WITH EMPTY KEY.
More data elements
SAP is currently working on several major notes to release around 24000+ data elements for development in ABAP Cloud. The feedback from customers and developers has been correspondingly large that more standard elements are needed to be able to work easily with ABAP Cloud. As soon as the notes are available, you will find them here.
The collective note 3470426 was released for all customers on September 5, 2024. The releases will generally be available in the releases SAP S/4HANA Cloud Private Edition 2025 and 2023 FPS2. You can also find the released data elements via the Cloudification Repository.
Hint: However, you should also take into account that each standard data element represents a dependency on the SAP standard. Many partners are currently having problems converting their solutions because many of them are based on standard elements that are no longer released or are sometimes deleted by SAP.
Complete example
You can find the complete executable class here, the data comes from a Cloud Appliance Library System. We do not provide the data elements in this case, but you can derive them from the examples above.
CLASS zcl_bs_demo_data_types DEFINITION
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
TYPES td_company_text TYPE I_CompanyCode-CompanyCodeName.
TYPES: BEGIN OF ts_data,
companycode TYPE I_CompanyCode-CompanyCode,
text_direct TYPE I_CompanyCode-CompanyCodeName,
text_type TYPE td_company_text,
END OF ts_data.
TYPES tt_data TYPE STANDARD TABLE OF ts_data WITH EMPTY KEY.
TYPES: BEGIN OF ts_data_element,
companycode TYPE I_CompanyCode-CompanyCode,
rcomp_release TYPE zfi_rcomp_released,
rcomp_dtel TYPE zfi_rcomp_dtel,
END OF ts_data_element.
TYPES tt_data_element TYPE STANDARD TABLE OF ts_data_element WITH EMPTY KEY.
METHODS get_company_name
RETURNING VALUE(rd_result) TYPE td_company_text.
ENDCLASS.
CLASS zcl_bs_demo_data_types IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA lt_withtype TYPE tt_data.
DATA lt_element TYPE tt_data_element.
SELECT FROM I_CompanyCode
FIELDS CompanyCode,
CompanyCodeName AS text_direct,
CompanyCodeName AS text_type
INTO TABLE @lt_withtype
UP TO 10 ROWS.
out->write( `With type:` ).
out->write( lt_withtype ).
SELECT FROM I_CompanyCode
FIELDS CompanyCode,
CompanyCodeName AS text_direct,
CompanyCodeName AS text_type
INTO TABLE @DATA(lt_inline)
UP TO 10 ROWS.
out->write( `Inline declaration:` ).
out->write( lt_inline ).
SELECT FROM I_CompanyCode
FIELDS CompanyCode,
Company AS rcomp_release,
Company AS rcomp_dtel
INTO TABLE @lt_element
UP TO 10 ROWS.
out->write( `Data elements:` ).
out->write( lt_element ).
ENDMETHOD.
METHOD get_company_name.
SELECT SINGLE FROM I_CompanyCode
FIELDS CompanyCodeName
INTO @rd_result.
ENDMETHOD.
ENDCLASS.
Conclusion
Using data types from the standard is no longer so easy, but there are various ways to get the typing. When developing, you should look at where you want to use the elements and then find the specific solution. If you build on clean software components, you should also keep the dependencies on the standard small.