How to maintain system configuration data in SAP BTP
2023-12-8 17:27:38 Author: blogs.sap.com(查看原文) 阅读量:9 收藏

For a multi tenant application, system configuration data is stored in cross-client tables with data class “S”. See also the multitenancy development guideline.

Read this blog post to learn how to maintain system configuration data with an executable class.

This blog is relevant for:

  • SAP BTP, ABAP Environment

You can use the following system table as an example:

@EndUserText.label : 'S table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #S
@AbapCatalog.dataMaintenance : #ALLOWED
define table zstab {
  key name : abap.char(30) not null;
  value    : abap.char(30);
}

You create an executable class that modifies the table data and records the changes in a workbench request.

CLASS zcl_option1 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun .
ENDCLASS.

CLASS zcl_option1 IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    DATA zstab_content TYPE TABLE OF zstab WITH EMPTY KEY.
    zstab_content = VALUE #( ( name = 'EEE' value = '555' ) ).
    MODIFY zstab FROM TABLE @zstab_content.
    DATA(transport_service) = cl_bcfg_cd_reuse_api_factory=>get_transport_service_instance(
       iv_objectname = 'ZSTAB'
       iv_objecttype = cl_bcfg_cd_reuse_api_factory=>simple_table ).
    TRY.
        transport_service->get_transport_recorder( )->add_tabu_content( zstab_content ).
        out->write( |Changes recorded in { transport_service->get_transport_request( )->get_task( ) }| ).
      CATCH cx_bcfg_transport_recorder
            cx_bcfg_transport_request INTO DATA(exc).
        out->write( exc->get_text( ) ).
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

The transport API automatically determines a workbench request. If none is found, a new one is created automatically.

You have the option to set a specific workbench request. However, this is only working if the workbench request has the attribute SAP_CUS_TRANSPORT_CATEGORY set to DEFAULT_CUSY or MANUAL_CUSY:

transport_service->get_transport_request( )->set_transport( <transport> ).
transport_service->get_transport_recorder( )->add_tabu_content( zstab_content ).

You can also use the XCO API to programmatically determine a workbench request:

"Create the filters to be used for the transport query.
"Additional filters can be added
DATA(request_type_filter) = xco_cp_transport=>filter->request_type( xco_cp_transport=>type->workbench_request ).
DATA(status_filter) = xco_cp_transport=>filter->status( xco_cp_transport=>status->modifiable ).
DATA(attribute_filter) = xco_cp_transport=>filter->attribute(
  io_name_constraint = xco_cp_abap_sql=>constraint->equal( 'SAP_CUS_TRANSPORT_CATEGORY' )
  io_value_constraint = xco_cp_abap_sql=>constraint->between( iv_low = 'DEFAULT_CUSY' iv_high = 'MANUAL_CUSY' )
).
"When querying transports via XCO_CP_CTS=>TRANSPORTS, both transport requests
"and tasks are retrieved. The "request" resolution applied below groups the retrieved tasks
"and requests so that only the list of transport requests is returned.
DATA(transports) = xco_cp_cts=>transports->where( VALUE #(
    ( attribute_filter )
    ( request_type_filter )
    ( status_filter )
  ) )->resolve( xco_cp_transport=>resolution->request ).

文章来源: https://blogs.sap.com/2023/12/08/how-to-maintain-system-configuration-data-in-sap-btp/
如有侵权请联系:admin#unsafe.sh