OData:无法创建工作 get_entity 方法(RFC nore ABAP)
OData: Unable to create working get_entity method (RFC nore ABAP)
我创建了一个简单的 table 用于测试目的,并想为此在 SEGW
中实现 get_entity
方法。
我有一个 RFC 可以获取两个密钥和 returns 匹配条目。
SELECT SINGLE * FROM ZORDER
INTO ORDERRETURN
WHERE ORDERADVENCO = ORDERADVENCOINPUT AND
POSITIONADVENCO = POSITIONADVENCOINPUT.
我试图用 /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10')
调用它,但我收到错误 400: Bad request
。
我的元数据returns如下:
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" sap:schema-version="1" Namespace="ZORDER_RFC_SRV">
<EntityType sap:content-version="1" Name="Order">
<Key>
<PropertyRef Name="Orderadvencoinput" />
<PropertyRef Name="Positionadvencoinput" />
</Key>
<Property Name="Orderreturn" Nullable="false" Type="ZORDER_RFC_SRV.Orderreturn" />
<Property Name="Orderadvencoinput" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Positionadvencoinput" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
</EntityType>
<ComplexType Name="Orderreturn">
<Property Name="Orderadvenco" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Positionadvenco" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Outcome" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Plantitem" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Progress" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Status" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Targetquantity" Nullable="false" Type="Edm.Int32" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="INT" />
<Property Name="Targettime" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Unit" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
</ComplexType>
<EntityContainer Name="ZORDER_RFC_SRV_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
<EntitySet sap:content-version="1" Name="OrderSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZORDER_RFC_SRV.Order" />
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_RFC_SRV/$metadata" rel="self" />
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_RFC_SRV/$metadata" rel="latest-version" />
</Schema>
</edmx:DataServices>
</edmx:Edmx>
我也尝试过自己编写方法:
method ORDERSET_GET_ENTITY.
DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs,
ls_key TYPE /IWBEP/S_MGW_TECH_PAIR,
lv_ORDERADVENCO TYPE zorder-ORDERADVENCO,
lv_POSITIONADVENCO TYPE zorder-POSITIONADVENCO,
ls_order TYPE zorder.
lt_keys = io_tech_request_context->get_keys( ).
READ TABLE lt_keys with key name = 'Orderadvenco' into ls_key.
lv_ORDERADVENCO = ls_key-value.
READ TABLE lt_keys with key name = 'Positionadvenco' into ls_key.
lv_POSITIONADVENCO = ls_key-value.
SELECT SINGLE * FROM ZORDER
INTO ls_order
WHERE ORDERADVENCO = lv_ORDERADVENCO and
POSITIONADVENCO = lv_POSITIONADVENCO.
IF sy-subrc = 0.
er_entity-ORDERADVENCO = ls_order-ORDERADVENCO.
ENDIF.
endmethod.
元数据:
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" sap:schema-version="1" Namespace="ZORDER_SRV">
<EntityType sap:content-version="1" Name="Order">
<Key>
<PropertyRef Name="Orderadvenco"/>
<PropertyRef Name="Positionadvenco"/>
</Key>
<Property Name="Orderadvenco" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Positionadvenco" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Outcome" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Plantitem" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Progress" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Status" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Targetquantity" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="INT" Nullable="false" Type="Edm.Int32"/>
<Property Name="Targettime" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Unit" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
</EntityType>
<EntityContainer Name="ZORDER_SRV_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
<EntitySet sap:content-version="1" Name="OrderSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZORDER_SRV.Order"/>
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_SRV/$metadata" rel="self"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_SRV/$metadata" rel="latest-version"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
但在这种情况下,lv_ORDERADVENCO
和 lv_POSITIONADVENCO
似乎没有任何价值。这正在制作 sy-subrc = 4
,因此失败了。
更新:
所以我现在称它为:
/sap/opu/odata/SAP/ZORDER_RFC_SRV_01/OrderSet(Orderadvenco='10100',Positionadvenco='10')
...但出现错误:
<code>/IWBEP/CX_MGW_BUSI_EXCEPTION</code>
<message>Resource not found for segment 'Order'</message>
我的 Orderadvenco 和 Positionadvenco 似乎也没有捕捉到我试图传递的值...
PS: 我也实现了
/sap/opu/odata/SAP/ZORDER_SRV/OrderSet
工作正常,但有趣的是它调用:
<id>http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/SAP/ZORDER_SRV/OrderSet(Orderadvenco='10100',Positionadvenco='10')</id>
但是当我尝试调用它时 link 它失败并出现与上述相同的错误。
查看您的 $metadata 文件会发现错误。您的实体类型 'Order' 有两个关键属性:'Orderadvencoinput' 和 'Positionadvencoinput'。当尝试访问 /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') table IT_KEY_TAB (或在您的情况下 lt_keys)时,会填充这两个键。但是,您尝试从 table lt_keys 中读取的是 NAME 字段填充为 'Orderadvenco' 和 'Positionadvenco' 的行。所以两个 READ TABLES 总是会失败,因此 ls_key 仍然是初始的,因此 lv_ORDERADVENCO 和 lv_POSITIONADVENCO 是初始的。因此 SELECT 将失败并且 sy-subrc = 4。网关通常要做的事情是抛出 400 HTTP 代码,因为请求的资源 OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') 未填充(er_entity又是首字母)
您应该做的是将 $ 元数据中的确切 属性 名称放入 READ TABLE 语句中。
好吧,问题是尽管调用了:
OrderSet(Orderadvenco='10100',Positionadvenco='10')
lt_keys 包含:
订购ADVENCO 10100
POSITIONADVENCO 10
所以我不得不改变:
READ TABLE lt_keys with key name = 'Orderadvenco' into ls_key.
READ TABLE lt_keys with key name = 'Positionadvenco' into ls_key.
至:
READ TABLE lt_keys with key name = 'ORDERADVENCO' into ls_key.
READ TABLE lt_keys with key name = 'POSITIONADVENCO' into ls_key.
其他错误:
OrderSet(Orderadvenco='10100',Positionadvenco='10') - 我不得不删除 space.
谢谢@mash
我创建了一个简单的 table 用于测试目的,并想为此在 SEGW
中实现 get_entity
方法。
我有一个 RFC 可以获取两个密钥和 returns 匹配条目。
SELECT SINGLE * FROM ZORDER
INTO ORDERRETURN
WHERE ORDERADVENCO = ORDERADVENCOINPUT AND
POSITIONADVENCO = POSITIONADVENCOINPUT.
我试图用 /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10')
调用它,但我收到错误 400: Bad request
。
我的元数据returns如下:
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" sap:schema-version="1" Namespace="ZORDER_RFC_SRV">
<EntityType sap:content-version="1" Name="Order">
<Key>
<PropertyRef Name="Orderadvencoinput" />
<PropertyRef Name="Positionadvencoinput" />
</Key>
<Property Name="Orderreturn" Nullable="false" Type="ZORDER_RFC_SRV.Orderreturn" />
<Property Name="Orderadvencoinput" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Positionadvencoinput" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
</EntityType>
<ComplexType Name="Orderreturn">
<Property Name="Orderadvenco" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Positionadvenco" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Outcome" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Plantitem" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Progress" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Status" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Targetquantity" Nullable="false" Type="Edm.Int32" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="INT" />
<Property Name="Targettime" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
<Property Name="Unit" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" />
</ComplexType>
<EntityContainer Name="ZORDER_RFC_SRV_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
<EntitySet sap:content-version="1" Name="OrderSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZORDER_RFC_SRV.Order" />
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_RFC_SRV/$metadata" rel="self" />
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_RFC_SRV/$metadata" rel="latest-version" />
</Schema>
</edmx:DataServices>
</edmx:Edmx>
我也尝试过自己编写方法:
method ORDERSET_GET_ENTITY.
DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs,
ls_key TYPE /IWBEP/S_MGW_TECH_PAIR,
lv_ORDERADVENCO TYPE zorder-ORDERADVENCO,
lv_POSITIONADVENCO TYPE zorder-POSITIONADVENCO,
ls_order TYPE zorder.
lt_keys = io_tech_request_context->get_keys( ).
READ TABLE lt_keys with key name = 'Orderadvenco' into ls_key.
lv_ORDERADVENCO = ls_key-value.
READ TABLE lt_keys with key name = 'Positionadvenco' into ls_key.
lv_POSITIONADVENCO = ls_key-value.
SELECT SINGLE * FROM ZORDER
INTO ls_order
WHERE ORDERADVENCO = lv_ORDERADVENCO and
POSITIONADVENCO = lv_POSITIONADVENCO.
IF sy-subrc = 0.
er_entity-ORDERADVENCO = ls_order-ORDERADVENCO.
ENDIF.
endmethod.
元数据:
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" sap:schema-version="1" Namespace="ZORDER_SRV">
<EntityType sap:content-version="1" Name="Order">
<Key>
<PropertyRef Name="Orderadvenco"/>
<PropertyRef Name="Positionadvenco"/>
</Key>
<Property Name="Orderadvenco" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Positionadvenco" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Outcome" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Plantitem" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Progress" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Status" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Targetquantity" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="INT" Nullable="false" Type="Edm.Int32"/>
<Property Name="Targettime" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
<Property Name="Unit" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false" sap:label="Char" MaxLength="60" Nullable="false" Type="Edm.String"/>
</EntityType>
<EntityContainer Name="ZORDER_SRV_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
<EntitySet sap:content-version="1" Name="OrderSet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZORDER_SRV.Order"/>
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_SRV/$metadata" rel="self"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/sap/ZORDER_SRV/$metadata" rel="latest-version"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
但在这种情况下,lv_ORDERADVENCO
和 lv_POSITIONADVENCO
似乎没有任何价值。这正在制作 sy-subrc = 4
,因此失败了。
更新: 所以我现在称它为:
/sap/opu/odata/SAP/ZORDER_RFC_SRV_01/OrderSet(Orderadvenco='10100',Positionadvenco='10')
...但出现错误:
<code>/IWBEP/CX_MGW_BUSI_EXCEPTION</code>
<message>Resource not found for segment 'Order'</message>
我的 Orderadvenco 和 Positionadvenco 似乎也没有捕捉到我试图传递的值...
PS: 我也实现了
/sap/opu/odata/SAP/ZORDER_SRV/OrderSet
工作正常,但有趣的是它调用:
<id>http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/SAP/ZORDER_SRV/OrderSet(Orderadvenco='10100',Positionadvenco='10')</id>
但是当我尝试调用它时 link 它失败并出现与上述相同的错误。
查看您的 $metadata 文件会发现错误。您的实体类型 'Order' 有两个关键属性:'Orderadvencoinput' 和 'Positionadvencoinput'。当尝试访问 /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') table IT_KEY_TAB (或在您的情况下 lt_keys)时,会填充这两个键。但是,您尝试从 table lt_keys 中读取的是 NAME 字段填充为 'Orderadvenco' 和 'Positionadvenco' 的行。所以两个 READ TABLES 总是会失败,因此 ls_key 仍然是初始的,因此 lv_ORDERADVENCO 和 lv_POSITIONADVENCO 是初始的。因此 SELECT 将失败并且 sy-subrc = 4。网关通常要做的事情是抛出 400 HTTP 代码,因为请求的资源 OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') 未填充(er_entity又是首字母)
您应该做的是将 $ 元数据中的确切 属性 名称放入 READ TABLE 语句中。
好吧,问题是尽管调用了:
OrderSet(Orderadvenco='10100',Positionadvenco='10')
lt_keys 包含:
订购ADVENCO 10100
POSITIONADVENCO 10
所以我不得不改变:
READ TABLE lt_keys with key name = 'Orderadvenco' into ls_key.
READ TABLE lt_keys with key name = 'Positionadvenco' into ls_key.
至:
READ TABLE lt_keys with key name = 'ORDERADVENCO' into ls_key.
READ TABLE lt_keys with key name = 'POSITIONADVENCO' into ls_key.
其他错误:
OrderSet(Orderadvenco='10100',Positionadvenco='10') - 我不得不删除 space.
谢谢@mash