天天看点

使用cds view annotation实现SAP UI5的drop down list效果

class ZCL_ZJERRY_SANDBOX_DPC_EXT definition

 public

 inheriting from ZCL_ZJERRY_SANDBOX_DPC

 create public .

public section.

 methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET

   redefinition .

protected section.

private section.

 methods FILL_STATUS_TEXT

   changing

     !CR_ENTITYSET type ref to DATA .

 methods GET_DOMAIN_LIST

   returning

     value(RT_RESULT) type DD07V_T .

 methods GET_STATUS_LIST

   exporting

     !ER_ENTITYSET type ref to DATA .

ENDCLASS.

CLASS ZCL_ZJERRY_SANDBOX_DPC_EXT IMPLEMENTATION.

* ---------------------------------------------------------------------------------------+

* | Instance Public Method ZCL_ZJERRY_SANDBOX_DPC_EXT->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET

* +-------------------------------------------------------------------------------------------------+

* | [--->] IV_ENTITY_NAME                 TYPE        STRING(optional)

* | [--->] IV_ENTITY_SET_NAME             TYPE        STRING(optional)

* | [--->] IV_SOURCE_NAME                 TYPE        STRING(optional)

* | [--->] IT_FILTER_SELECT_OPTIONS       TYPE        /IWBEP/T_MGW_SELECT_OPTION(optional)

* | [--->] IT_ORDER                       TYPE        /IWBEP/T_MGW_SORTING_ORDER(optional)

* | [--->] IS_PAGING                      TYPE        /IWBEP/S_MGW_PAGING(optional)

* | [--->] IT_NAVIGATION_PATH             TYPE        /IWBEP/T_MGW_NAVIGATION_PATH(optional)

* | [--->] IT_KEY_TAB                     TYPE        /IWBEP/T_MGW_NAME_VALUE_PAIR(optional)

* | [--->] IV_FILTER_STRING               TYPE        STRING(optional)

* | [--->] IV_SEARCH_STRING               TYPE        STRING(optional)

* | [--->] IO_TECH_REQUEST_CONTEXT        TYPE REF TO /IWBEP/IF_MGW_REQ_ENTITYSET(optional)

* | [<---] ER_ENTITYSET                   TYPE REF TO DATA

* | [<---] ES_RESPONSE_CONTEXT            TYPE        /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT

* | [!CX!] /IWBEP/CX_MGW_BUSI_EXCEPTION

* | [!CX!] /IWBEP/CX_MGW_TECH_EXCEPTION

* +--------------------------------------------------------------------------------------

 METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset.

   CASE iv_entity_name.

     WHEN 'OrderStatus'.

       get_Status_list( IMPORTING er_entityset = er_entityset ).

     WHEN OTHERS.

       TRY.

           CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset

             EXPORTING

               iv_entity_name           = iv_entity_name

               iv_entity_set_name       = iv_entity_set_name

               iv_source_name           = iv_source_name

               it_filter_select_options = it_filter_select_options

               it_order                 = it_order

               is_paging                = is_paging

               it_navigation_path       = it_navigation_path

               it_key_tab               = it_key_tab

               iv_filter_string         = iv_filter_string

               iv_search_string         = iv_search_string

               io_tech_request_context  = io_tech_request_context

             IMPORTING

               er_entityset             = er_entityset

               es_response_context      = es_response_context.

         CATCH /iwbep/cx_mgw_busi_exception .

         CATCH /iwbep/cx_mgw_tech_exception .

       ENDTRY.

       IF iv_entity_name = 'Z_C_OrderType'.

         fill_status_text( CHANGING cr_entityset = er_entityset ).

       ENDIF.

   ENDCASE.

 ENDMETHOD.

* | Instance Private Method ZCL_ZJERRY_SANDBOX_DPC_EXT->FILL_STATUS_TEXT

* | [<-->] CR_ENTITYSET                   TYPE REF TO DATA

 method FILL_STATUS_TEXT.

   FIELD-SYMBOLS: TYPE zcl_zjerry_sandbox_mpc=>tt_z_c_ordertype.

   ASSIGN cr_entityset->* TO .

   DATA(idd07v) = get_domain_list( ).

   LOOP AT ASSIGNING FIELD-SYMBOL().

     READ TABLE idd07v ASSIGNING FIELD-SYMBOL() WITH KEY domvalue_l = -order_status.

     IF sy-subrc = 0.

        -order_status_text = -ddtext.

     ENDIF.

   ENDLOOP.

 endmethod.

* | Instance Private Method ZCL_ZJERRY_SANDBOX_DPC_EXT->GET_DOMAIN_LIST

* | [<-()] RT_RESULT                      TYPE        DD07V_T

 method GET_DOMAIN_LIST.

   CALL FUNCTION 'DD_DOMVALUES_GET'

     EXPORTING

       domname        = 'ZORDER_STATUS_DOMAIN'   "<-- Your Domain Here

       text           = 'X'

       langu          = sy-langu

     TABLES

       dd07v_tab      = rt_result

     EXCEPTIONS

       wrong_textflag = 1

       OTHERS         = 2.

* | Instance Private Method ZCL_ZJERRY_SANDBOX_DPC_EXT->GET_STATUS_LIST

 METHOD get_status_list.

   FIELD-SYMBOLS: TYPE STANDARD table.

   CREATE DATA er_entityset TYPE zcl_zjerry_sandbox_mpc=>tt_orderstatus.

   ASSIGN er_entityset->* TO .

   LOOP AT idd07v ASSIGNING FIELD-SYMBOL().

      DATA(list) = value zcl_zjerry_sandbox_mpc=>ts_orderstatus(

      code = -domvalue_l text = -ddtext ).

      APPEND list to .

class ZCL_ZJERRY_SANDBOX_MPC_EXT definition

 inheriting from ZCL_ZJERRY_SANDBOX_MPC

 methods DEFINE

CLASS ZCL_ZJERRY_SANDBOX_MPC_EXT IMPLEMENTATION.

* | Instance Public Method ZCL_ZJERRY_SANDBOX_MPC_EXT->DEFINE

* | [!CX!] /IWBEP/CX_MGW_MED_EXCEPTION

 method DEFINE.

   super->define( ).

   zcl_fis_shlp_annotation=>create(

     io_odata_model = model

     io_vocan_model = vocab_anno_model

     iv_namespace = 'sap'

     iv_entitytype = 'Z_C_OrderType'

     iv_property = 'order_status'

     iv_search_help = space

     iv_search_supported = abap_false

     iv_search_help_field = space

     iv_valuelist_entityset = 'OrderStatusEntitySet'

     iv_valuelist_property = 'Code' ##NO_TEXT

     )->add_display_parameter( iv_valuelist_property  = 'Text' ).

   data(lo_txt_property) = model->get_entity_type( 'Z_C_OrderType' )->get_property( 'order_status' ).

   lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ).

   data(lo_text_anno) = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).

   lo_text_anno->add( iv_key = 'text' iv_value = 'order_status_text').

   lo_txt_property = model->get_entity_type( 'OrderStatus' )->get_property( 'Code' ).

   lo_text_anno = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).

   lo_text_anno->add( iv_key = 'text' iv_value = 'Text').

继续阅读