Sie sind auf Seite 1von 8

1. How to build Gateway Service?

SEGW
2. How to active Gateway Service? /IWFND/MAINT_SERVICE
3. How to implement Gateway Servcie��

Using SEGW (SAP Gateway Service Builder)


/sap/opu/odata/sap/ZGEA_DEMO02_SRV/
/sap/opu/odata/sap/ZGEA_SO_SRV/

1) Import from structure


Structrue: ZGEA_S_BP

URI
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/BusinessPartnerSet

2) Import from Sturcture and Map to CDS View

URI
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/SalesOrderSet
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/SalesOrderSet('10000000')
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/SalesOrderSet('10000000')/SalesOrderItems

Structure: ZGEA_S_SO_HEADER
ZGEA_S_SO_ITEM

Assiociation: SalesOrder_To_Items
Navigation

CDS View: ZGEA_CV_SalesOrder


ZGEA_CV_SalesOrderItems

Service Implementation
Mapping to Source Entity

DPC_EXT=>Sadl

3) Referece to CDS View


CDS View: ZGEA_CV_BusinessPartner

4) Query By Sadl
importing parameter io_tech_request_context
sadl method _get_entity_set_request_detail.

GET EntitySet
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/ZGEA_CV_BusinessPartner?$inlinecount=allpages
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/ZGEA_CV_BusinessPartner/$count
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/ZGEA_CV_BusinessPartner?
$filter=substringof(CompanyName, 'SAP')&$inlinecount=allpages
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/ZGEA_CV_BusinessPartner?
$select=BusinessPartnerID,CompanyName

/sap/opu/odata/sap/ZGEA_SO_SRV/BusinessPartnerSet?
$select=BusinessPartnerID,CompanyName&$filter=substringof(CompanyName,
'SAP')&$orderby=CompanyName&$skip=1&$top=4&$inlinecount=allpages
/sap/opu/odata/sap/ZGEA_DEMO02_SRV/ZGEA_CV_BusinessPartner?
$select=BusinessPartnerID,CompanyName&$filter=substringof(CompanyName,
'SAP')&$orderby=CompanyName&$skip=1&$top=4&$inlinecount=allpages
GET Entity
/sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet('10000000')

GET EntitySet By Navigation


/sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet('10000000')/SalesOrderItems

GET EntitySet By To Expand


/sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet('10000000')?
$expand=SalesOrderItems,BusinessPartner

5) CREATE/UPDATE/DELETE Entity

5.1) Sample: Create SalesOrder


Request URI: /sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet
Method POST

Header
Content-Type application/json

{
"SalesOrderID": "0010000001",
"Note": "Test 02",
"BuyerID":"0000000002",
"CurrencyCode": "CNY",
"GrossAmount":"200",
"NetAmount":"180",
"TaxAmount":"20"
}

5.2)Sample: Create SalesOrderItem


URI /sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderItemsSet
Method Post

Header
Content-Type application/json

"SalesOrderID":"0010000001",
"SalesOrderItem":"10",
"ProductID":"P1",
"Note":"10000000-P1",
"CurrencyCode":"CNY",
"GrossAmount":"100",
"NetAmount":"90",
"TaxAmount":"10",
"Quantity":"1",
"QuantityUnit":"EA"

5.3)Sample: Crate SalesOrderItem by Navigation


URI /sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet('10000001')/SalesOrderItems

Header
Content-Type application/json
{

"SalesOrderItem":"20",
"ProductID":"P2",
"Note":"10000000-P2",
"CurrencyCode":"CNY",
"GrossAmount":"100",
"NetAmount":"90",
"TaxAmount":"10",
"Quantity":"1",
"QuantityUnit":"EA"

5.4)Sample: Create SalesOrderItem by Deep Insert

URI /sap/opu/odata/sap/ZGEA_SO_SRV/SalesOrderSet

Header
Content-Type application/atom+xml

Body
<?xml version="1.0" encoding="utf-8"?>
<entry m:etag="W/&quot;datetime'2017-07-27T06%3A12%3A05.5508910'&quot;"
xml:base="http://CNDLCT01.cndlc.sap.corp:8000/sap/opu/odata/sap/ZGEA_SO_SRV/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

<category term="ZGEA_SO_SRV.SalesOrder"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderItems"
type="application/atom+xml;type=feed" title="SalesOrderItems">
<m:inline>
<feed
xml:base="http://CNDLCT01.cndlc.sap.corp:8000/sap/opu/odata/sap/ZGEA_SO_SRV/">
<author>
<name/>
</author>
<entry>
<category term="ZGEA_SO_SRV.SalesOrderItems"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:SalesOrderID>10000002</d:SalesOrderID>
<d:SalesOrderItem>10</d:SalesOrderItem>
<d:ProductID>P1</d:ProductID>
<d:Note>10000002-P1</d:Note>
<d:NoteLanguage/>
<d:CurrencyCode>CNY</d:CurrencyCode>
<d:GrossAmount>100.00</d:GrossAmount>
<d:NetAmount>90.00</d:NetAmount>
<d:TaxAmount>10.00</d:TaxAmount>
<d:DeliveryDate m:null="true"/>
<d:Quantity>1</d:Quantity>
<d:QuantityUnit>EA</d:QuantityUnit>
</m:properties>
</content>
</entry>

<entry>
<category term="ZGEA_SO_SRV.SalesOrderItems"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:SalesOrderID>10000002</d:SalesOrderID>
<d:SalesOrderItem>20</d:SalesOrderItem>
<d:ProductID>P2</d:ProductID>
<d:Note>10000002-P2</d:Note>
<d:NoteLanguage/>
<d:CurrencyCode>CNY</d:CurrencyCode>
<d:GrossAmount>100.00</d:GrossAmount>
<d:NetAmount>90.00</d:NetAmount>
<d:TaxAmount>10.00</d:TaxAmount>
<d:DeliveryDate m:null="true"/>
<d:Quantity>1</d:Quantity>
<d:QuantityUnit>EA</d:QuantityUnit>
</m:properties>
</content>
</entry>
</feed>
</m:inline>
</link>
<content type="application/xml">
<m:properties>
<d:SalesOrderID>10000002</d:SalesOrderID>
<d:Note>Test 01</d:Note>
<d:BuyerID>1</d:BuyerID>
<d:BuyerName>SAP</d:BuyerName>
<d:CurrencyCode>CNY</d:CurrencyCode>
<d:GrossAmount>100.00</d:GrossAmount>
<d:NetAmount>90.00</d:NetAmount>
<d:TaxAmount>10.00</d:TaxAmount>
<d:LifecycleStatus/>
<d:LifecycleStatusDescription/>
<d:BillingStatus/>
<d:BillingStatusDescription/>
<d:DeliveryStatus/>
<d:DeliveryStatusDescription/>

</m:properties>
</content>
</entry>

Header
Content-Type application/json
Body
{
"SalesOrderID": "0010000003",
"Note": "Test 03",
"BuyerID":"0000000002",
"CurrencyCode": "CNY",
"GrossAmount":"200",
"NetAmount":"180",
"TaxAmount":"20",
"SalesOrderItems":[
{ "SalesOrderItem":"10",
"ProductID":"P1",
"Note":"10000003-P1",
"CurrencyCode":"CNY",
"GrossAmount":"100",
"NetAmount":"90",
"TaxAmount":"10",
"Quantity":"1",
"QuantityUnit":"EA"},
{ "SalesOrderItem":"20",
"ProductID":"P2",
"Note":"10000003-P2",
"CurrencyCode":"CNY",
"GrossAmount":"100",
"NetAmount":"90",
"TaxAmount":"10",
"Quantity":"1",
"QuantityUnit":"EA"}
]
}

5.5)ChangeSet
Changeset Sample
URI /sap/opu/odata/sap/ZGEA_SO_SRV/$batch
Method POST

Header
Content-Type multipart/mixed;boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77

Body
--batch_36522ad7-fc75-4b56-8c71-56071383e77
Content-Type: multipart/mixed; boundary=changeset_36522ad7-0001

--changeset_36522ad7-0001
Content-Type: application/http
Content-Transfer-Encoding: binary

POST BusinessPartnerSet HTTP/1.1


Content-Type: application/json
Content-Length: 200

{
"BusinessPartnerID":"0000000007",
"BusinessPartnerRole":"02",
"CompanyName":"SAP Vendoer 02",
"Address":{
"AddressID":"0000010002",
"City":"Dalian",
"PostalCode":"116023",
"Street":"WuYi Road",
"Building":"24#",
"Country":"CN",
"AddressType":"02"
}
}

--changeset_36522ad7-0001
Content-Type: application/http
Content-Transfer-Encoding: binary

POST BusinessPartnerSet HTTP/1.1


Content-Type: application/json
Content-Length: 200

{
"BusinessPartnerID":"0000000008",
"BusinessPartnerRole":"02",
"CompanyName":"SAP Vendoer 03",
"Address":{
"AddressID":"0000010003",
"City":"Dalian",
"PostalCode":"116023",
"Street":"WuYi Road",
"Building":"23#",
"Country":"CN",
"AddressType":"02"
}
}

--changeset_36522ad7-0001--

--batch_36522ad7-fc75-4b56-8c71-56071383e77--

5.4) Update Entity

URI /sap/opu/odata/sap/ZGEA_SO_SRV/BusinessPartnerSet('6')
METHOD MERGE

Header
Content-Type application/json
If-Match W/"datetime'2017-07-26T06%3A12%3A16.1836510'"

Body

{
"CompanyName": "SAP Vendor 01"
}

5.5) Update Entity By ChangeSet


URI: /sap/opu/odata/sap/ZGEA_SO_SRV/$batch

Header
Content-Type multipart/mixed;boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77

--batch_36522ad7-fc75-4b56-8c71-56071383e77
Content-Type: multipart/mixed; boundary=changeset_36522ad7-0001

--changeset_36522ad7-0001
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE BusinessPartnerSet('8') HTTP/1.1


Content-Type: application/json
Content-Length: 200
If-Match: W/"datetime'2017-07-31T15%3A52%3A04.1413340'"

"CompanyName":"SAP Vendor 03"

--changeset_36522ad7-0001
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE BusinessPartnerSet('7') HTTP/1.1


Content-Type: application/json
Content-Length: 200
If-Match: W/"datetime'2017-07-26T06%3A17%3A35.7223630'"

"CompanyName":"SAP Vendor 02"

--changeset_36522ad7-0001--

--batch_36522ad7-fc75-4b56-8c71-56071383e77--

5.5) Deleve Entity

-----------------------------------------------------------------
Batch->Get
Batch->ChangeSet Content-ID
Batch->ChangeSet Defer
Function Import

-----------------------------------------------

MPC_EXT

How to Enhance ODATA Service