ODATA Master-Detail GatewayService 创建与发布

开放数据协议(Open Data Protocol,简称OData)是一种描述如何创建和访问Restful服务的OASIS标准。

T-CODE: /IWFND/MAINT_SERVICE - 激活并维护服务
SEGW - SAP Gateway Service Builder 创建ODATA
首先创建GatewayService (SEGW)
ODATA Master-Detail GatewayService 创建与发布_第1张图片
Data Model 导入Entity Types 右击Data Model->import->DDIC structure
ODATA Master-Detail GatewayService 创建与发布_第2张图片
参照的表VBAK 选取了其中几个字段 其中 VBELN作为主键 finifsh
ODATA Master-Detail GatewayService 创建与发布_第3张图片
再根据以上方法创建一个Entity Set
ODATA Master-Detail GatewayService 创建与发布_第4张图片
ODATA Master-Detail GatewayService 创建与发布_第5张图片
为两个Entity Set建立Association 一对多的关系
ODATA Master-Detail GatewayService 创建与发布_第6张图片
两个EntitySet通过VBELN来关联
ODATA Master-Detail GatewayService 创建与发布_第7张图片
激活
ODATA Master-Detail GatewayService 创建与发布_第8张图片
方法实现,右键->重定义继承的方法
ODATA Master-Detail GatewayService 创建与发布_第9张图片
方法:SALESORDERSET_GET_ENTITY

    DATA: LS_KEY LIKE LINE OF IT_KEY_TAB ,
          LV_VALUE TYPE vbak-VBELN .

    CLEAR LS_KEY.
    READ TABLE IT_KEY_TAB INTO LS_KEY WITH KEY NAME = 'Vbeln'.

    LV_VALUE = |{ LS_KEY-VALUE ALPHA = IN WIDTH = 10 }|.

    SELECT SINGLE * INTO CORRESPONDING FIELDS OF ER_ENTITY
      FROM ZVBAK
      WHERE VBELN = LV_VALUE .

方法:SALESORDERSET_GET_ENTITYSET

  DATA: lw_entityset LIKE LINE OF it_filter_select_options,
        lr_netwr     LIKE lw_entityset-select_options,
        LR_SELECT    TYPE /IWBEP/S_COD_SELECT_OPTION.

  DATA: IS_ORDER TYPE /IWBEP/S_MGW_SORTING_ORDER,
        LT_SORTORDER TYPE ABAP_SORTORDER_TAB ,
        LS_SORTORDER TYPE ABAP_SORTORDER .

"过滤
 IF it_filter_select_options[] IS NOT INITIAL.
      CLEAR lw_entityset.
      CLEAR: lr_netwr[].
      LOOP AT it_filter_select_options INTO lw_entityset.
        CASE lw_entityset-property.
          WHEN 'Netwr'.
            lr_netwr = lw_entityset-select_options.
          WHEN 'Vbeln'.
            lr_netwr = lw_entityset-select_options.

        ENDCASE.
      ENDLOOP.
 "查询
   IF lw_entityset-property EQ 'Netwr'.
     SELECT * FROM Zvbak
       INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
       WHERE netwr IN lr_netwr.
    ELSE.
    SELECT * FROM Zvbak
       INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
       WHERE VBELN IN lr_netwr.
   ENDIF.

 ELSE.
     SELECT * FROM Zvbak
      INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
      UP TO 100 ROWS .
 ENDIF.
"排序
  IF IT_ORDER[] IS NOT INITIAL.
    LOOP AT IT_ORDER INTO IS_ORDER.
      LS_SORTORDER-NAME = IS_ORDER-PROPERTY.
      IF LS_SORTORDER-NAME = 'Vbeln'.
        LS_SORTORDER-NAME = 'VBELN'.
      ELSEIF LS_SORTORDER-NAME = 'Netwr'.
        LS_SORTORDER-NAME = 'NETWR'.
      ENDIF.
      IF IS_ORDER-ORDER = 'desc'.
         LS_SORTORDER-DESCENDING = 'X'.
      ELSE.
         LS_SORTORDER-DESCENDING = ''.

      ENDIF.
      APPEND LS_SORTORDER TO LT_SORTORDER .

    ENDLOOP.
    SORT ET_ENTITYSET BY (LT_SORTORDER).

  ENDIF.

方法:SALESORDERITEMSS_GET_ENTITYSET

  DATA: LS_KEY LIKE LINE OF IT_KEY_TAB ,
        LV_VALUE TYPE vbak-VBELN .

  CLEAR LS_KEY.
  READ TABLE IT_KEY_TAB INTO LS_KEY WITH KEY NAME = 'Vbeln'.

  LV_VALUE = |{ LS_KEY-VALUE ALPHA = IN WIDTH = 10 }|.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
    FROM ZVBAP
    WHERE VBELN = LV_VALUE .

这就是建好的Gateway Service的名字
ODATA Master-Detail GatewayService 创建与发布_第10张图片
/IWFND/MAINT_SERVICE - 激活并维护服务 ,添加服务找到建好的Gateway Service
ODATA Master-Detail GatewayService 创建与发布_第11张图片
点击添加所选服务到指定系统,就完成发布了
ODATA Master-Detail GatewayService 创建与发布_第12张图片
返回SAP Gateway客户端去测试,200说明发布成功
ODATA Master-Detail GatewayService 创建与发布_第13张图片

你可能感兴趣的:(FIORI,后端,前端,大数据,程序人生,经验分享)