Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all 2823 articles
Browse latest View live

500 Internal Server Error for OData model in sapui5

$
0
0

Hi All,

 

I have an odata webservice which is tested successfully on the browser which returns the metadata. However when i use the url to create an Odata model in my ui5 application in eclipse and run it locally from eclipse , it gives me 500 internal server error in console.

 

One thing to note is that I am using VPN to access the odata url of the gateway server and I am prefixing my URL with proxy

 

var oMdl_Article = new sap.ui.model.odata.ODataModel("proxy/http/<ip>:<port>/sap/opu/odata/sap/zarticle_viewer_srv/");

proxy1.JPG

 

proxy2.JPG

 

When I view the webservice URL in the browser seperately it works fine after asking me username and password

proxy3.JPG

 

PS: When I upload as BSP to gateway server and remove the proxy/ keyword , the ODATA url returns successfull 200 code. Hence the issue is been faced only while executing this app locally from eclipse for testing,

 

Message was edited by: Amber .


How to fetch image from DMS in ODATA

$
0
0

Hi All,

 

I am able to fetch an image from Mime Repository and send it as XML output in an odata service (using  cl_mime_repository_api=>get_api( )->get )

 

Now my requirement is I need to fetch the image from DMS instead of MIME repository. The image of DMS will be basically linked to Article Master Table. I am not able to find the methods/approach to fetch an image from DMS. Kindly suggest if someone has any idea on this

 

Thanks & Regards

Amber

How to expose Gateway Services via HCI OData Provisioning, and secure them using SAP API Management on HCP Trial - Part 1

$
0
0

There is already a very fine blog from Martin Bachmann explaining HANA Cloud Platform, the benefits of cloud and HCI Odata Provisioning in general, as well as the scenario for connecting SAP HCI OData Provisioning to an SAP Gateway system here How to connect the SAP Business Suite to the SAP HANA Cloud Platform using Gateway as a Service Trial Edition. However like so many things in the cloud, there are changes already, as soon as its published. I will not re-cover the informational content contained therein again, but I will be showing the updated screens for the most recent version.

 

If you have already configured HCI Odata Provisioning using Martin's blog, or on your own, and want to skip to the SAP API Management part, please copy down the URL path to your HCI Odata Provisioning Services and go to Part 2 of this blog.

 

A quick bit on "Why SAP API Management?"

SAP API Management does not replace SAP Gateway, and in fact, relies on SAP Gateway to expose data from SAP Backends. What SAP API Management adds is an enhancement of the capabilities provided by SAP Gateway. It can sit on top of a Gateway deployment in order to provide Secure and Scalable access, through security, and data management policies, as well as providing a developer engagement area. With a deployment on HCP, it is even easier, as a user of SAP Gateway only needs to install/run the IWBEP component of Gateway on their SAP Backend system, and use HCI OData Provisioning on HCP to connect to it, consuming the exposed OData endpoints directly in SAP API Management. Additionally SAP API Management can combine other data sources such as HANA XS or Non-SAP data together with Gateway exposed data, exposed via a single secure endpoint for developers to build impressive Apps.

 

But this walkthrough will focus on using HCI OData provisioning (hereafter referred to as HCIODP) to consume services exposed by SAP Gateway, and expose them as OData endpoints which will be consumed by SAP API Management as API Proxies.

 

 


PART I – Creating OData Endpoints in HCIODP

 

* Pre-Requisite: An account on an SAP Gateway system accessible via Internet. For this walk-through I will be using the SAP Developer Center ES4 system. Anyone can sign up for an account here: SAP NetWeaver Gateway Developer Center


1. Enabling HCIODP in Trial

 

Login to trial, check the Services section, under "Integration" i.e. In HCP Trial Account

 

HCP_Services_HCIODP.png

 

Click HCI OData Provisioning tile to enter service. Check status of service. If click status is "Not enabled" click the "Enable" button. Wait until you see service status change to Enabled.

 

HCP_HCIODP_Service_enablement.png

 

 

2. Configuring HCIODP Destination(s)

 

Click “Configure HCI OData provisioning” - This should bring up the “Destinations” tab under "Configure HCI OData Provisioning". Click “New Destination” in order to create the destination for the SAP Developer Center ES4 system.

 

Enter details for the Gateway system. All details, including login, and password will be those which you have registered on the Gateway system. E.g. for SAP Developer center ES4 system, see below:

 

HCIODP_ES4_Destination_Settings.png

 

After you save, wait until details are saved in system, which will be indicated by the configuration screen turning grey and no longer allowing input.

 


3. Configuring HCIODP Roles

 

Click the “Roles” tab to configure user access in HCIODP.

 

Select GW_Admin role, and click “Assign” below in the “Individual Users” section. This will authorize the user to enter the Admin window for HCIODP to configure available services, view logs, or configure Metadata options.

 

In the popup window, enter the SAP ID login information (P-User, S-User, I#, etc.) you will be using, and click "Assign"..

 

HCIODP_Roles_GWAdmin.png

 

Assign_GW_Admin_User.png

Repeat this process with the role GW_User, this will assign authorization for a user to consume the services configured on HCIODP (but not to access the Admin window).

Once complete, you should have a user assigned to both the roles GW_Admin and GW_User.

 

 

4. Configuring HCIODP Services

Click the “HCI OData Provisioning” link at the top of the window, to return to the HCIODP base screen

 

HCP_Cockpit_Return_Selection.png

Then click “Go to Service” from the base screen for HCIODP.

 

If everything worked correctly, this will open a new browser tab, for the HCIODP Admin screen. You may be prompted to enter SAP ID credentials, enter the credentials for the user configured in the GW_Admin role. After login the Admin screen should appear as below:

 

HCIODP_Main_Screen.png

 

To begin exposing services from Gateway system configured, click the "Register" button at the top of the screen to bring up the “Register Service” screen. Select the SAP Gateway system configured in Step 2 from the drop down list for Destinations, then click the icon of a Magnifying Glass next to “Search Services” to bring up a list of available Gateway Services.

 

HCIODP_Search_ES4_Services.png

 

Select the desired service to be exposed to API Management by clicking the empty box on the far left to highlight that selection. E.g. to select “GWDEMO” below:

 

HCIODP_Select_Service.png
Note: The box will fill blue when selected, and if you move the mouse cursor away, you will see the entire row is blue when selected. If this is not the case, the row was not properly selected.

 

Click the "Register" button, to register the selected service in HCIODP. The service should now appear in the list of Registered Services for HCIODP.

HCIODP_Registered_Service.png

 

Click “Open Service Document” for the newly added service, to test that the service is exposing data as expected. This will open a new browser tab, with service data in OData format. Copy down the URL in your browser bar for the service, this will be used as the Target endpoint for the API Proxy.

Repeat these steps above for each Gateway service you want to expose.

 

When you have completed registering services, the next step will be creating API proxies in SAP API Management, using HCIODP as the OData Target Endpoints, and the Services as the APIs in this case. This will be covered in Part 2.

 

 

For questions, feedback, concerns, feel free to leave a comment, or send us an E-Mail.


Also follow us online
SAP API ManagementSAP.com|SCN| YouTube

How to expose Gateway Services via HCI OData Provisioning, and secure them using SAP API Management on HCP Trial - Part 2

$
0
0

This is a continuation from Part 1 where we walk-through setting up HCI OData Provisioning on HANA Cloud Platform against SAP Developer Center'ss ES4 Gateway system. If you haven't already completed this, I recommend going through Part 1 in order to be ready for this blog.


Now that you should have at least one SAP Gateway service exposed in HCI OData Provisioning (hereafter referred to as HCIODP), it's time to set things up so that they can be connected to by SAP API Management. Due to the Platform nature of HANA Cloud Platform, this is remarkably easy fortunately. If you have not yet enabled SAP API Management, please follow the steps outlined here Free Trial of SAP API Management on HANA Cloud Platform is available now!

 

Once you are set-up, can get started right away.


PART II – Creating API Proxies from OData Endpoints in SAP API Management

 

1. Creating a "System" connection to HCIODP.


Login to your HCP Trial Account with SAP API Management enabled. Open the Services pane, and locate SAP API Management under the "Integration" section. Launch API Management API Portal by clicking "Access SAP API Management API Portal"

 

Launch_SAP_API_Mgmt_Portal.png

 

This should load the "Configure" section of SAP API Management by default, if not, click the drop down menu from the top left hand corner and select “Configure”. This is where one generates Target systems for SAP API Management. Click "Create" in the bottom right hand corner to add a system.

This will take you to the Create System window, where you will need to enter the relevant details for the HCIODP system used in Part I.


Title: HCIODP

Details: HCI OData Provisioning system, providing exposed Gateway Services

Host: enter the Base URL from the Service Document URL you saved from Part I. (The format will be gwaas-<userID>trial.hanatrial.ondemand.com)

Port: 443
Check Use SSL
Authentication Type:
Basic

Service Collection URL:  /CATALOGSERVICE/ServiceCollection

 

Create_New_System.png

 

* The Catalog URL is something unique to SAP Gateway systems, which allows SAP API Management to "Discover" available services from the Catalog Service. It is not used for Non-SAP systems.

 

After checking details entered, then click “Save”. Once system has been saved, click “Launch” hyperlink at bottom left-hand side of screen, this will launch a new tab, opening the SAP API Management Destinations area on the HCP Cockpit, not to be confused with the Global HCP Destinations. Here you will add Authentication settings for the newly created System. Click the name of the system you newly created, e.g. HCIODP and click the "Edit" button at the bottom of the page.

 

User: <Use the accountID that was added under GW_User in Part I>

Password: <Password for accountID added under GW_User in Part I>
Next, Click “New Property” under Additional Properties, and enter Key: TrustAll || Value: true

 

 

API_System_Details.png

Then click “Save”.Changes can take up to 5 minutes to save (but usually will only take a few seconds).

 

 

2. Creating an API Proxy using HCIODP Service

 

Close HCP Cockpit to return to API Management API Portal window. Select drop-down menu list from top left hand corner and select "Manage" to open API Proxy page.


API_Menu.png


In the API Proxy window, click “Create” at the bottom-right hand corner, and select “Create API” from popup selection to bring up the “Create API” screen.

Provider System: <Select system created in step 2>
Click “Discover” button to see a list of all services exposed by HCI-OData Provisioning.

Select a Service and click “OK” this should auto-fill all the API Information for you.

 

Create_API.png

* Link Target Server will create the API with all System information determined by the Provider System you determine, and all pathing linked as a virtual path. This allows for easy transition between environments (such as Dev, Test, Prod) for the API Proxy. Documentation flag determines whether SAP API Management attempts to pull existing documentation from the Service, and is only applicable for SAP Gateway endpoints.


Click “Create” to generate the API Proxy. If everything was entered correctly, the API Details screen should come up, with all Resources (and corresponding descriptions of the model) created automatically from the Metadata.

 

Create_API_full.png

 

Then click “Save”. If everything went well you should see a message at the bottom of the screen telling you "API Registered Successfully".

 

To test that the API Proxy is working correctly, click “GET” for one of the resources with that operation available. If no resources are available, select “Test” from the main Drop-Down menu, then select the name of the API Proxy from the list of APIs.

Click “Authentication: None” and select “Basic Authentication” from the drop down list.
User Name: <UserID added under GW_User in Part I>
Password: <Password for userID added under GW_User in Part I>
Select the “GET” operation.

 

Test_Console.png

 

Click “Send” in the bottom right hand corner.

This should successfully retrieve the OData Collection provided by HCIODP, via a call to the SAP API Management API Proxy Endpoint URL.

 

Now that you have an API Proxy sitting on top of the HCIODP service, you can start adding Policies to extend the functionality, as well as expose it to the Developer Portal so that Developers could begin to build apps on top of the data. I will not get into that in this blog, as we were just quickly getting up and running connecting SAP API Management to HCIODP.

 

If you would like to start learning more about what you can do with SAP API Management, I suggest looking at the repository of information SAP API Management - Overview & Getting started which will continue to be updated as more enablement content is added.

 

Of particular interest to this particular exercise, will be the Blog on creating a Policy SAP API Management - Enabling URL masking . If you notice above, the returned data includes links to the HCI OData Provisioning service, which is not what you want if SAP API Management is the intended target for connectivity. The linked blog will tell you how to have SAP API Management automatically mask all URLs through SAP API Management.

 

For questions, feedback, concerns, feel free to leave a comment, or send us an E-Mail.


Also follow us online
SAP API ManagementSAP.com|SCN| YouTube

Usage of $skiptoken with Offline

$
0
0

Hello fellow SAPers.

 

I have found myself with an issue due the amount of records our service is returning into the device. The issue is an error 500 which ends the service and returns an error response.

 

The way we figured this could work was using $skiptoken command and using the logic to separate the response. This has been working wonderfully for online scenarios since we return to the Front Team  the link to the next data to fecth, making the responses from the service smaller and easier to handle.

 

The issue however, comes when trying to pair this with Offline Scenarios, they're using kapsel to manage the offline stores. However they tried to test this with this and the service didn't return any value and just froze. We noticed that commenting the next lines of code made it work correctly:

 

es_reponse_context-skiptoken = lv_index_end + 1.

CONDENSE     es_response_context

 

 

The issue with this is that's how we know what are the next records to fetch in the consecutive calls. The thing is, how do we make this to work correctly with offline or if there's no way to do so, is there any other way to try to handle the pagination.

 

With no further ado, I'll be thankful to hear your recomendations or comments regarding this issue.

Role of SAP Gateway OS process in handling ODATA calls

$
0
0

Dear Team,

 

First of all, I am very new to the Gateway and ODATA services.

 

I would like to understand how the ODATA calls are handled by Netweaver systems from Firori launchpad application perspective.

In most of the guides, we never talks about the Gateway process, below is my understanding about the connection flow, Is this correct?

 

Fiori Launchpad (SAP UI5)  --> ICM --> Gateway service (OS processes) --> Gateway

ICM calls to Gateway registered programs is handled via Gateway services, right?

 

Thanks,

Razal

getting error that --> '/IWFND/OM_MED_CATAL_ODC_0002_BE' '01' 'DEFAULT' does not exist

$
0
0

hi all

 

while accessing gateway from sap webide getting error that

 

Value    Data Provider implementation '/IWFND/OM_MED_CATAL_ODC_0002_BE' '01' 'DEFAULT' does not exist

 

 

please give need full information

Odata Service for CDS View with Input Parameter

$
0
0

Hi Gurus,

 

I would needing yours expert suggestion for following problem:

 

1. I've created on CDS View with Input Parameter;

Untitled.png

2. Then I created the Service in SEGW t-code

Untitled.png

Untitled.png

3. Now when I try to execute the Odata Service for this I'm getting below error:

Untitled.png

Will be needing your expert views on this, I think I'm not correctly passing the Input parameter for the underlying CDS view, pleasw let me know how to do it.

 

Thanks and Regards,

Binay Biswakarma


How to pass decimal data to Netweaver OData service from JSON input

$
0
0

Hi,

 

I have a POST service and I am trying to send some some data to the webservice using JSON format. In my input, only the decimal fields are not getting passed to the service. The Edm type of those fields is Decimal (13,3).

 

My JSON input is as follows:

 

"Item":[{"Field1":"xxxxx",    "Field2":"yyyy",   "DecimalField1":"1.000",         "DecimalField2":"2.000""DecimalField3":"3.000"}]


Please tell me whether I need to change the format of the decimal fields in the input.

Hierarchy gateway O data service creation...

$
0
0

Hi Folks,

 

I am looking for example or help for creation o data like below..

 

Output :

 

Module 1

     -Track Name 1

          -Reports

               -1

               -2

               -3

               .

               .

               n(dynamically report name will populate)


Module 2

     -Track Name 2

          -Reports

               -1

               -2

               -3

               .

               .

               n(dynamically report name will populate)



Amol S

SAP Netweaver Gateway Client HTTP Response is 201 (Created) but nothing being created in backend ERP

$
0
0

Hi,

 

I am trying to create a Sales Order through OData service.

I tried creating with Gateway Client and Firefox REST client.

The Response is same. 201 - Created.

 

But nothing being created in the backend ERP system.

 

Please help.

 

Thank you.

Ravinder.

What is the Content-Type field value in rest client for Zipped files

$
0
0

I am testing in Google Chrome REST CLIENT. Please let me know what we need to pass to Content-Type when our attachment in ZIP File.

 

Capture.PNG

 

When we pass

"application/octet-stream" for Content-Type field in rest client.

and see in debugging mode

In Method: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM, in parameter ==> is_media_resource-mime_type we are getting value as "multipart/form-data", Due to this reason I am not able to see the actual Zip File XSTRING value.

 

reffred: http://stackoverflow.com/questions/856013/mime-type-for-zip-file-in-google-chrome)

 

In my Gateway client when I am passing as below screen shot and I am able to see correct Zip File XSTRING value In Method: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM

 

Capture.PNG

Please help.

 

Below are the F4 values I see in Content-Type field:

  1. multipart-form-dataapplication
  2. x-www-form-urlencodedapplication
  3. jsonapplication
  4. xmlapplication
  5. base64application
  6. octet-streamtext
  7. plaintext
  8. csstext
  9. htmlapplication
  10. javascript

 

Thanks,

Madhu M V

Service not prompting for UserID/password for SAP Gateway

$
0
0

Hi,

 

We are facing a strange issue.

 

We have MXX-200 system which is configured as a gateway system for SXX-200(Dev system), and MXX-300 is configured as a gateway for SXY-300(Testing System). We have checked every configuration and compared them between these two systems, and made every config uniform. Still, while accessing the service from MXX_200, it is prompting for a userID/password, but no such password is been asked for MXX-300. Further, which doing test-service, we are facing the error as "RFC Error: User misses authorization object S_RFCACL in target system".

 

The RFC used as a gateway is configured a 'Current User' type, still no prompt for UserID/password.

 

Any ideas on this would be very helpful. This issue is pending since a month. I have re-created all the trusted RFCs, and made all changes as compared to the dev system, still no luck.

 

Please help.

 

Regards,

Soumyojit

Create / delete links between entities ($links) in gateway

$
0
0

Hi experts,

 

Is it possible to manipulate (DELETE, CREATE) links between entities in gateway?

 

The documentation is somewhat contradictory:

Note 1574568 clearly mentions that it is not supported (General Constraints, point 7)

However, this document: /IWBEP/IF_MGW_APPL_SRV_RUNTIME - SAP Gateway - SAP Library mentions 2 methods in interface  /IWBEP/IF_MGW_APPL_SRV_RUNTIME: CREATE_LINK and DELETE_LINK

 

links.jpg


We are running SAP_GWFND SPS13 and these 2 methods are not available in our system. A 'method not implemented' exception is raised in our GW hub system when we try to execute a DELETE on a $link.

 

Are there plans to support this functionality? As of which release?

 

Best Regards,

Thomas

ValueList from different Service with Annotations

$
0
0

Hi everybody,

 

I have a question regarding Annotations.

 

I successfully added a ValueList Annotation for a property inside the _MPC_EXT class.

Now I want to add another ValueList Annotation for a different property, but the EntitySet I want to address is in a different Service. So my question is: Am I able to access EntitySets from a different Service for a ValueList annotation and if so, how can I do that?

 

For clarifiation:

Let's assume, that I have Service A (with entity Businesspartner and entity set BusinesspartnerSet) and Service B (with entity Invoice and entity set InvoiceSet). The invoice entity has a property called partner, which should have a ValueList to find a specific Businesspartner.

 

Thanks a lot

Nils


ODATA Service at Production System

$
0
0

Dear All

 

May be a simple question, but not able to get it.

Can someone please explain the steps.

 

1. I created a ODATA service in the Development Client 103. (development client no data)

 

     How to use that url - to access data from client 102, (which is a testing client where data is there).

 

2. Once tested, how to transport the Service to Production system.

    or do i need to recreate it in production system

 

 

  

Regards,

Venkat

 

Tags edited by: Jitendra Kansal (Moderator)

Introduction: OData $batch Processing with Content ID in SAP Gateway

$
0
0

cid_150.png

Dear all,


Thanks for your attention. If you are the one of frequent SCN readers, you would think I'm publishing yet another H2G blog :-) - yes this is important topic hence I wrote it.


Question.


Do you know OData? - Most likely yes.


Have you ever used OData? Most likely yes too.


And - do you know about "Content ID"? - Perhaps no.


"Content ID" is nothing new, it has been defined in the standard OData specification for a while, based on the idea that any OData app can take advantage of when building relationships between entities. A section of "Batch Processing" (2.2.1. Referencing Requests in a Change Set) describes what it is and how to use it - but without any context, you would have no idea when we use it.

 

Why we need this?


One very common use case is - OData providers need to support Content ID when we use Header-Items (or "Parent-Children") data with Offline Store of SMP3/HCPms OData SDK.

A_h_i.png

Let's have a quick look at how it works in an offline store. If you're familiar with Offline Store, it is nothing new. As an OData $batch request, we create a set of  header & item entities in the offline store locally. Each entity has its own create request via OData client API.

A_1.png

Here comes the interesting part. To add related child entities to a parent entity, you need to know, or be able to reference, the parent entity's ID.  The "Content ID" acts as a reference to the parent entity’s ID. As you see, a Content ID has a prefixed value with a "$" character.

A_id.png

For example, by using the Content ID referencing, you can refer the items with the resource navigation path "$100/ToItems". $100 indicates the header entity by using Content ID. As it is still created locally, those entities don't have any finalized key that will be given by the OData services.


Time to flush the local entities. These entities needs to be flushed via OData $batch request.

A_2.png

Once your $batch flush goes successfully, the OData services handle "Content ID" and assign key(s) to the entities for all the set of headers & items on the backend side. Most likely you want to do refresh too.

A_3.png

Got it? As you see, Content ID plays a critical role to handle header-item relationship with Offline Store during OData $batch processing. In other words -  to create child items for entites within a change set of $batch request.


To give you some more practical idea from the OData client SDK perspective, here's a small piece of code that demonstrates the idea in iOS API (Android, Windows, and Kapsel API follow the same rule):


01 SODataRequestParamBatchDefault *batch = [[SODataRequestParamBatchDefault alloc] init];
02 SODataRequestChangesetDefault *changeset = [[SODataRequestChangesetDefault alloc] init];
03    
04 SODataRequestParamSingleDefault *parentReq = [[SODataRequestParamSingleDefault alloc] initWithMode:SODataRequestModeCreate resourcePath:@"/HeaderSet"];
05 parentReq.payload = parentEntity;
06 parentReq.contentID = @"100";
07    
08 SODataRequestParamSingleDefault *childReq = [[SODataRequestParamSingleDefault alloc] initWithMode:SODataRequestModeCreate resourcePath:@"$100/ToItems"];
09 childReq.payload = childEntity;
10    
11 [changeset.requestParams addObject:parentReq];
12 [changeset.requestParams addObject:childReq];
13    
14 [batch.batchItems addObject:changeset];
15   
16 [store scheduleRequest:batch delegate:self];

#01 & #02:  creating a batch and changeset object.

#04 - #06: is for creating parent entity - as #04 indicates, it is a Header entity. You see the #06 that is assigning Content ID.

#08 - #09: for child entity. #08 indicates the child entityset is described as "$100/ToItems" that is navigation resource path from parent to children.

#11 - #16: execute a $batch request.


That's all the Content ID referencing from client perspective. Now you get the idea of what Content ID is - and the next question is how to implement OData services that support it.


The aim of the following H2G is how to implement OData $batch processing with Content ID in SAP Gateway.


Note: This introductory page focuses on the Offline Store in SMP3/HCPms OData SDK. However, Content ID Referencing could make sense (or useful) when we have these reasons in general:


  1. You want (or need) to create parent and one or more related child entities in the same transaction.
  2. You choose to use a OData $batch changeset.
  3. You choose to create the relationship by issuing a POST request to the navigation URL of the parent entity (rather than, for example, using a deep insert)
  4. You do not have enough information to construct the edit URL of the parent entity (because some part of the key is generated)


Perhaps another common use case in which we want to use Content ID is when we create a header-items data via HANA Cloud Integration. HCI supports $batch request as a runtime. My buddy colleague Midhun VP wrote a tip of how to execute the $batch call through HCI.

hci.png

Prerequisites


Content ID Referencing is supported in the following versions:

 

  • SAP Gateway 2.0 SP12+
  • SAP NetWeaver 740 SP13+
  • SAP NetWeaver 750


You have a skillset of building basic CRUD OData services with SAP Gateway Workbench (tx code: SEGW) as explained here: #1 - OData CRUD Crash Course - Getting ready with offline store


Are you ready? Let's hop in the implementation.

cid_circle_75.png

Testing OData $batch Processing with Content ID in SAP Gateway

$
0
0

cid_150.png

This page is for explaining how to test the OData $batch services with Content ID, which is implemented in the H2G.


In this H2G, we're going through the steps of testing OData $batch services with Content ID by REST Client.


In the test steps, we'll create a $batch request that contains one parent entity with Content ID $100, and two children.

b_batch_payload.png

Two testing tools are explained:

 

SAP Gateway Client


In the SAP tx SEGW, find your Gateway project and select "Service Maintenance" > "Your GW System" > "SAP Gateway Client".

t1.png

In a SAP Gateway Client tool, enter following request information:


Note: SAP Gateway Client handles all the authentication info such as X-CSRF-Token or Basic Auth behind the scenes.


  • HTTP Method = POST
  • Request URI = the URL has $batch suffix
  • Content-Type = multipart/mixed;boundary=batch_mybatch
  • Payload body = enter the batch script

t2.png

And execute it - confirm the successful response.

t3.png

 

 

POSTMAN REST client


Start a POSTMAN REST client. Type the URL of your OData service document URL (the URL that ends with "_SRV/"). Set following params:

 

  • HTTP GET
  • Content-Type = multipart/mixed;boundary=batch_mybatch
  • X-CSRF-Token = Fetch
  • Authentication - (basic auth credentials)

c_1.png

Execute the request by pressing "Send". You should be able to obtain the returned x-csrf-token value. Copy it - this is required to execute HTTP POST later.

c_2.png

Paste the token value for X-CSRF-Token param in the header. Set following params:


  • HTTP POST - the URL has $batch suffix
  • Content-Type = multipart/mixed;boundary=batch_mybatch
  • X-CSRF-Token = <token>
  • Authentication - (basic auth credentials)

 

c_3.png

Now your POSTMAN is fully ready for sending the $batch payload. Click on "Body" and select raw.

c_0.png

Here you'll enter the payload. (Explanation follows)

 

01 --batch_mybatch
02 Content-Type: multipart/mixed; boundary=changeset_mychangeset1
03
04 --changeset_mychangeset1
05 Content-Type: application/http
06 Content-Transfer-Encoding: binary
07
08 POST HeaderSet HTTP/1.1
09 Content-Type: application/xml
10 Content-Length: 1021
11 Content-ID: 100
12
13 <?xml version="1.0" encoding="utf-8"?>
14 <entry xml:base="http://..._SRV/"
15     xmlns="http://www.w3.org/2005/Atom"
16     xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
17     xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
18     <content type="application/xml">
19         <m:properties>
20             <d:Id>1</d:Id>
21             <d:Text>New parent entity</d:Text>
22         </m:properties>
23     </content>
24 </entry> 
25
26 --changeset_mychangeset1
27 Content-Type: application/http
28 Content-Transfer-Encoding: binary
29
30 POST $100/ToItems HTTP/1.1
31 Content-Type: application/xml
32 Content-Length: 1021
33
34 <?xml version="1.0" encoding="utf-8"?>
35 <entry xml:base="http://..._SRV/"
36     xmlns="http://www.w3.org/2005/Atom"
37     xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
38     xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
39     <content type="application/xml">
40         <m:properties>
41             <d:ParentId></d:ParentId>
42             <d:Id>000010</d:Id>
43             <d:Text>First child entity</d:Text>
44         </m:properties>
45     </content>
46 </entry>
47
48 --changeset_mychangeset1
49 Content-Type: application/http
50 Content-Transfer-Encoding: binary
51
52 POST $100/ToItems HTTP/1.1
53 Content-Type: application/xml
54 Content-Length: 1021
55
56 <?xml version="1.0" encoding="utf-8"?>
57 <entry xml:base="http://..._SRV/"
58     xmlns="http://www.w3.org/2005/Atom"
59     xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
60     xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
61     <content type="application/xml">
62         <m:properties>
63             <d:ParentId></d:ParentId>
64             <d:Id>000020</d:Id>
65             <d:Text>Second child entity</d:Text>
66         </m:properties>
67     </content>
68 </entry>
69
70 --changeset_mychangeset1--
71 
72 --batch_mybatch--

#01 - The beginning of the $batch request. It has to start with "--" with the batch name, which is the same name you defined in the header of Content-Type = multipart/mixed;boundary=batch_mybatch.

#02 - Content type definition of the changeset.

#03 - This line space is very important. At least one "carriage return line feed" is required.

#04 - The beginning of the changeset. It has to start with "--" with the changeset name, which is the same name you defined in the line #02.

#05/06 - Conventional value for Content-Type and Content-Transfer-Encoding.

#07 - At least one "carriage return line feed" is required.

#08/09 - POST request for HeaderSet entity.

#10 - Content-Length value must be equal to or greater than the real length of the data below.

#11 - A line of the Content ID value.

#12 - At least one "carriage return line feed" is required.

#13 to 24 - The HeaderSet payload. You can obtain this payload format via Read operation. If you obtain the payload via Read, that should contain the tags like <id/>, <title/>, <updated/>, <category/>, and <link/>. You can keep them in this $batch payload or just discard them - the OData services simply ignore them.

#25 - At least one "carriage return line feed" is required.

#26 - As the next entity is a part of the same changeset, it has the same value with the line #04.

#27 to 29 - Same rule follows in the ItemSet.

#30 - POST request for ItemSet entity. As you see, the Content ID is being used.

#31 to 33 - Same rule follows in the ItemSet.

#34 to 46 - The ItemSet payload. Just like you did for HeaderSet entity, you can obtain this payload format via Read operation. Please note this payload has the empty value for <parentID> tag. During OData $batch processing, this value will be handled correctly via the Content ID value.

#47 to 69 - The second HeaderItem POST request.

#70 - The closing of the changeset. It has to start with "--" with the changeset name AND closing "--" characters.

#71 - At least one "carriage return line feed" is required.

#72 - The closing of the batch request. It has to start with "--" with the batch name AND closing "--" characters.

 

Let's execute the $batch request by pressing Send button. If the $batch processing is done correctly, you should be able to see "201 Created" responses for each entity in the returned payload body.


Note: As written, the line spacing is critical (it is a part of the standard OData specification).

c_8.png

Time to experiment further... try set the remote breakpoint in the ABAP editor - and see how the changeset_begin, changeset_process, and changeset_end are called sequentially.

cid_circle_75.png

How To Implement OData $batch Processing with Content ID in SAP Gateway

$
0
0

cid_150.png

Please read this introductory page explaining why we need to know how to implement OData $batch processing with Content ID.


In this H2G, we're going through step-by-step implementation of building OData $batch services with a a set of simple header & item ABAP database tables.


Table of Contents (Estimated Time)


  1. Define simple header & item tables (10 mins.)
  2. Creating association (= navigation resource path) (5 mins.)
  3. Build CRUD services for each entity (20 mins.)
  4. Enable $batch (changeset_begin/changeset_end) (10 mins.)
  5. The $batch implementation to handle Content ID (changeset_process) (20 mins.)
  6. Test it
  7. Appendix: HeaderSet & ItemSet code
  8. Appendix: changeset_process code

cid_circle_75.png

Define simple header & item tables


Let's create a set of header & item database tables in SE11. For the sake of the simplicity, here's a very simple design to demonstrate the idea.


(Note: In a real use case, add "MANDT" field for both zheader and zitem)

zheader.png

ZHEADER - ID is a key and TEXT is a small text value.

header.jpg

zitem.png

ZITEM - PARENT_ID (= ID of ZHEADER) and ID are the keys and TEXT is a small text value.

item.jpg

Once you created the ZHEADER and ZITEM database tables, go to the tx SEGW and create a project (this case the name is Z_CONTENTID). Right click on the Data Model node and select Import > DDIC Structure.

1.png

Type in the Name field - "Header" - this is the exact name of the OData entity. And ABAP Structure is zheader.

2.png

Select all the field to expose as OData.

3.png

Tick in ID row as "Is Key".

4.png

You created Header entity, the next one is Item. Right click on the Data Model node and select Import > DDIC Structure.

1.png

Type in the Name field - "Item" - And ABAP Structure is zitem.

5.png

Select all the field to expose as OData.

6.png

Tick in PARENT_ID and ID row as "Is Key".

7.png

You have created HeaderSet and ItemSet entities!

8.png

Back to Top

cid_circle_75.png

Creating association (= navigation resource path)


We're going to create a navigation resource path from Header to Item. More precisely - once we configure it, a Header entity (parent) can follow its Item entities (children)  by using the navigation path link such as HeaderSet('0000000001')/ToItems .

zh_zi.png

Right click on Associations > Create.

9.png

Name it as "HeaderItemAssociation" and select Entity Type Name for Header and Item. Be sure to set the Cardinality value as 1:n. You set the Navigation Property value as "ToItems" that will be displayed in the OData payload.

10.png

Select Dependent Property value as "ParentId" - now Header and Item is linked together with the key fields.

11.png

Confirm the default value and save it.

12.png

Now you have done with the Navigation Properties that navigates from Header to Item(s). The relationship is going to be calculated by the GW framework and rendered in an OData payload. (ex. HeaderSet('0000000001')/ToItems will return relevant ItemSet entities)

13.png

Back to Top

cid_circle_75.png

Build CRUD services for each entity


Time to build CRUD operations for each entity. First off, let's generate the base code by selecting Generate Runtime.

14.png

And - register the OData services by clicking on Service Maintenance > (Your GW) > Register.

15.png

Now your OData services became callable from HTTP client.


As described in the prerequisite section, you should have a skillset of building basic CRUD OData services with SAP Gateway Workbench (tx code: SEGW) as explained here: #1 - OData CRUD Crash Course - Getting ready with offline store .


At least we need Query & Read operation for header and item respectively  - we will use them during the test step later. The code is written in the appendix.


Back to Top

cid_circle_75.png

Enable $batch (changeset_begin/changeset_end)


Note: - the official SAP Gateway documentation about $batch processing about changeset_begin/end/process.


Let's implement $batch specific methods. Redefine CHANGESET_BEGIN of "/IWBEP/IF_MGW_APPL_SRV_RUNTIME".

18.png

01 METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_begin.
02
03   DATA ls_operation_info LIKE LINE OF it_operation_info.
04
05* set cv_defer_mode as TRUE to call changeset_process method
06    LOOP AT it_operation_info INTO ls_operation_info.
07      IF ls_operation_info-content_id IS NOT INITIAL OR
08         ls_operation_info-content_id_ref IS NOT INITIAL.
09        cv_defer_mode = abap_true.
10      ENDIF.
11    ENDLOOP.
12
13 ENDMETHOD.

The very important thing we need to understand here is once you redefine the changeset_begin, it will start the Logical Unit of Work (LUW) in ABAP that essentially means a transaction scope. And by setting the cv_defer_mode as TRUE, it will call the changeset_process method that will be explained in the next section.


The transaction scope means that in case of any failure happens during the changeset_process, all the database update will be rolled back.


Redefine CHANGESET_END of "/IWBEP/IF_MGW_APPL_SRV_RUNTIME".

19.png

01 METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_end.
02
03 ENDMETHOD.

Once the logic reaches the changeset_end, the COMMIT WORK will be automatically issued by the SAP Gateway framework.


Back to Top

cid_circle_75.png

The $batch implementation to handle Content ID (changeset_process)


Note: - the official SAP Gateway documentation about $batch processing about changeset_begin/end/process.


Redefine CHANGESET_PROCESS of "/IWBEP/IF_MGW_APPL_SRV_RUNTIME".

20.png

What the implementation needs to do is as follows:


  1. Obtain a changeset as an internal table "it_changeset_request".
  2. Loop it - and pick up each change request (= create request of each entity).
  3. When it is Header entity - create a header entity.
  4. When it is Item entity - create an item entity.

 

That's all. It is fairly simple - and I need to add the detailed explanation during the step 4. As we know the parent has Content ID, so the child needs to look up the Content ID and replace it with the finalized parent key. Here's the code to implement the step 4:


Note: - the entire code is in the appendix.


Note: - this is demonstrating the parent-child relationship, however you can implement any level of relationship (such as parent-child-grandchild-..) by using Content ID.


056            WHEN 'Item'.
057* Item entity
058              ls_changeset_request-entry_provider->read_entry_data( IMPORTING es_data = ls_item ).
059
060              IF ls_changeset_request-content_id_ref IS NOT INITIAL.
061* look up the parent by content id
062                READ TABLE it_changeset_request INTO ls_changeset_req_parent WITH KEY content_id = ls_changeset_request-content_id_ref.
063
064                IF ( sy-subrc = 0 ).
065                  READ TABLE ct_changeset_response INTO ls_changeset_resp_parent WITH TABLE KEY operation_no = ls_changeset_req_parent-operation_no.
066                  IF ( sy-subrc = 0 ).
067                    ASSIGN ls_changeset_resp_parent-entity_data->* TO .
068                    IF <ls_header>-id IS NOT INITIAL.
069* header key value is obtained for items
070                      ls_item-parent_id = <ls_header>-id.
071
072                      INSERT INTO zitem VALUES ls_item.
073
074                      IF ( sy-subrc = 0 ).
075* entity inserted
076                        copy_data_to_ref(
077                           EXPORTING
078                             is_data = ls_item
079                           CHANGING
080                             cr_data = ls_changeset_response-entity_data ).
081                      ELSE.
082* entity alredy exists - $batch will be rolled back
083                        CONCATENATE lv_entity_type
084                                    '('''
085                                    ls_item-parent_id
086                                    ','''
087                                    ls_item-id
088                                    ''')'
089                          INTO lv_error_entity.
090                        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
091                          EXPORTING
092                            textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
093                            entity_type = lv_error_entity.
094                      ENDIF.
095
096                      ls_changeset_response-operation_no = ls_changeset_request-operation_no.
097                      INSERT ls_changeset_response INTO TABLE ct_changeset_response.
098
099                    ENDIF.
100                  ENDIF.
101                ENDIF.
102              ENDIF.
103          ENDCASE. "end of lv_entity_type

#056 - case block if the entity is "Item".

#058 - read the payload data of Item entity.

#060 - check if the Item entity has "Content ID Reference" value (= the value should exist if the POST request is done with the $ ID)

#062 - if the Item has the reference value - the parent should have the value too.

#064 - should be TRUE if a related parent is found.

#065 - ct_changeset_response should contain a parent. Pick up the parent value - it should contain the finalized key.

#067 - load the parent data onto the ls_header structure.

#068 - the Header entity should contain the finalized key named "id".

#070 - set the parent's id to the child's "parent_id" field. This links both the parent and the child together.

#072 - insert the value in the zitem ABAP database table.

#074 to 080 - insert goes fine - returning the OData entity for "HTTP 201 Created".

#081 to 094 - insert failed - throw the Duplicate exception. The entire $batch request will roll back.

#096 to 097 - prepare the changeset response.


I believe you got a very clear idea how Content ID and Content ID reference value work in the $batch processing to glue the parent and children together.


Back to Top

cid_circle_75.png

Test it


Are you ready for testing the $batch service? That's the next step.


Back to Top


Appendix: HeaderSet & ItemSet code


HeaderSet entity CRUD implementation:

 

   Naming convention:    l - local scope   t - table   s - structure   v - variable   o - object

01 METHOD headerset_get_entityset.
02
03   DATA: lt_entityset TYPE TABLE OF zheader.
04
05   SELECT * FROM zheader INTO TABLE lt_entityset.
06
07   et_entityset = lt_entityset.
08
09 ENDMETHOD.
01 METHOD headerset_get_entity.
02
03   DATA: ls_key_tab   TYPE /iwbep/s_mgw_name_value_pair,
04         lv_id        TYPE vbeln,
05         ls_entityset TYPE zheader.
06
07   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
08   UNPACK ls_key_tab-value TO lv_id. "Converts 10 digits value
09
10   SELECT SINGLE * FROM zheader INTO ls_entityset WHERE id = lv_id.
11
12   er_entity = ls_entityset.
13
14  ENDMETHOD.
01 METHOD headerset_create_entity.
02
03   DATA: ls_entityset    TYPE zheader,
04         lv_error_entity TYPE string.
05
06   io_data_provider->read_entry_data( IMPORTING es_data = ls_entityset ).
07
08   INSERT INTO zheader VALUES ls_entityset.
09
10   IF ( sy-subrc = 0 ).
11* entity inserted
12     er_entity = ls_entityset.
13   ELSE.
14* entity alredy exists
15     CONCATENATE iv_entity_name
16                 '('''
17                 ls_entityset-id
18                 ''')'
19       INTO lv_error_entity.
20     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
21       EXPORTING
22         textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
23         entity_type = lv_error_entity.
24   ENDIF.
25
26 ENDMETHOD.
01 METHOD headerset_update_entity.
02
03   DATA: ls_entityset    TYPE zheader,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_id           TYPE vbeln,
06         lv_error_entity TYPE string.
07
08   io_data_provider->read_entry_data( IMPORTING es_data = ls_entityset ).
09
10* key is id
11   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
12   UNPACK ls_key_tab-value TO lv_id.
13
14* make sure the value matches with the one in OData payload
15   IF lv_id EQ ls_entityset-id.
16
17* new data
18     UPDATE zheader FROM ls_entityset.
19
20     IF ( sy-subrc = 0 ).
21* entity found and updated
22       er_entity = ls_entityset.
23     ELSE.
24* entity not found
25       CONCATENATE iv_entity_name
26                   '('''
27                   ls_key_tab-value
28                   ''')'
29         INTO lv_error_entity.
30       RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
31         EXPORTING
32           textid      = /iwbep/cx_mgw_busi_exception=>resource_not_found
33           entity_type = lv_error_entity.
34     ENDIF.
35   ENDIF.
36
37 ENDMETHOD.
01 METHOD headerset_delete_entity.
02
03   DATA: ls_entityset    TYPE zheader,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_id           TYPE vbeln,
06         lv_error_entity TYPE string.
07
08* key is id
09   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
10   UNPACK ls_key_tab-value TO lv_id.
11
12   DELETE FROM zheader WHERE id = lv_id.
13
14   IF ( sy-subrc = 0 ).
15* delete completed
16     ELSE.
17* entity not found
18     CONCATENATE iv_entity_name
19                 '('''
20                 ls_key_tab-value
21                 ''')'
22       INTO lv_error_entity.
23     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
24       EXPORTING
25         textid      = /iwbep/cx_mgw_busi_exception=>resource_not_found
26         entity_type = lv_error_entity.
27   ENDIF.
28
29 ENDMETHOD.

ItemSet entity CRUD implementation:

 

01 METHOD itemset_get_entityset.
02
03   DATA: lt_entityset TYPE TABLE OF zitem.
04
05   SELECT * FROM zitem INTO TABLE lt_entityset.
06
07   et_entityset = lt_entityset.
08
09 ENDMETHOD.
01 METHOD itemset_get_entity.
02
03   DATA: ls_key_tab   TYPE /iwbep/s_mgw_name_value_pair,
04         lv_parent_id TYPE vbeln,
05         lv_id        TYPE posnr,
06         ls_entityset TYPE zitem.
07
08   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
09   UNPACK ls_key_tab-value TO lv_parent_id.
10   READ TABLE it_key_tab INTO ls_key_tab INDEX 2.
11   UNPACK ls_key_tab-value TO lv_id.
12
13   SELECT SINGLE * FROM zitem INTO ls_entityset WHERE parent_id = lv_parent_id AND id = lv_id.
14
15   er_entity = ls_entityset.
16
17 ENDMETHOD.
01 METHOD itemset_create_entity.
02
03   DATA: ls_entityset    TYPE zitem,
04         lv_error_entity TYPE string.
05
06   io_data_provider->read_entry_data( IMPORTING es_data = ls_entityset ).
07
08   INSERT INTO zitem VALUES ls_entityset.
09
10   IF ( sy-subrc = 0 ).
11* entity inserted
12     er_entity = ls_entityset.
13   ELSE.
14* entity alredy exists
15     CONCATENATE iv_entity_name
16                 '('''
17                 ls_entityset-parent_id
18                 ','''
19                 ls_entityset-id
20                 ''')'
21       INTO lv_error_entity.
22     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
23       EXPORTING
24         textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
25         entity_type = lv_error_entity.
26   ENDIF.
27
28 ENDMETHOD.
01 METHOD itemset_update_entity.
02
03   DATA: ls_entityset    TYPE zitem,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_parent_id    TYPE vbeln,
06         lv_id           TYPE posnr,
07         lv_error_entity TYPE string.
08
09   io_data_provider->read_entry_data( IMPORTING es_data = ls_entityset ).
10
11* key is parent_id and id
12   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
13   UNPACK ls_key_tab-value TO lv_parent_id.
14   READ TABLE it_key_tab INTO ls_key_tab INDEX 2.
15   UNPACK ls_key_tab-value TO lv_id.
16
17* make sure the value matches with the one in OData payload
18   IF lv_parent_id EQ ls_entityset-parent_id AND lv_id EQ ls_entityset-id.
19
20* new data
21     UPDATE zitem FROM ls_entityset.
22
23     IF ( sy-subrc = 0 ).
24* entity found and updated
25       er_entity = ls_entityset.
26     ELSE.
27* entity not found
28       CONCATENATE iv_entity_name
29                   '('''
30                   lv_parent_id
31                   ','''
32                   lv_id
33                   ''')'
34            INTO lv_error_entity.
35       RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
36         EXPORTING
37           textid      = /iwbep/cx_mgw_busi_exception=>resource_not_found
38           entity_type = lv_error_entity.
39     ENDIF.
40   ENDIF.
41
42 ENDMETHOD.
01 METHOD itemset_delete_entity.
02
03   DATA: ls_entityset    TYPE zitem,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_parent_id    TYPE vbeln,
06         lv_id           TYPE posnr,
07         lv_error_entity TYPE string.
08
09* key is parent_id and id
10   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
11   UNPACK ls_key_tab-value TO lv_parent_id.
12   READ TABLE it_key_tab INTO ls_key_tab INDEX 2.
13   UNPACK ls_key_tab-value TO lv_id.
14
15   DELETE FROM zitem WHERE parent_id = lv_parent_id AND id = lv_id.
16
17   IF ( sy-subrc = 0 ).
18* delete completed
19   ELSE.
20* entity not found
21     CONCATENATE iv_entity_name
22                 '('''
23                 lv_parent_id
24                 ','''
25                 lv_id
26                 ''')'
27        INTO lv_error_entity.
28     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
29       EXPORTING
30         textid      = /iwbep/cx_mgw_busi_exception=>resource_not_found
31         entity_type = lv_error_entity.
32   ENDIF.
33
34 ENDMETHOD.

Back to Top


Appendix: changeset_process code

 

001  METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_process.
002
003    DATA:
004      ls_changeset_request     TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request,
005      ls_changeset_req_parent  TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request,
006      lo_create_context        TYPE REF TO /iwbep/if_mgw_req_entity_c,
007      lv_entity_type           TYPE string,
008      ls_changeset_response    TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response,
009      ls_changeset_resp_parent TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response,
010      ls_header                TYPE zcl_zcontentid_mpc=>ts_header, "replace the mcp class name for your own
011      ls_item                  TYPE zcl_zcontentid_mpc=>ts_item, "replace the mcp class name for your own
012      lv_error_entity          TYPE string.
013
014    FIELD-SYMBOLS:
015      <ls_header>              TYPE zcl_zcontentid_mpc=>ts_header. "replace the mcp class name for your own
016
017    LOOP AT it_changeset_request INTO ls_changeset_request.
018
019      lo_create_context ?= ls_changeset_request-request_context.
020      lv_entity_type = lo_create_context->get_entity_type_name( ).
021
022      CASE ls_changeset_request-operation_type.
023        WHEN /iwbep/if_mgw_appl_types=>gcs_operation_type-create_entity.
024* create (HTTP POST)
025          CASE lv_entity_type.
026* which entity? The name is case sensitive
027            WHEN 'Header'.
028* Header entity
029              ls_changeset_request-entry_provider->read_entry_data( IMPORTING es_data = ls_header ).
030
031              INSERT INTO zheader VALUES ls_header.
032
033              IF ( sy-subrc = 0 ).
034* entity inserted
035                copy_data_to_ref(
036                   EXPORTING
037                     is_data = ls_header
038                   CHANGING
039                     cr_data = ls_changeset_response-entity_data ).
040              ELSE.
041* entity alredy exists - $batch will be rolled back
042                CONCATENATE lv_entity_type
043                            '('''
044                            ls_header-id
045                            ''')'
046                  INTO lv_error_entity.
047                RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
048                  EXPORTING
049                    textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
050                    entity_type = lv_error_entity.
051              ENDIF.
052
053              ls_changeset_response-operation_no = ls_changeset_request-operation_no.
054              INSERT ls_changeset_response INTO TABLE ct_changeset_response.
055
056            WHEN 'Item'.
057* Item entity
058              ls_changeset_request-entry_provider->read_entry_data( IMPORTING es_data = ls_item ).
059
060              IF ls_changeset_request-content_id_ref IS NOT INITIAL.
061* look up the parent by content id
062                READ TABLE it_changeset_request INTO ls_changeset_req_parent WITH KEY content_id = ls_changeset_request-content_id_ref.
063
064                IF ( sy-subrc = 0 ).
065                  READ TABLE ct_changeset_response INTO ls_changeset_resp_parent WITH TABLE KEY operation_no = ls_changeset_req_parent-operation_no.
066                  IF ( sy-subrc = 0 ).
067                    ASSIGN ls_changeset_resp_parent-entity_data->* TO <ls_header>.
068                    IF <ls_header>-id IS NOT INITIAL.
069* header key value is obtained for items
070                      ls_item-parent_id = <ls_header>-id.
071
072                      INSERT INTO zitem VALUES ls_item.
073
074                      IF ( sy-subrc = 0 ).
075* entity inserted
076                        copy_data_to_ref(
077                           EXPORTING
078                             is_data = ls_item
079                           CHANGING
080                             cr_data = ls_changeset_response-entity_data ).
081                      ELSE.
082* entity alredy exists - $batch will be rolled back
083                        CONCATENATE lv_entity_type
084                                    '('''
085                                    ls_item-parent_id
086                                    ','''
087                                    ls_item-id
088                                    ''')'
089                          INTO lv_error_entity.
090                        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
091                          EXPORTING
092                            textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
093                            entity_type = lv_error_entity.
094                      ENDIF.
095
096                      ls_changeset_response-operation_no = ls_changeset_request-operation_no.
097                      INSERT ls_changeset_response INTO TABLE ct_changeset_response.
098
099                    ENDIF.
100                  ENDIF.
101                ENDIF.
102              ENDIF.
103          ENDCASE. "end of lv_entity_type
104      ENDCASE."end of create_entity
105    ENDLOOP.
106  ENDMETHOD.

Back to Top

Update Entity Operation Taking Time To Trigger...

$
0
0

Hi,

 

I have implemented Update entity operation with a simple code.

The issue is that, when I am triggering URL from UI5 application it is taking 7 sec to reach ABAP code however when I am hitting same URL from gateway client it is taking milliseconds to reach ABAP code...

 

Any suggestions...

 

 

-Amol S

Viewing all 2823 articles
Browse latest View live