2

I have created a simple table for testing purposes and want to implement the get_entity method in SEGW for this.

I have an RFC that gets the two keys and returns the matching entry.

SELECT SINGLE * FROM ZORDER
  INTO ORDERRETURN
  WHERE ORDERADVENCO    = ORDERADVENCOINPUT AND
        POSITIONADVENCO = POSITIONADVENCOINPUT.

I attempt to call it with /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10'), but I get the error 400: Bad request.

My metadata returns the following:

<?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>

I have also attempted to code the method myself:

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.

Metadata:

<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>

But in this case the lv_ORDERADVENCO and lv_POSITIONADVENCO don't seem to get any value. This is making the sy-subrc = 4, and thus failing.

UPDATE: So I called it now with:

/sap/opu/odata/SAP/ZORDER_RFC_SRV_01/OrderSet(Orderadvenco='10100',Positionadvenco='10')

... but get the error:

<code>/IWBEP/CX_MGW_BUSI_EXCEPTION</code>

<message>Resource not found for segment 'Order'</message>

Also my Orderadvenco and Positionadvenco dont seem to catch the values I attempt to pass...

enter image description here

PS: I have also implemented the

/sap/opu/odata/SAP/ZORDER_SRV/OrderSet

which works fine, but the interesting part is that it calls:

<id>http://vhcala4hci.wdf.sap.corp:50000/sap/opu/odata/SAP/ZORDER_SRV/OrderSet(Orderadvenco='10100',Positionadvenco='10')</id>

But when I attempt to call that link it fails with the same error as above.

enter image description here

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
stackmonkey
  • 115
  • 2
  • 11

2 Answers2

1

Looking at your $metadata file reveals the error. Your entity type 'Order' has two key properties: 'Orderadvencoinput' and 'Positionadvencoinput'. When trying to access /sap/opu/odata/sap/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') table IT_KEY_TAB (or in your case lt_keys) gets filled with these two keys. However what you try to read from the table lt_keys are the lines with NAME field filled as 'Orderadvenco' and 'Positionadvenco'. So the two READ TABLES will always fail, thus ls_key is still initial and thus lv_ORDERADVENCO and lv_POSITIONADVENCO are initial. So the SELECT will fail and the sy-subrc = 4. A common thing for gateway to do is throw an 400 HTTP Code because the requested resource OrderSet(Orderadvencoinput='10100', Positionadvencoinput='10') wasnt filled (er_entity is again initial)

What you should do is put the exact property name from your $metadata into the READ TABLE statements.

mash
  • 183
  • 1
  • 6
  • I corrected it now, but still cant seem to get the values I try to pass... I have just updated the post with the debug and error. – stackmonkey Sep 30 '16 at 09:17
  • 1
    Can you update your $metadata as well in this post? I see some inconsistencies. Also can you show whats inside lt_keys. Another thing is you may redefined a method in the wrong class. Please also check if there is a *DPC_EXT class. you should put your redifinition there. You also do not need to call lt_keys = io_tech_request_context->get_keys( ) because there should be an importing table with the keys – mash Oct 02 '16 at 13:08
  • I have just updated the post, I also found out why the RFC version did not work. Because the call had a space: /sap/opu/odata/SAP/ZORDER_RFC_SRV/OrderSet(Orderadvencoinput='10100',Positionadvencoinput='10'). But the code I have written does not seem to have any content in lt_keys (Image in post). – stackmonkey Oct 04 '16 at 11:41
  • 1
    LT_KEYS does have two lines. This is the [2x2(68)]. The very first 2 tells you it has two lines. Can you doubleclick at LT_KEYS in the Variables 1 tab? you should see the content of this table Also please check if there is also a DPC_EXT class somewhere. you should put your code inside this one! – mash Oct 04 '16 at 18:55
  • The values are: 1. ORDERADVENCO 10100; 2. POSITIONADVENCO 10; ... so the values that I have passed to the method are in there. DCP_EXT is present, and that is where I have written my code. – stackmonkey Oct 05 '16 at 06:54
0

Okay so the problem was that despite the call:

OrderSet(Orderadvenco='10100',Positionadvenco='10')

lt_keys contained:

  1. ORDERADVENCO 10100

  2. POSITIONADVENCO 10

So I had to change:

READ TABLE lt_keys with key name = 'Orderadvenco' into ls_key.
READ TABLE lt_keys with key name = 'Positionadvenco' into ls_key.

to:

READ TABLE lt_keys with key name = 'ORDERADVENCO' into ls_key.
READ TABLE lt_keys with key name = 'POSITIONADVENCO' into ls_key.

Other errors:

OrderSet(Orderadvenco='10100',Positionadvenco='10') - Where I had to delete the space.

Thank you @mash

stackmonkey
  • 115
  • 2
  • 11