Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
umtyzc
Participant
Summary

One of the most influential libraries recently introduced by SAP is XCO. After trying andre.fischer 's RAP Generator, I came across it when I researched the technology it uses in the background. It's really a great library that provides a lot of product development possibilities and the ability to automate a lot of ABAP developments and new development methodologies such as RAP.

Purpose

In this article, I will show you how to quickly create a domain, data element, and table using this library. The purpose of this article is to make the XCO library easy to understand. It is also to provide practical examples for those who want to write "RAP Generator-like" applications using this library.

What will you learn?



Most of the time we-developers- start developing  ABAP programs by creating domains, data elements that use them, and tables that use these data elements. Sometimes this number gets too big.


In this example I will show you simply copying an existing domain using the XCO library, then using this domain in a data element, and then 🙂 using this data element in a table.


Thanks Andre Fischer to has proven us how this simple example can be turned into a great product and application.


Check out RAP Generator.


 




Introduction

"The XCO library is organized as a collection of (largely) independent modules (corresponding to ABAP packages). The public API of each module is exposed via a special class, called the API “class” of the module. It is distinguished from all other XCO classes and interfaces in that it starts with “XCO_CP_”. The API class acts as the single point of entry for the functionality offered by a given module."


"Starting with the API class, code completion can be used to easily discover the scope of a given module."


"The prerequisite for building and executing operations is a generation environment. A generation environment is backed by a transport which must be in status ‘Modifiable’ and is obtained via the XCO_CP_GENERATION API.

You can reach the "Core Principles" details about XCO Library here.

 



Example

1- Create a package






2- Create a class


3- In method implementation, we will create our objects in a chained way using our XCO library.

co_package = "Our Package Name to contain created objects."

lo_transport_target = We use 'xco_cp_abap_repository' module to "Transport Target".

lo_transport_request = We use 'xco_cp_cts' module to create "Transport Request"


xo_cp_generation_environment = After we prepared the package and transport configs, we will create a "put operation" to execute all objects.


Note: If you want to see more detail about all modules in XCO, please check Overview of XCO Modules.


CLASS zcl_generate_dictionary IMPLEMENTATION.


METHOD if_oo_adt_classrun~main.

CONSTANTS:
co_package TYPE sxco_package VALUE 'ZXCO_EXAMPLES'.

DATA(lo_transport_target) = xco_cp_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 copied domains to the PUT operation.
DATA(lo_template) = xco_cp_generation_doma=>template->for_domain(
iv_name = '/DMO/CUSTOMER_ID'
io_read_state = xco_cp_abap_dictionary=>object_read_state->active_version
).

lo_put_operation->for-doma->add_object( 'ZCOPIEDID_DOMAIN'
)->set_package( 'ZXCO_EXAMPLES'
)->set_template( lo_template ).

"Add data elements(with copied domain) to the PUT operation.

DATA(lo_specification) = lo_put_operation->for-dtel->add_object( 'ZDATA_ELEMENT'
)->set_package( 'ZXCO_EXAMPLES'
)->create_form_specification( ).
lo_specification->set_short_description( 'My generated data element with XCO' ).

lo_specification->set_data_type( xco_cp_abap_dictionary=>domain( 'ZCOPIEDID_DOMAIN' ) ).
lo_specification->field_label-short->set_text( 'ID' ).
lo_specification->field_label-medium->set_text( 'New ID' ).
lo_specification->field_label-long->set_text( 'New User identifier' ).
lo_specification->field_label-heading->set_text( 'New User identifier' ).

" Add the database table and data elements to the PUT operation.
DATA(lo_database_table) = lo_put_operation->for-tabl-for-database_table->add_object( 'ZTBL_XCO_EXAMPLE'
)->set_package( co_package
)->create_form_specification( ).
lo_database_table->set_short_description( 'My generated database table with XCO' ).
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( 'MANDT'
)->set_key_indicator(
)->set_type( xco_cp_abap_dictionary=>built_in_type->clnt
)->set_not_null( ).

lo_database_table->add_field( 'ID'
)->set_key_indicator(
)->set_type( xco_cp_abap_dictionary=>data_element( 'ZDATA_ELEMENT' )
)->set_not_null( ).

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

lo_put_operation->execute( ).

ENDMETHOD.
ENDCLASS.




When "put_operation" execute, it creates all objects at once.❤️😊



Output





References



Related Blogs and Projects

https://blogs.sap.com/2020/09/21/introducing-the-xco-library-cloud-platform-edition/

https://github.com/SAP-samples/cloud-abap-rap

https://github.com/SAP-samples/abap-file-uploader


Please submit questions in the respective Q&A area in SAP Community.





Labels in this area