The most powerful ABAP library – SAP XCO Library

0
2276

The SAP XCO library is a general-purpose ABAP library that provides an efficient ABAP development experience.

It provides tools for generating development objects programmatically by providing a hierarchy of APIs based on classes. 

This blog post will learn more about this new efficient and more powerful XCO ABAP development library.

SAP XCO Library

The ABAP XCO (“Extension Components”) library is a general-purpose development library designed to make ABAP development as efficient as possible. The SAP XCO library is organized as a collection of independent modules.

There are several modules within the XCO library, each of which focuses on a different functional area. Every module exposes its public API through a particular class, called the API “class” of the module. 

In each module, the API class serves as the point of entry to all offered functionality. The name of the API class starts with “XCO_CP_” (or) “XCO_KU_.

History of SAP ABAP XCO Library

XCO library was initially introduced in SAP BTP ABAP Environment (aka Steampunk) 2005 and ABAP Platform on-premise S/4 HANA 2020.

With the 2008 release, the SAP XCO Library is now publicly available on the SAP Cloud Platform ABAP Environment (aka Steampunk).

Overview of XCO Modules

The library comprises three types of modules

  1. Cloud Platform(CP) edition
  2. Key User edition
  3. On-premise edition  

When writing this blog, below is the list of modules available in both ABAP Environment on-premise S/4 HANA 2020 and SAP BTP ABAP Environment.

1. Key User Extensibility XCO Modules:

Below are the 4 ABAP Key User XCO modules. The key user (KU) edition of the SAP XCO library provides a set of functions that support typical In-App Extensibility scenarios.

API Class NameDescription
XCO_KU_JSONIt works with JSON data as simply as possible
XCO_KU_REGULAR_EXPRESSIONIt works with POSIX and PCRE regular expressions in ABAP
XCO_KU_STRINGThis API works with strings like splitting and joining
XCO_KU_UUIDIt provides a simple way to translate between different UUID formats

2. Cloud Platform(CP) XCO Modules:

Below is the list of XCO APIs available as part of the ABAP Cloud Platform edition.

API Class Name Description
XCO_CP_ABAPIt provides access to conceptual abstractions for classes and interfaces and representations of ABAP built-in and generic types.
XCO_CP_ABAP_DICTIONARYIt provides access to conceptual abstractions for ABAP Dictionary elements (Database tables, data elements, structures, table types, and domains) and representations of ABAP Dictionary built-in types and their corresponding reference types.
XCO_CP_ABAP_OBJECTSIt provides access to enumerations specific to ABAP Objects.
XCO_CP_ABAP_REPOSITORYIt provides APIs and abstractions for retrieving and filtering development objects of the ABAP Repository.
XCO_CP_ABAP_SQLIt provides methods for building ABAP SQL constraints to be used in conjunction with filtering functionality.
XCO_CP_DATA_DEFINITIONIt provides access to enumerations and text attributes specific to CDS data definitions.
XCO_CP_DATA_ELEMENTIt provides access to text attributes specific to data elements
XCO_CP_DATABASE_TABLEIt provides access to database table-specific enumerations, e.g., the size category of a database table.
XCO_CP_DOMAINIt provides access to text attributes specific to domains.
XCO_CP_DDLIt provides ways to build DDL (Data definition language) expressions to be used when generating DDLS objects.
XCO_CP_DCLIt provides ways to build DCL (Data control language) expressions to be used when generating DCLS objects
XCO_CP_CDSIt provides access to enumerations specific to the field of Core Data Services (CDS) and conceptual abstractions for behavior definitions, data definitions, metadata extensions, and CDS entities.
XCO_CP_CDS_ANNOTATIONIt provides ways to build CDS annotation values when generating DDLS, DDLX, or SRVD objects.
XCO_CP_AMDPIt provides access to enumerations in the context of ABAP-managed database procedures.
XCO_CP_ARSIt provides standard abstractions in the context of the API Release (ARS) framework when programmatically setting or getting API states.
XCO_CP_BALIt provides APIs for creating, deleting, and searching logs and standard abstractions for integrating logging functionality into the custom application logic.
XCO_CP_BEHAVIOR_DEFINITIONIt provides access to enumerations specific to behavior definitions.
XCO_CP_BEHAVIOR_IMPLEMENTATIONIt provides access to enumerations specific to behavior implementations.
XCO_CP_GENERATIONProvides access to the XCO Generation APIs, i.e., allows obtaining a generation environment that can be used to create PUT and DELETE operations.
XCO_CP_I18NProvides access to the XCO I18N APIs, i.e., allows obtaining a domain, data element, data definition, and message class targets used to maintain language-dependent texts programmatically.
XCO_CP_JSONProvides access to facilities used when working with JSON data in the context of the XCO standard library, such as the JSON builder or standard JSON transformations.
XCO_CP_MESSAGEIt provides access to enumerations specific to messages, such as the message type.
XCO_CP_METADATA_EXTENSIONIt provides access to enumerations specific to metadata extensions.
XCO_CP_PACKAGEIt provides access to enumerations specific to packages.
XCO_CP_REGULAR_EXPRESSIONProvides access to abstractions used when working with regular expressions, such as different regular expression engines.
XCO_CP_SERVICE_BINDINGIt provides access to enumerations specific to service bindings.
XCO_CP_SOFTWARE_COMPONENTIt provides access to enumerations specific to software components.
XCO_CP_STRINGIt provides access to abstractions used when working with strings, such as string builders or standard compositions and decompositions.
XCO_CP_SYSTEMIt provides access to abstractions for system-wide entities such as software components or application components.
XCO_CP_TABLEIt provides access to enumerations specific to tables (i.e., structures and database tables).
XCO_CP_TABLE_TYPEIt provides access to enumerations specific to table types.
XCO_CP_TRANSPORTIt provides access to enumerations and abstractions specific to transports.
XCO_CP_UUIDIt provides access to abstractions used when working with UUIDs, such as different UUID formats.

3. ABAP On-premise XCO Modules

Below is the list of XCO modules we can use with on-premise S/4 HANA 2020. Most of the CP and on-premise edition APIs are similar.

API Class Name Description
XCO_ABAP_DICTIONARYIt provides access to conceptual abstractions for ABAP Dictionary elements (Database tables, data elements, structures, table types, and domains) and representations of ABAP Dictionary built-in types and their corresponding reference types.
XCO_ABAP_LANGUAGE_VERSIONIt provides APIs for the ABAP language version.
XCO_ABAP_OBJECTSIt provides access to enumerations specific to ABAP Objects.
XCO_ABAP_REPOSITORYIt provides APIs and abstractions for retrieving and filtering development objects of the ABAP Repository.
XCO_ABAP_REPOSITORY_TDIt provides APIs for the Double Test framework
XCO_ABAP_SQLIt provides methods for building ABAP SQL constraints to be used in conjunction with filtering functionality.

The RAP Generator

RAP Generator makes it easier for the developer to programmatically create the complete stack of objects needed to implement a RAP business object.

Now that we know how powerful ABAP development is, the XCO library, the famous RAP Generator by Andre Fischer, is based on this XCO framework.

Demo Time

Let’s write some ABAP code to create an ABAP repository object programmatically; SE11 Table using XCO Generation, a part of the XCO (“Extension Components”) ABAP development library.

Below is the sample code which creates a DDIC table using XCO APIs; we make it simple to understand.

CONSTANTS:
  co_package   TYPE sxco_package VALUE 'ZDEMO'.

DATA(lo_transport_target) = xco_abap_repository=>package->for( co_package
        )->read(
        )-property-transport_layer->get_transport_target( ).

"Create a TR
DATA(lo_transport_request) = xco_cp_cts=>transports->workbench( lo_transport_target->value
        )->create_request( 'Generated transport request' ).


DATA(lo_put_operation) = xco_cp_generation=>environment->dev_system( lo_transport_request->value
  )->create_put_operation( ).

" Add the database table to the PUT operation.
DATA(lo_database_table) = lo_put_operation->for-tabl-for-database_table->add_object( 'ZTBL_XCO_DEMO'
  )->set_package( co_package
  )->create_form_specification( ).
lo_database_table->set_short_description( 'My generated database table' ).
lo_database_table->set_delivery_class( xco_cp_database_table=>delivery_class->l ).
lo_database_table->set_data_maintenance( xco_cp_database_table=>data_maintenance->allowed ).

lo_database_table->add_field( 'KEY_FIELD'
  )->set_key_indicator(
  )->set_type( xco_cp_abap_dictionary=>built_in_type->char( 30 )
  )->set_not_null( ).

" Further fields (including information about foreign keys, search helps, etc.) can be
" added following the same pattern.

lo_put_operation->execute( ).

You will create the following database table (or their update for those that already exist) and their activation as one mass activation by executing this code.

SAP XCO Library Demo

Conclusion

Congrats!! You have successfully learned SAP XCO( “Extension Components” ).

  1. What is the SAP XCO Library?
  2. What are the different SAP XCO Modules and APIs? 
  3. How to create, update and delete ABAP repository objects programmatically using XCO Library?

Other References