Friday, 19 July 2019

Gateway – OData Post using Postman

In this blog i’m gonna demonstrate how to use Postman to execute Post calls to a SAP Gateway server.

Then, create the Z table below in your backend (assuming it’s a Hub scenario) server:

SAP ABAP Study Materials, SAP ABAP Online Exam, SAP ABAP Tutorials and Materials, SAP ABAP Learning

After that, create both RFC enabled Functional Modules:

function zdemo_gw_post.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_POST) TYPE  ZPOST1 OPTIONAL
*"----------------------------------------------------------------------
  "Just get it in there...
  modify zpost1 from im_post.
  commit work.
endfunction.

function zdemo_gw_post_read.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_FIELD1) TYPE  CHAR10 OPTIONAL
*"  EXPORTING
*"     VALUE(EX_POST) TYPE  ZPOST1
*"----------------------------------------------------------------------
  select single *
    from zpost1
    into ex_post
    where field1 = im_field1.
endfunction.

Now setup your ZDEMO_POST Gateway project (SEGW) like this:

SAP ABAP Study Materials, SAP ABAP Online Exam, SAP ABAP Tutorials and Materials, SAP ABAP Learning

Your Object Entity (ref from the Z table) with same Key field:

SAP ABAP Study Materials, SAP ABAP Online Exam, SAP ABAP Tutorials and Materials, SAP ABAP Learning

Create implementation:

SAP ABAP Study Materials, SAP ABAP Online Exam, SAP ABAP Tutorials and Materials, SAP ABAP Learning

Read implementation:

SAP ABAP Study Materials, SAP ABAP Online Exam, SAP ABAP Tutorials and Materials, SAP ABAP Learning

Setup your Service to your backend Alias:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

After that you’re all set on the Gateway/ABAP side.

Now let’s open Postman:

Create a Request (saving in a Collection, to group calls):

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

To get it, you need to execute a GET call fetching the token, so let’s do it:

Execute a GET cal, you could just get the metadata with the following URL:  SERVER:PORT/sap/opu/odata/sap/ZDEMO_POST_SRV/$metadata

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

In the Authorization tab, select Basic Auth and enter your Gateways user/password:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

Hit Send, and the metadata returns with success:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

So it’s communicating šŸ‘, now to get the Token, in the Headers Tab, add a entry with x-csrf-token = Fetch, like below:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

After executing the service, note that the token gets returned in the Headers Tab.

Now we’re all set to execute the POST call, so we change it like below:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

SERVER:PORT/sap/opu/odata/sap/ZDEMO_POST_SRV/ObjectSet

Change the Token to the value returned:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

In the Body section, insert this XML (change to the values that you want to be inserted in each XML Field):

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="/sap/opu/odata/sap/ZDEMO_POST_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">
 <title type="text">ObjectSet</title>
 <updated>2019-07-18T17:50:32Z</updated>
 <category term="ZDEMO_POST_SRV.Object" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
 <link href="ObjectSet" rel="self" title="Object"/>
 <content type="application/xml">
  <m:properties>
   <d:Field1>WIKI</d:Field1>
   <d:Field2>FIELD2</d:Field2>
   <d:Field3>FIELD3</d:Field3>
  </m:properties>
 </content>
</entry>

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

Send, if everything is correct, 201 status is returned:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

The data inserted in the Z table:

ABAP Development, SAP ABAP Tutorials and Materials, SAP ABAP Study Materials, SAP ABAP Online Exam

2 comments:

  1. i will see your post it was a nice
    best matrimonial site
    best matrimonial site

    Sulekha.com is one of India’s best digital platforms for local service businesses and internet marketing that help for user generates leads.

    ReplyDelete