SAP使用XCO框架创建RAP所有对象

最近头都要忙掉了,先备份一下之前写的测试代码,后面有空再整理相关其他内容吧

*&---------------------------------------------------------------------*
*& Report ZDEMO_XCO_GEN_DOMA
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zdemo_xco_gen_obj NO STANDARD PAGE HEADING.

DATA(gv_overwrite) = abap_true.
DATA(gv_transport) = CONV sxco_transport( 'DM2K900325' ).
DATA(gv_package) = CONV sxco_package('ZTEST_XCO_GEN').

"Generate Domain
PERFORM gen_doma.

"Generate Data element
PERFORM gen_dtel.

"Generate Table
PERFORM gen_tabl.

"Generate Draft Table
PERFORM gen_tabl_draft.

"Generate CDS(interface view & projection view)
PERFORM gen_ddls.

"Generate Metadata extension
PERFORM gen_ddlx.

"Generate Behavior Definitions
PERFORM gen_bdef.

"Generate Behavior Definitions implementation Class
PERFORM gen_clas.

"Generate Service Defination
PERFORM gen_srvd.

"Generate Service Binding
PERFORM gen_srvb.
*&---------------------------------------------------------------------*
*& Form gen_doma
*&---------------------------------------------------------------------*
*& Generate Domain
*&---------------------------------------------------------------------*
FORM gen_doma .
  DATA(lv_doma_name) = CONV sxco_ad_object_name( 'ZDTEST1' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.
  DATA lo_mass_patch_operation TYPE REF TO if_xco_gen_o_patch_mass.

  DATA(lv_exist_flg) = xco_abap_dictionary=>domain( lv_doma_name )->exists( ).

  IF lv_exist_flg = abap_false OR gv_overwrite = abap_true.
    lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

    DATA(lo_create_specification) = lo_mass_put_operation->for-doma->add_object( lv_doma_name
      )->set_package( gv_package )->create_form_specification( ).

    lo_create_specification->set_short_description('Test created by xco').

    lo_create_specification->set_format( xco_abap_dictionary=>built_in_type->char( 10 ) ).

    lo_create_specification->fixed_values->add_fixed_value( '10' )->set_description('Test domain value 1').
    lo_create_specification->fixed_values->add_fixed_value( '20' )->set_description('Test domain value 2').

    TRY.
        lo_mass_put_operation->execute( ).

        WRITE:`Domain: 'ZDTEST1' create successful`.NEW-LINE.
        NEW-LINE.
      CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
        WRITE:`Domain: `,put_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ELSE.
    lo_mass_patch_operation = xco_generation=>environment->transported( gv_transport )->create_mass_patch_operation( ).

    DATA(lo_update_specification) = lo_mass_patch_operation->for-doma->add_object( lv_doma_name
      )->create_change_specification( ).

    lo_update_specification->for-update->set_short_description('Test changed by xco').

    lo_update_specification->for-update->set_format( xco_abap_dictionary=>built_in_type->char( 20 ) ).

    lo_update_specification->for-update->add_fixed_value( '10' )->set_description('Test domain value 1 -changed').

    TRY.
        lo_mass_patch_operation->execute( ).

        WRITE:`Domain: 'ZDTEST1' update successful`.NEW-LINE.
      CATCH cx_xco_gen_patch_exception INTO DATA(patch_exp).
        WRITE:`Domain: `,patch_exp->get_text( ).NEW-LINE.
        lt_err_details = patch_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_dtel
*&---------------------------------------------------------------------*
*& Generate Data element
*&---------------------------------------------------------------------*
FORM gen_dtel .
  DATA(lv_dtel_name) = CONV sxco_ad_object_name( 'ZETEST1' ).
  DATA(lv_doma_name) = CONV sxco_ad_object_name( 'ZDTEST1' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.
  DATA lo_mass_patch_operation TYPE REF TO if_xco_gen_o_patch_mass.

  DATA(lv_exist_flg) = xco_abap_dictionary=>data_element( lv_dtel_name )->exists( ).

  IF lv_exist_flg = abap_false OR gv_overwrite = abap_true.
    lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

    DATA(lo_create_specification) = lo_mass_put_operation->for-dtel->add_object( lv_dtel_name
      )->set_package( gv_package )->create_form_specification( ).

    lo_create_specification->set_short_description( 'Test created by xco' ).

    "Use domain
    lo_create_specification->set_data_type( xco_abap_dictionary=>domain( lv_doma_name ) ).

    "Or you can use built-in type
*    lo_create_specification->set_data_type( xco_abap_dictionary=>built_in_type->char( 20 ) ).

    lo_create_specification->field_label-short->set_text( 'Short text' )->set_length( 10 ).
    lo_create_specification->field_label-medium->set_text( 'medium text' )->set_length( 20 ).
    lo_create_specification->field_label-long->set_text( 'long text' )->set_length( 40 ).
    lo_create_specification->field_label-heading->set_text( 'heading text' )->set_length( 20 ).

    TRY.
        lo_mass_put_operation->execute( ).

        WRITE:`DateElement: 'ZETEST1' create successful`.NEW-LINE.
      CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
        WRITE:`DateElement: `,put_exp->get_longtext( ).NEW-LINE.
        DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ELSE.
    lo_mass_patch_operation = xco_generation=>environment->transported( gv_transport )->create_mass_patch_operation( ).

    DATA(lo_update_specification) = lo_mass_patch_operation->for-dtel->add_object( lv_dtel_name
      )->create_change_specification( ).

    lo_update_specification->for-update->set_short_description( 'Test changed by xco' ).

    lo_update_specification->for-update->field_label-medium->set_text( 'medium text -changed' )->set_length( 20 ).

    TRY.
        lo_mass_patch_operation->execute( ).

        WRITE:`DateElement: 'ZETEST1' update successful`.NEW-LINE.
      CATCH cx_xco_gen_patch_exception INTO DATA(patch_exp).
        WRITE:`DateElement: `,patch_exp->get_text( ).NEW-LINE.
        lt_err_details = patch_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_tabl
*&---------------------------------------------------------------------*
*& Generate Table
*&---------------------------------------------------------------------*
FORM gen_tabl .
  DATA(lv_tabl_name) = CONV sxco_dbt_object_name( 'ZTTEST_XCO' ).
  DATA(lv_dtel_name) = CONV sxco_ad_object_name( 'ZETEST1' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.
  DATA lo_mass_patch_operation TYPE REF TO if_xco_gen_o_patch_mass.

  DATA(lv_exist_flg) = xco_abap_dictionary=>table( 'ZTTEST_XCO' )->exists( ).

  IF lv_exist_flg = abap_false OR gv_overwrite = abap_true.
    lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

    DATA(lo_create_specification) = lo_mass_put_operation->for-tabl-for-database_table->add_object( lv_tabl_name
      )->set_package( gv_package )->create_form_specification( ).

    lo_create_specification->set_short_description('Test created by xco').
    lo_create_specification->set_delivery_class( xco_database_table=>delivery_class->a ).
    lo_create_specification->set_data_maintenance( xco_database_table=>data_maintenance->allowed ).

    lo_create_specification->add_field( 'MANDT' )->set_type( xco_abap_dictionary=>data_element( 'MANDT' )
          )->set_key_indicator(
          )->set_not_null( ).
    DATA(lo_id) = lo_create_specification->add_field( 'ID' )->set_type( xco_abap_dictionary=>data_element( 'SYSUUID_X16' )
      )->set_key_indicator(
      )->set_not_null( ).
    lo_create_specification->add_field( 'START_DATE' )->set_type( xco_abap_dictionary=>built_in_type->dats ).
    lo_create_specification->add_field( 'END_DATE' )->set_type( xco_abap_dictionary=>built_in_type->dats ).
    lo_create_specification->add_field( 'ZTEST' )->set_type( xco_abap_dictionary=>data_element( lv_dtel_name ) ).
    lo_create_specification->add_field( 'IS_ACTIVE' )->set_type( xco_abap_dictionary=>data_element( 'ABAP_BOOLEAN' ) ).
    lo_create_specification->add_field( 'AMOUNT' )->set_type( xco_abap_dictionary=>data_element( 'WRBTR' )
      )->currency_quantity->set_reference_table( 'ZTTEST_XCO' )->set_reference_field( 'CURRENCY' ).
    lo_create_specification->add_field( 'CURRENCY' )->set_type( xco_abap_dictionary=>data_element( 'CURRENCY' ) ).
    lo_create_specification->add_field( 'CREATED_BY' )->set_type( xco_abap_dictionary=>data_element( 'ABP_CREATION_USER' ) ).
    lo_create_specification->add_field( 'CREATED_AT' )->set_type( xco_abap_dictionary=>data_element( 'ABP_CREATION_TSTMPL' ) ).
    lo_create_specification->add_field( 'LOCAL_LAST_CHANGED_BY' )->set_type( xco_abap_dictionary=>data_element( 'ABP_LOCINST_LASTCHANGE_USER' ) ).
    lo_create_specification->add_field( 'LOCAL_LAST_CHANGED_AT' )->set_type( xco_abap_dictionary=>data_element( 'ABP_LOCINST_LASTCHANGE_TSTMPL' ) ).

    TRY.
        lo_mass_put_operation->execute( ).

        WRITE:`Table: 'ZTTEST_XCO' create successful`.NEW-LINE.
        NEW-LINE.
      CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
        WRITE:`Table: `,put_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ELSE.
    lo_mass_patch_operation = xco_generation=>environment->transported( gv_transport )->create_mass_patch_operation( ).

    DATA(lo_update_specification) = lo_mass_patch_operation->for-tabl-for-database_table->add_object( lv_tabl_name
      )->create_change_specification( ).

    lo_update_specification->for-update->add_field( 'ZTEST' )->set_type( xco_abap_dictionary=>data_element( 'WRBTR' )
      )->currency_quantity->set_reference_table( 'ZTTEST_XCO' )->set_reference_field( 'CURRENCY' ).

    TRY.
        lo_mass_patch_operation->execute( ).

        WRITE:`Table: 'ZTTEST_XCO' update successful`.NEW-LINE.
      CATCH cx_xco_gen_patch_exception INTO FINAL(patch_exp).
        WRITE:`Table: `,patch_exp->get_message( )->get_text( ).NEW-LINE.
        lt_err_details = patch_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_tabl_draft
*&---------------------------------------------------------------------*
*& Generate Draft Table
*&---------------------------------------------------------------------*
FORM gen_tabl_draft .
  DATA(lv_tabl_name) = CONV sxco_dbt_object_name( 'ZTTEST_XCO_D' ).
  DATA(lv_dtel_name) = CONV sxco_ad_object_name( 'ZETEST1' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.
  DATA lo_mass_patch_operation TYPE REF TO if_xco_gen_o_patch_mass.

  DATA(lv_exist_flg) = xco_abap_dictionary=>table( 'ZTTEST_XCO_D' )->exists( ).

  IF lv_exist_flg = abap_false OR gv_overwrite = abap_true.
    lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

    DATA(lo_create_specification) = lo_mass_put_operation->for-tabl-for-database_table->add_object( lv_tabl_name
      )->set_package( gv_package )->create_form_specification( ).

    lo_create_specification->set_short_description('Test created by xco -draft table').
    lo_create_specification->set_delivery_class( xco_database_table=>delivery_class->a ).
    lo_create_specification->set_data_maintenance( xco_database_table=>data_maintenance->allowed_with_restrictions ).
    lo_create_specification->set_enhancement_category( xco_table=>enhancement_category->extensible_any ).

    "Notice: Draft table field name should same with interface view
    lo_create_specification->add_field( 'MANDT' )->set_type( xco_abap_dictionary=>data_element( 'MANDT' )
          )->set_key_indicator(
          )->set_not_null( ).
    DATA(lo_id) = lo_create_specification->add_field( 'ID' )->set_type( xco_abap_dictionary=>data_element( 'SYSUUID_X16' )
      )->set_key_indicator(
      )->set_not_null( ).
    lo_create_specification->add_field( 'STARTDATE' )->set_type( xco_abap_dictionary=>built_in_type->dats ).
    lo_create_specification->add_field( 'ENDDATE' )->set_type( xco_abap_dictionary=>built_in_type->dats ).
    lo_create_specification->add_field( 'TESTFIELD' )->set_type( xco_abap_dictionary=>data_element( lv_dtel_name ) ).
    lo_create_specification->add_field( 'ISACTIVE' )->set_type( xco_abap_dictionary=>data_element( 'ABAP_BOOLEAN' ) ).
    lo_create_specification->add_field( 'AMOUNT' )->set_type( xco_abap_dictionary=>data_element( 'WRBTR' )
      )->currency_quantity->set_reference_table( 'ZTTEST_XCO_D' )->set_reference_field( 'CURRENCY' ).
    lo_create_specification->add_field( 'CURRENCY' )->set_type( xco_abap_dictionary=>data_element( 'CURRENCY' ) ).
    lo_create_specification->add_field( 'CREATEDBY' )->set_type( xco_abap_dictionary=>data_element( 'ABP_CREATION_USER' ) ).
    lo_create_specification->add_field( 'CREATEDAT' )->set_type( xco_abap_dictionary=>data_element( 'ABP_CREATION_TSTMPL' ) ).
    lo_create_specification->add_field( 'LOCALLASTCHANGEDBY' )->set_type( xco_abap_dictionary=>data_element( 'ABP_LOCINST_LASTCHANGE_USER' ) ).
    lo_create_specification->add_field( 'LOCALLASTCHANGEDAT' )->set_type( xco_abap_dictionary=>data_element( 'ABP_LOCINST_LASTCHANGE_TSTMPL' ) ).

    "Add draft control fields
    lo_create_specification->add_include( )->set_structure( 'SYCH_BDL_DRAFT_ADMIN_INC' )->set_group_name( '%ADMIN' ).

    TRY.
        lo_mass_put_operation->execute( ).

        WRITE:`Draft Table: 'ZTTEST_XCO_D' create successful`.NEW-LINE.
        NEW-LINE.
      CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
        WRITE:`Draft Table: `,put_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ELSE.
    lo_mass_patch_operation = xco_generation=>environment->transported( gv_transport )->create_mass_patch_operation( ).

    DATA(lo_update_specification) = lo_mass_patch_operation->for-tabl-for-database_table->add_object( lv_tabl_name
      )->create_change_specification( ).

    lo_update_specification->for-update->add_field( 'ZTEST' )->set_type( xco_abap_dictionary=>data_element( 'WRBTR' )
      )->currency_quantity->set_reference_table( 'ZTTEST_XCO' )->set_reference_field( 'CURRENCY' ).

    TRY.
        lo_mass_patch_operation->execute( ).

        WRITE:`Draft Table: 'ZTTEST_XCO_D' update successful`.NEW-LINE.
      CATCH cx_xco_gen_patch_exception INTO FINAL(patch_exp).
        WRITE:`Draft Table: `,patch_exp->get_message( )->get_text( ).NEW-LINE.
        lt_err_details = patch_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_ddls
*&---------------------------------------------------------------------*
*& Generate CDS(interface view & consumption view)
*&---------------------------------------------------------------------*
FORM gen_ddls .
  DATA(lv_ddls_i_name) = CONV sxco_cds_object_name( 'ZI_TEST_XCO' ).
  DATA(lv_ddls_c_name) = CONV sxco_cds_object_name( 'ZC_TEST_XCO' ).
  DATA(lv_tabl_name) = CONV sxco_dbt_object_name( 'ZTTEST_XCO' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.
  DATA lo_mass_patch_operation TYPE REF TO if_xco_gen_o_patch_mass.

  DATA(lv_exist_flg) = xco_cds=>view_entity( lv_ddls_i_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-ddls->create_delete_operation( ).
    lo_delete_operation->add_object( lv_ddls_i_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
        WRITE:`CDS interface view delete exception: `,delete_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.

    CLEAR lv_exist_flg.
  ENDIF.

  lv_exist_flg = xco_cds=>view_entity( lv_ddls_c_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    lo_delete_operation = xco_generation=>environment->transported( gv_transport )->for-ddls->create_delete_operation( ).
    lo_delete_operation->add_object( lv_ddls_c_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO delete_exp.
        WRITE:`CDS interface view delete exception: `,delete_exp->get_text( ).NEW-LINE.
        lt_err_details = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
    CLEAR lv_exist_flg.
  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

************************************************************************
  "Add interface view
  DATA(lo_i_create_specification) = lo_mass_put_operation->for-ddls->add_object( lv_ddls_i_name
    )->set_package( gv_package )->create_form_specification( ).

  DATA(lo_view_entity) = lo_i_create_specification->set_short_description('Test created by xco -interface view'
    )->add_view_entity( ).

  lo_view_entity->set_root( )->data_source->set_view_entity( CONV #( lv_tabl_name ) ).

  "you can add where condtion like this:
*  lo_view_entity->set_where( xco_cp_ddl=>field( 'is_active' )->eq( xco_cp_ddl=>literal->character( 'X' ) ) ).

  "View annotations.
  lo_view_entity->add_annotation( 'AccessControl.authorizationCheck' )->value->build( )->add_enum( 'NOT_REQUIRED' ).
  lo_view_entity->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Test created by xco -interface view' ).
  lo_view_entity->add_annotation( 'Metadata.allowExtensions' )->value->build( )->add_boolean( abap_true ).

  "Add Key fields.
  DATA(lo_id) = lo_view_entity->add_field( xco_cp_ddl=>field( 'id' ) )->set_key( )->set_alias( 'ID' ).
  lo_id->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'ID' ).

  "Add entity fields
  lo_view_entity->add_field( xco_cp_ddl=>field( 'start_date' ) )->set_alias( 'StartDate' ).
  lo_view_entity->add_field( xco_cp_ddl=>field( 'end_date' ) )->set_alias( 'EndDate' ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'ztest' ) )->set_alias( 'TestField' ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'is_active' ) )->set_alias( 'IsActive' ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'amount' ) )->set_alias( 'Amount'
    )->add_annotation( 'Semantics.amount.currencyCode' )->value->build( )->add_string( 'Currency' ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'currency' ) )->set_alias( 'Currency' ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'created_by' ) )->set_alias( 'CreatedBy'
    )->add_annotation( 'Semantics.user.createdBy' )->value->build( )->add_boolean( abap_true ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'created_at' ) )->set_alias( 'CreatedAt'
  )->add_annotation( 'Semantics.systemDateTime.createdAt' )->value->build( )->add_boolean( abap_true ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'local_last_changed_by' ) )->set_alias( 'LocalLastChangedBy'
  )->add_annotation( 'Semantics.user.localInstanceLastChangedBy' )->value->build( )->add_boolean( abap_true ).

  lo_view_entity->add_field( xco_cp_ddl=>field( 'local_last_changed_at' ) )->set_alias( 'LocalLastChangedAt'
  )->add_annotation( 'Semantics.systemDateTime.lastChangedAt' )->value->build( )->add_boolean( abap_true ).

************************************************************************
  "Add consumption view
  DATA(lo_c_create_specification) = lo_mass_put_operation->for-ddls->add_object( lv_ddls_c_name
    )->set_package( gv_package )->create_form_specification( ).

  DATA(lo_projection_view) = lo_c_create_specification->set_short_description('Test created by xco -consumption view'
    )->add_projection_view( ).

  lo_projection_view->set_root( )->data_source->set_view_entity( lv_ddls_i_name ).
  lo_projection_view->set_provider_contract( xco_cp_cds=>provider_contract->transactional_query ).

  "View annotations.
  lo_projection_view->add_annotation( 'AccessControl.authorizationCheck' )->value->build( )->add_enum( 'NOT_REQUIRED' ).
  lo_projection_view->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Test created by xco -consumption view' ).
  lo_projection_view->add_annotation( 'Metadata.allowExtensions' )->value->build( )->add_boolean( abap_true ).

  "Add Key fields.
  lo_projection_view->add_field( xco_cp_ddl=>field( 'ID' ) )->set_key(
    )->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'ID' ).

  "Add entity fields
  lo_projection_view->add_field( xco_cp_ddl=>field( 'StartDate' )
    )->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Start Date' ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'EndDate' )
    )->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'End Date' ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'TestField' )
    )->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Test Field' ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'IsActive' ) ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'Amount' )
    )->add_annotation( 'Semantics.amount.currencyCode' )->value->build( )->add_string( 'Currency' ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'Currency' ) ).

  lo_projection_view->add_field( xco_cp_ddl=>field( 'CreatedBy' ) ).
  lo_projection_view->add_field( xco_cp_ddl=>field( 'CreatedAt' ) ).
  lo_projection_view->add_field( xco_cp_ddl=>field( 'LocalLastChangedBy' ) ).
  lo_projection_view->add_field( xco_cp_ddl=>field( 'LocalLastChangedAt' ) ).

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`CDS interface view: 'ZI_TEST_XCO' create successful`.NEW-LINE.
      WRITE:`CDS consumption view: 'ZC_TEST_XCO' create successful`.NEW-LINE.
      NEW-LINE.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`CDS interface view | CDS consumption view : `,put_exp->get_text( ).NEW-LINE.
      lt_err_details = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO ls_err_details.
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_ddlx
*&---------------------------------------------------------------------*
*& Generate Metadata extension
*&---------------------------------------------------------------------*
FORM gen_ddlx .
  TYPES:
    BEGIN OF ts_field,
      name       TYPE sxco_cds_field_name,
      line_label TYPE string,
      line_pos   TYPE sy-tabix,
      iden_pos   TYPE sy-tabix,
      sele_pos   TYPE sy-tabix,
    END OF ts_field,
    tt_field TYPE STANDARD TABLE OF ts_field WITH EMPTY KEY.

  DATA(lt_fields) = VALUE tt_field(
      ( name = 'ID'        line_label = '' line_pos = 10 iden_pos = 10 sele_pos = 10 )
      ( name = 'StartDate' line_label = '' line_pos = 20 iden_pos = 20 sele_pos = 20 )
      ( name = 'EndDate'   line_label = '' line_pos = 30 iden_pos = 30 sele_pos = 30 )
      ( name = 'TestField' line_label = '' line_pos = 40 )
      ( name = 'IsActive'  line_label = '' line_pos = 50 )
      ( name = 'Amount'    line_label = '' line_pos = 60 )
      ( name = 'Currency'  line_label = '' line_pos = 70 )
    ).

  DATA(lv_ddls_c_name) = CONV sxco_cds_object_name( 'ZC_TEST_XCO' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.

  DATA(lv_exist_flg) = xco_cds=>metadata_extension( lv_ddls_c_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-ddlx->create_delete_operation( ).
    lo_delete_operation->add_object( lv_ddls_c_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
        WRITE:`Metadata extension delete exception: `,delete_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

  DATA(lo_create_specification) = lo_mass_put_operation->for-ddlx->add_object( lv_ddls_c_name
    )->set_package( gv_package )->create_form_specification( ).

  lo_create_specification->set_short_description('Test created by xco -ddlx'
    )->set_layer( xco_cp_metadata_extension=>layer->customer
    )->set_view( lv_ddls_c_name ).

  LOOP AT lt_fields INTO DATA(ls_fields).
    DATA(lo_field) = lo_create_specification->add_field( ls_fields-name ).

    "   Add facet at first field
    IF ls_fields-line_pos = 10.
      "@UI.facet:
      DATA(lo_build) = lo_field->add_annotation( 'UI.facet' )->value->build( ).

      "[{
      lo_build->begin_array( )->begin_record( ).

      "id: 'Head'
      lo_build->add_member( 'id' )->add_string( 'Head' ).

      "purpose: #STANDARD
      lo_build->add_member( 'purpose' )->add_enum( 'STANDARD' ).

      "position: 10
      lo_build->add_member( 'position' )->add_number( 10 ).

      "type:#IDENTIFICATION_REFERENCE
      lo_build->add_member( 'type' )->add_enum( 'IDENTIFICATION_REFERENCE' ).

      "label: 'Test head facet'
      lo_build->add_member( 'label' )->add_string( 'Test head facet' ).

      "}]
      lo_build->end_record( )->end_array( ).
    ENDIF.

    IF ls_fields-line_pos IS NOT INITIAL.
      "@UI.lineItem:
      lo_build = lo_field->add_annotation( 'UI.lineItem' )->value->build( ).

      "[{
      lo_build->begin_array( )->begin_record( ).

      "position: 10
      lo_build->add_member( 'position' )->add_number( ls_fields-line_pos ).

      "label: ''
      IF ls_fields-line_label IS NOT INITIAL.
        lo_build->add_member( 'label' )->add_string( ls_fields-line_label ).
      ENDIF.

      "}]
      lo_build->end_record( )->end_array( ).
    ENDIF.

    IF ls_fields-iden_pos IS NOT INITIAL.
      "@UI.identification:
      lo_build = lo_field->add_annotation( 'UI.identification' )->value->build( ).

      "[{
      lo_build->begin_array( )->begin_record( ).

      "position: 10
      lo_build->add_member( 'position' )->add_number( ls_fields-iden_pos ).

      "}]
      lo_build->end_record( )->end_array( ).
    ENDIF.

    IF ls_fields-sele_pos IS NOT INITIAL.
      "@UI.selectionField:
      lo_build = lo_field->add_annotation( 'UI.selectionField' )->value->build( ).

      "[{
      lo_build->begin_array( )->begin_record( ).

      "position: 10
      lo_build->add_member( 'position' )->add_number( ls_fields-sele_pos ).

      "}]
      lo_build->end_record( )->end_array( ).
    ENDIF.
  ENDLOOP.

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`Metadata extension: 'ZC_TEST_XCO' create successful`.NEW-LINE.
      NEW-LINE.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`Metadata extension: `,put_exp->get_text( ).NEW-LINE.
      lt_err_details = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO ls_err_details.
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_bdef
*&---------------------------------------------------------------------*
*& Generate Behavior Definitions
*&---------------------------------------------------------------------*
FORM gen_bdef .
  DATA(lv_bdef_i_name) = CONV sxco_cds_object_name( 'ZI_TEST_XCO' ).
  DATA(lv_bdef_c_name) = CONV sxco_cds_object_name( 'ZC_TEST_XCO' ).
  DATA(lv_ddls_i_name) = CONV sxco_cds_object_name( 'ZI_TEST_XCO' ).
  DATA(lv_ddls_c_name) = CONV sxco_cds_object_name( 'ZC_TEST_XCO' ).
  DATA(lv_tabl_name) = CONV sxco_dbt_object_name( 'ZTTEST_XCO' ).
  DATA(lv_draft_tabl_name) = CONV sxco_dbt_object_name( 'ZTTEST_XCO_D' ).
  DATA(lv_etag_field_name) = CONV sxco_cds_field_name( 'LocalLastChangedAt' ).
  DATA(lv_clas_i_name) = CONV sxco_ao_object_name( 'ZCL_TEST_XCO_IMP' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.

  DATA(lv_exist_flg) = xco_cds=>behavior_definition( lv_bdef_i_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-bdef->create_delete_operation( ).
    lo_delete_operation->add_object( lv_bdef_i_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
        WRITE:`Behavior Definitions delete exception: `,delete_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.

  CLEAR lv_exist_flg.
  lv_exist_flg = xco_cds=>behavior_definition( lv_bdef_c_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    lo_delete_operation = xco_generation=>environment->transported( gv_transport )->for-bdef->create_delete_operation( ).
    lo_delete_operation->add_object( lv_bdef_c_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO delete_exp.
        WRITE:`Behavior Projection delete exception: `,delete_exp->get_text( ).NEW-LINE.
        lt_err_details = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO ls_err_details.
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

************************************************************************
  "Create behavior defination
  DATA(lo_i_create_specification) = lo_mass_put_operation->for-bdef->add_object( lv_bdef_i_name
    )->set_package( gv_package )->create_form_specification( ).

  lo_i_create_specification->set_short_description('Test created by xco -bdef_i'
    )->set_implementation_type( xco_cp_behavior_definition=>implementation_type->managed
    )->set_implementation_class( lv_clas_i_name
    )->set_strict_n( 2
    )->set_draft_enabled( ).

  "Characteristics
  DATA(lo_interface_behavior) = lo_i_create_specification->add_behavior( lv_ddls_i_name ).

  lo_interface_behavior->characteristics->set_alias( 'TestBDEF' ).
  lo_interface_behavior->characteristics->set_persistent_table( lv_tabl_name ).
  lo_interface_behavior->characteristics->set_draft_table( lv_draft_tabl_name ).
  lo_interface_behavior->characteristics->set_with_additional_save( ).
  lo_interface_behavior->characteristics->lock->set_master( )->set_master_total_etag( lv_etag_field_name ).
  lo_interface_behavior->characteristics->authorization->set_master_instance( ).

  "Standard operations.
  lo_interface_behavior->add_standard_operation( xco_cp_behavior_definition=>standard_operation->create ).
  lo_interface_behavior->add_standard_operation( xco_cp_behavior_definition=>standard_operation->update ).
  lo_interface_behavior->add_standard_operation( xco_cp_behavior_definition=>standard_operation->delete ).

  "Field
  lo_interface_behavior->add_field( 'ID' )->set_readonly_update( ).

  "Action
  lo_interface_behavior->add_action( 'TestAction' )->result->set_cardinality( xco_cp_cds=>cardinality->one )->set_self( ).

  "Draft action
  lo_interface_behavior->add_action( 'Edit' )->set_draft( ).
  lo_interface_behavior->add_action( 'Activate' )->set_draft( )->set_optimized( ).
  lo_interface_behavior->add_action( 'Discard' )->set_draft( ).
  lo_interface_behavior->add_action( 'Resume' )->set_draft( ).
  lo_interface_behavior->add_action( 'Prepare' )->set_draft( )->set_determine( ).

  "Mapping
  lo_interface_behavior->add_mapping_for( lv_tabl_name )->set_field_mapping(
    VALUE #(
      ( cds_view_field = 'ID'                 dbtable_field = 'id' )
      ( cds_view_field = 'StartDate'          dbtable_field = 'start_date' )
      ( cds_view_field = 'EndDate'            dbtable_field = 'end_date' )
      ( cds_view_field = 'TestField'          dbtable_field = 'ztest' )
      ( cds_view_field = 'IsActive'           dbtable_field = 'is_active' )
      ( cds_view_field = 'Amount'             dbtable_field = 'amount' )
      ( cds_view_field = 'Currency'           dbtable_field = 'currency' )
      ( cds_view_field = 'CreatedBy'          dbtable_field = 'created_by' )
      ( cds_view_field = 'CreatedAt'          dbtable_field = 'created_at' )
      ( cds_view_field = 'LocalLastChangedBy' dbtable_field = 'local_last_changed_by' )
      ( cds_view_field = 'LocalLastChangedAt' dbtable_field = 'local_last_changed_at' )
    )
  ).

************************************************************************
  "Create behavior projection
  DATA(lo_c_create_specification) = lo_mass_put_operation->for-bdef->add_object( lv_bdef_c_name
      )->set_package( gv_package )->create_form_specification( ).

  lo_c_create_specification->set_short_description('Test created by xco -bdef_c'
    )->set_implementation_type( xco_cp_behavior_definition=>implementation_type->projection
    )->set_strict_n( 2
    )->set_use_draft( ).

  "Characteristics
  DATA(lo_consumption_behavior) = lo_c_create_specification->add_behavior( lv_ddls_c_name ).

  "Standard operations
  lo_consumption_behavior->add_standard_operation( xco_behavior_definition=>standard_operation->create
     )->set_use( ).
  lo_consumption_behavior->add_standard_operation( xco_behavior_definition=>standard_operation->update
    )->set_use( ).
  lo_consumption_behavior->add_standard_operation( xco_behavior_definition=>standard_operation->delete
    )->set_use( ).

  "Action
  lo_consumption_behavior->add_action( 'TestAction' )->set_use( ).

  "Draft action
  lo_consumption_behavior->add_action( 'Edit' )->set_use( ).
  lo_consumption_behavior->add_action( 'Activate' )->set_use( ).
  lo_consumption_behavior->add_action( 'Discard' )->set_use( ).
  lo_consumption_behavior->add_action( 'Resume' )->set_use( ).
  lo_consumption_behavior->add_action( 'Prepare' )->set_use( ).

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`Behavior Definitions: 'ZI_TEST_XCO' create successful`.NEW-LINE.
      WRITE:`Behavior Projection: 'ZC_TEST_XCO' create successful`.NEW-LINE.
      NEW-LINE.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`Behavior Definitions | Behavior Projection: `,put_exp->get_text( ).NEW-LINE.
      lt_err_details = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO ls_err_details.
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_clas
*&---------------------------------------------------------------------*
*& Generate Behavior Definitions implementation Class
*&---------------------------------------------------------------------*
FORM gen_clas .
  DATA(lv_clas_i_name) = CONV sxco_ao_object_name( 'ZCL_TEST_XCO_IMP' ).
  DATA(lv_bdef_i_name) = CONV sxco_cds_object_name( 'ZI_TEST_XCO' ).
  DATA(lv_ddls_i_name) = CONV sxco_cds_object_name( 'ZI_TEST_XCO' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.

  DATA(lv_exist_flg) = xco_abap=>class( lv_clas_i_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
  IF lv_exist_flg = abap_true.
    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-clas->create_delete_operation( ).
    lo_delete_operation->add_object( lv_clas_i_name ).
    TRY.
        lo_delete_operation->execute( ).
      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
        WRITE:`Behavior Definitions delete exception: `,delete_exp->get_text( ).NEW-LINE.
        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
        LOOP AT lt_err_details INTO DATA(ls_err_details).
          WRITE:ls_err_details->get_text( ).NEW-LINE.
        ENDLOOP.
    ENDTRY.
  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).

  DATA(lo_create_specification) = lo_mass_put_operation->for-clas->add_object( lv_clas_i_name
    )->set_package( gv_package )->create_form_specification( ).

  "Set class description
  lo_create_specification->set_short_description( 'Test created by xco -clas' ).

  "Definition public abstract for behavior
  lo_create_specification->definition->set_abstract( )->set_for_behavior_of( lv_bdef_i_name ).

************************************************************************
  "Definition local class
  DATA(lo_handler) = lo_create_specification->add_local_class( 'LCL_XCO_TEST' ).

  "Set inheriting from
  lo_handler->definition->set_superclass( 'CL_ABAP_BEHAVIOR_HANDLER' ).

*----------------------------------------------------------------------*
  "Add custom method
  DATA(lo_test_method_def) = lo_handler->definition->section-private->add_method( 'TEST' ).

  "Set for modify
  lo_test_method_def->behavior_implementation->set_for_modify(
    )->set_result( 'result' ).

  "Set importing parameters and for action
  lo_test_method_def->add_importing_parameter( 'keys'
    )->behavior_implementation->set_for_action(
      iv_entity_name = 'TestBDEF'
      iv_action_name = 'TestAction'
  ).

  "Create implementation method
  DATA(lo_test_method_imp) = lo_handler->implementation->add_method( 'test' ).

  "Set source code
  lo_test_method_imp->set_source(
    VALUE #( ( |"some logic here...| ) )
   ).
*----------------------------------------------------------------------*
  "Add instance authorizations method
  lo_test_method_def = lo_handler->definition->section-private->add_method( 'get_instance_authorizations' ).

  "Set for modify
  lo_test_method_def->behavior_implementation->set_for_instance_authorization(
    )->set_result( 'result' ).

  "Set importing parameters and for action
  lo_test_method_def->add_importing_parameter( 'keys'
    )->behavior_implementation->set_request( 'requested_authorizations'
    )->set_for( 'testBDEF' ).

  "Create implementation method
  lo_test_method_imp = lo_handler->implementation->add_method( 'get_instance_authorizations' ).

  "Set source code
  lo_test_method_imp->set_source(
    VALUE #( ( |"some logic here...| ) )
   ).
************************************************************************

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`Class: 'ZCL_TEST_XCO_IMP' create successful`.NEW-LINE.
      NEW-LINE.

      DATA(lt_check_syntax_msg) = xco_abap=>class( lv_clas_i_name )->check_syntax( )->if_xco_news~get_messages( ).

      LOOP AT lt_check_syntax_msg INTO DATA(ls_check_syntax_msg).
        WRITE:'warning:',ls_check_syntax_msg->get_text( ).NEW-LINE.
      ENDLOOP.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`Class: `,put_exp->get_text( ).NEW-LINE.
      lt_err_details = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO ls_err_details.
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_srvd
*&---------------------------------------------------------------------*
*& Generate Service Definition
*&---------------------------------------------------------------------*
FORM gen_srvd .
  DATA(lv_srvd_name) = CONV sxco_cds_object_name( 'ZSRVD_TEXT_XCO' ).
  DATA(lv_ddls_c_name) = CONV sxco_cds_object_name( 'ZC_TEST_XCO' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.

  DATA(lv_exist_flg) = xco_abap_repository=>object->srvd->for( lv_srvd_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
*  IF lv_exist_flg = abap_true.
*    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-srvd->create_delete_operation( ).
*    lo_delete_operation->add_object( lv_srvd_name ).
*    TRY.
*        lo_delete_operation->execute( ).
*      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
*        WRITE:`Service Defination delete exception: `,delete_exp->get_text( ).NEW-LINE.
*        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
*        LOOP AT lt_err_details INTO DATA(ls_err_details).
*          WRITE:ls_err_details->get_text( ).NEW-LINE.
*        ENDLOOP.
*    ENDTRY.
*  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).


  DATA(lo_create_specification) = lo_mass_put_operation->for-srvd->add_object( lv_srvd_name
      )->set_package( gv_package )->create_form_specification( ).

  lo_create_specification->set_short_description( 'Test created by xco -srvd' ).

  lo_create_specification->add_annotation( 'EndUserText.label' )->value->build( )->add_string( 'Test XCO gen service definition' ).
  lo_create_specification->add_annotation( 'ObjectModel.leadingEntity.name' )->value->build( )->add_string( 'ZC_TEST_XCO' ).
  lo_create_specification->add_exposure( lv_ddls_c_name ).

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`Service Defination: 'ZSRVD_TEXT_XCO' create successful`.NEW-LINE.
      NEW-LINE.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`Service Defination: `,put_exp->get_text( ).NEW-LINE.
      DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO DATA(ls_err_details).
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form gen_srvb
*&---------------------------------------------------------------------*
*& Generate Service Binding
*&---------------------------------------------------------------------*
FORM gen_srvb .
  DATA(lv_srvb_name) = CONV sxco_cds_object_name( 'ZSRVB_TEXT_XCO' ).
  DATA(lv_srvd_name) = CONV sxco_cds_object_name( 'ZSRVD_TEXT_XCO' ).
  DATA lo_mass_put_operation TYPE REF TO if_xco_gen_o_mass_put.

  DATA(lv_exist_flg) = xco_abap_repository=>object->srvb->for( lv_srvb_name )->exists( ).

  "If already exists, delete it first --OPTIONAL!
*  IF lv_exist_flg = abap_true.
*    DATA(lo_delete_operation) = xco_generation=>environment->transported( gv_transport )->for-srvb->create_delete_operation( ).
*    lo_delete_operation->add_object( lv_srvb_name ).
*    TRY.
*        lo_delete_operation->execute( ).
*      CATCH cx_xco_gen_delete_exception INTO DATA(delete_exp).
*        WRITE:`Service Binding delete exception: `,delete_exp->get_text( ).NEW-LINE.
*        DATA(lt_err_details) = delete_exp->findings->if_xco_news~get_messages( ).
*        LOOP AT lt_err_details INTO DATA(ls_err_details).
*          WRITE:ls_err_details->get_text( ).NEW-LINE.
*        ENDLOOP.
*    ENDTRY.
*  ENDIF.

  lo_mass_put_operation = xco_generation=>environment->transported( gv_transport )->create_mass_put_operation( ).


  DATA(lo_create_specification) = lo_mass_put_operation->for-srvb->add_object( lv_srvb_name
      )->set_package( gv_package )->create_form_specification( ).

  lo_create_specification->set_short_description( 'Test created by xco -srvb' ).

  lo_create_specification->set_binding_type( xco_cp_service_binding=>binding_type->odata_v4_ui ).
  lo_create_specification->add_service( )->add_version( '0001' )->set_service_definition( lv_srvd_name ).

  TRY.
      lo_mass_put_operation->execute( ).

      WRITE:`Service Binding: 'ZSRVB_TEXT_XCO' create successful`.NEW-LINE.
      NEW-LINE.

      DATA lo_operation TYPE REF TO if_xco_srvb_operation.
      DATA(lo_service_binding) = xco_abap_repository=>object->srvb->for( lv_srvb_name ).

      lo_operation = xco_service_binding=>local_service_endpoint->odata_v4->operation->publish( lo_service_binding ).

      lo_operation->execute( ).

      WRITE:`Service Binding: 'ZSRVB_TEXT_XCO' publish successful`.NEW-LINE.
      NEW-LINE.
    CATCH cx_xco_gen_put_exception INTO DATA(put_exp).
      WRITE:`Service Binding: `,put_exp->get_text( ).NEW-LINE.
      DATA(lt_err_details) = put_exp->findings->if_xco_news~get_messages( ).
      LOOP AT lt_err_details INTO DATA(ls_err_details).
        WRITE:ls_err_details->get_text( ).NEW-LINE.
      ENDLOOP.
  ENDTRY.
  SKIP.
ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeveloperMrMeng

觉得有用的佛系投币哦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值