Introducing the XCO Library Cloud Platform edition
Starting with CE 2008 the XCO Library is now publicly available on the SAP Cloud Platform ABAP Environment (aka Steampunk) for the first time. It is a completely newly engineered development library for ABAP with the goal to offer a highly intuitive and effective development experience for tasks that go beyond the mere scope of the ABAP programming language.
With this blog post I want to give you a first impression of what working with the XCO Library looks like. A detailed explanation of the overall organization, design principles and available functionality is provided with the official documentation, which can be found at https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/c154dffe892b4d9ea4566722f0bcd5f1.html.
A first impression of the library
The initial CE 2008 shipment of the XCO Library already comes with a wealth of functionality for different areas. To give you an idea of how the XCO Library looks and feels like in action I will provide a simple, integrated example that showcases the following aspects:
- Creating and releasing transports
- Generating ABAP Repository objects
- Searching for and accessing the content of ABAP Repository objects
At first we will have a look at how a new Workbench transport request can be created. Before being able to create a new transport request the transport target which is usually derived from the transport layer of a development package needs to be known. With the XCO Library, we can perform these operations concisely with just the following statements:
DATA(lo_package) = xco_cp_abap_repository=>package->for( 'Z_MY_PACKAGE' ). DATA(lv_transport_target) = lo_package->read( )-property-transport_layer->get_transport_target( )->value. DATA(lo_transport_request) = xco_cp_cts=>transports->workbench( lv_transport_target )->create_request( 'My generated transport request' ).
Equipped with a development package and a modifiable transport request we can use the XCO Generation APIs to easily create a new database table with a simple CDS view entity on top of it:
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( 'ZMY_DBT' )->set_package( lo_package->name )->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. " Add the data definition for the CDS view entity to the PUT operation DATA(lo_data_definition) = lo_put_operation->for-ddls->add_object( 'ZMY_VIEW_ENTITY' )->set_package( lo_package->name )->create_form_specification( ). lo_data_definition->set_short_description( 'My generated view entity' ). DATA(lo_view_entity) = lo_data_definition->add_view_entity( ). lo_view_entity->data_source->set_view_entity( 'ZMY_DBT' ). DATA(lo_key_field) = lo_view_entity->add_field( xco_cp_ddl=>field( 'KEY_FIELD' ) ). lo_key_field->set_key( )->set_alias( 'keyField' ). lo_key_field->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Key field' ). lo_put_operation->execute( ).
Executing this coding will result in the following database table and CDS view entity being created (or updated in case they already exist) and activated together in a single mass activation:
Database tables and data definitions are just two examples of object types that are already supported by the XCO Generation APIs. With the CE 2008 shipment it is possible to generate all the objects that go into a full-fledged RAP business object, starting from domains, data elements and database tables over CDS view entities and behavior definitions all the way up to service definitions and service bindings. An overview of all currently supported object types is available here.
Where the XCO Generation APIs allow you to modify the ABAP Repository by creating, updating or deleting objects, the XCO ABAP Repository APIs can be used to search for objects and read their contents:
DATA(lo_name_constraint) = xco_cp_abap_sql=>constraint->contains_pattern( 'ZMY_%' ). DATA(lo_name_filter) = xco_cp_abap_repository=>object_name->get_filter( lo_name_constraint ). " This query will retrieve all database tables whose name starts with ZMY_ that are contained " in the package denoted by LO_PACKAGE. DATA(lt_database_tables) = xco_cp_abap_repository=>objects->tabl->database_tables->where( VALUE #( ( lo_name_filter ) ) )->in( lo_package )->get( ). LOOP AT lt_database_tables INTO DATA(lo_database_table). " LS_CONTENT is a structure comprised of the header attributes of the " database table such as the delivery class or the technical settings. DATA(ls_content) = lo_database_table->content( )->get( ). " LT_FIELDS is a table of objects representing the fields of the database " table. As with the header information, the field objects can be used to " access the content of the field (e.g. its type or foreign key). DATA(lt_fields) = lo_database_table->fields->all->get( ). ENDLOOP.
Finally, releasing a transport request is as simple as
DATA(lt_transport_tasks) = lo_transport_request->get_tasks( ). LOOP AT lt_transport_tasks INTO DATA(lo_transport_task). IF lo_transport_task->get_status( ) EQ xco_cp_transport=>status->modifiable. lo_transport_task->release( ). ENDIF. ENDLOOP. lo_transport_request->release( ).
The simple example presented above is meant to give you a sense of the expressiveness and power that is now available with the XCO Library.
The functionality offered with CE 2008 already ranges far beyond working with objects of the ABAP Repository. Other highlights include APIs for integrating business application logs into your own application logic as well as an already rich set of standard library functionality. This includes in particular the XCO JSON module which offers new ideas of how to work with JSON data in ABAP.
Feel free to try out the XCO Library and post your questions and thoughts in the comments. The XCO Library is still under very active development, so stay tuned for lots more features to come!
Last but not least I can highly recommend the blog from Andre Fischer about the RAP Generator that he has built based on the XCO Library. It allows you to easily generate complete RAP business objects which are defined in a JSON file and showcases what is now possible with the XCO Library on the SAP Cloud Platform ABAP Environment.