SAP FIORI

UI5开发 – OData Model编程

2017-03-19  本文已影响228人  46b61a5f089d

前面在SEGW中完成了Model的创建工作,接下来我们需要开始写代码,前面说过,在激活Model的时候产生了4个类,MPC两个(Model Provider),DPC两个(Data Provider),在实际开发中,主要基于DPC_EXT进行程序的开发。


首先我们来看看DCP_EXT几个主要的方法:

可以看到,对于每个entity,都包括了CRUD的操作,其中READ包含GET_ENTITY以及GET_ENTITYSET

取得plant列表

重定义PLANTSET_GET_ENTITYSET方法

    method PLANTSET_GET_ENTITYSET.  
     SELECT * from t001w  
     into CORRESPONDING FIELDS OF TABLE et_entityset  
     UP TO 50 ROWS  
     where adrnr <> space.  
    endmethod.  

取得plant单条记录

    method PLANTSET_GET_ENTITY.  
     DATA ls_converted_keys LIKE er_entity.  
     data lv_plant type werks_d.  
     io_tech_request_context->get_converted_keys(  
     IMPORTING  
     es_key_values = ls_converted_keys ).  
     lv_plant = ls_converted_keys-werks.  
      
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
     EXPORTING  
     input = lv_plant  
     IMPORTING  
     output = lv_plant.  
      
     select single * from t001w into CORRESPONDING FIELDS OF ER_ENTITY  
     where werks = lv_plant.  
    endmethod.  

根据plant信息,取得address信息

 method ADDRESSSET_GET_ENTITY.  
     data: lt_key_tab TYPE /iwbep/t_mgw_tech_pairs,  
     ls_keys LIKE LINE OF lt_key_tab.  
     data: lv_adrnr type AD_ADDRNUM,  
     lv_werks type werks_d.  
     CALL METHOD io_tech_request_context->get_source_keys  
     RECEIVING  
     rt_source_keys = lt_key_tab.  

     IF lt_key_tab IS INITIAL.  
       lt_key_tab = io_tech_request_context->get_source_keys( ).  
     ENDIF.  
      
     read table lt_key_tab INTO ls_keys index 1.  
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
       EXPORTING  
         input = ls_keys-value  
       IMPORTING  
         output = lv_werks.  
     select single adrnr from t001w into lv_adrnr where werks = lv_werks.  
      
     select SINGLE * from adrc into CORRESPONDING FIELDS OF ER_ENTITY  
       where ADDRNUMBER = lv_adrnr.  
    endmethod.  

根据plant信息,取得geo信息

method GEOCODESET_GET_ENTITY.  
     data: lt_key_tab TYPE /iwbep/t_mgw_tech_pairs,  
     ls_keys LIKE LINE OF lt_key_tab.  
     data: lv_adrnr type AD_ADDRNUM,  
     lv_werks type werks_d.  
     CALL METHOD io_tech_request_context->get_source_keys  
     RECEIVING  
     rt_source_keys = lt_key_tab.  
     .  
     IF lt_key_tab IS INITIAL.  
     lt_key_tab = io_tech_request_context->get_source_keys( ).  
     ENDIF.  
      
     read table lt_key_tab INTO ls_keys index 1.  
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
     EXPORTING  
     input = ls_keys-value  
     IMPORTING  
     output = lv_werks.  
     select single adrnr from t001w into lv_adrnr where werks = lv_werks.  
      
     select SINGLE * from geoloc into CORRESPONDING FIELDS OF ER_ENTITY  
     where ADDRNUMBER = lv_adrnr.  
    endmethod.

接下来我们会介绍如何把已经开发的odata service注册到Gateway server上面。

上一篇 下一篇

猜你喜欢

热点阅读