August 2016 - Sap 4 All

Latest

Wednesday, 17 August 2016

SAP NetWeaver Gateway is a technology that provides a simple way to connect devices, environments and platforms to SAP software based on market standards. Completely flexible, SAP NetWeaver Gateway offers connectivity to SAP applications using any programming language or model without much need for SAP knowledge by leveraging REST services and OData/ATOM protocols.

Below are the generally used,

HTTP_METHODS:
GET        : Get Entityset or Entity
POST      : Create
PUT        : Update


DELETE   : Delete

Usual errors while testing the services:

400   Bad Request
1. When CSRF Token not added
2. Types of data sent are inconsistent

407   Method not allowed
1. URL/Request format and the selected HTTP Method are inconsistent.

500   Internal Server Error
1. If SQL Queries fail resulting in duplicate entries

These are the very common errors and will be updating the list going forward.

CSRF - Cross-Site Request Forgery: 
This is needed while sending create and update requests. Call the GET service to get the CSRF Token first and perform the create/update operation using the generated token.

*****************************************

Below are the methods implemented to get the service working for different purposes and explanation regarding the Method Parameters to be used while coding.

*_GET_ENTITYSET:


IV_ENTITY_NAME
Entity Name
IV_ENTITY_SET_NAME
Entity Set Name
IV_SOURCE_NAME
Entity Name
IT_FILTER_SELECT_OPTIONS
Values mentioned in FILTER Clause. But better to get it like given for IT_ORDER.
IS_PAGING
We do get TOP and SKIP values given in service URL and can be used to fetch data from database. This is for Paging of the data.
IT_KEY_TAB
This comes into picture when using Associations. Key value mentioned with Principal Entity.
IT_NAVIGATION_PATH
This comes into picture when using Associations
IT_ORDER
Fields mentioned for $orderby Clause. But better to get it fromIO_TECH_REQUEST_CONTEXT->GET_ORDERBY() method as this will give correct field mapping.
IV_FILTER_STRING
Gives the FILTER String given on URL by $filter
IV_SEARCH_STRING
Strings used with Clause search will be in this parameter
IO_TECH_REQUEST_CONTEXT
Mentioned Format, Request ID, orderby, User Name, Service Path, Filter Values (FILTER_SELECT_OPTIONS), GET_TOP, GET_SKIP and Navigation Path etc. will be available in this instance. Look for the methods in this interface.
ET_ENTITYSET
Fill this internal table to show the entries in output
ES_RESPONSE_CONTEXT
This is to fill HTTP Response Header parameters. Custom HTTP Header parameters can be set using below procedure. This can be used, when some kind of extra  message to be passed to the UI when the response is a success.

DATA:ls_header TYPE ihttpnvp.
ls_header
-name 'my-custom-message'.
ls_header
-value '{msg_typ:S, desc: Data Retrieved}'.
/iwbep/if_mgw_conv_srv_runtime
~set_headerls_header ).



*_GET_ENTITY:

IV_ENTITY_NAME
Entity Name
IV_ENTITY_SET_NAME
Entity Set Name
IV_SOURCE_NAME
Entity Name
IT_KEY_TAB
Red colored value will be captured into this table. Let’s say key fields declared at Gateway Level.
If the request url is the below,
/sap/opu/odata/sap/ZMA_EMPS_SRV/Emp_DataSet('00000001')

IO_TECH_REQUEST_CONTEXT
Mentioned Format, Request ID, orderby, User Name, Service Path, Filter Values (FILTER_SELECT_OPTIONS), GET_TOP, GET_SKIP and Navigation Path etc. will be available in this instance. Look for the methods in this interface.
IT_NAVIGATION_PATH               
This comes into picture when using Associations
ER_ENTITY
Output data will be populated into this
ES_RESPONSE_CONTEXT
This is to fill HTTP Response Header parameters. Custom HTTP Header parameters can be set using below procedure.

DATA:ls_header TYPE ihttpnvp.
ls_header
-name 'my-custom-message'.
ls_header
-value '{msg_typ:S, desc: Data Retrieved}'.
/iwbep/if_mgw_conv_srv_runtime
~set_headerls_header ).


*_CREATE_ENTITY:


IV_ENTITY_NAME
Entity Name
IV_ENTITY_SET_NAME
Entity Set Name
IV_SOURCE_NAME
Entity Name
IT_KEY_TAB
As Described Above
IO_TECH_REQUEST_CONTEXT
HTTP Method, Format of data, Operation etcAs Described Above

IT_NAVIGATION_PATH
As Described Above
IO_DATA_PROVIDER
Get the input data by the request can be retrieved using method READ_ENTRY_DATA.IO_DATA_PROVIDER-> READ_ENTRY_DATA( ).
ER_ENTITY
Fill this structure to show up the created entry in the Output Response.

*_UPDATE_ENTITY:

Same as *_CREATE_ENTITY

*_DELETE_ENTITY:

All Parameters                                  - As described above

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY



Build final table with exact deep structure ER_DEEP_ENTITY has. 

IO_EXPAND
IO_EXPAND-> MT_CHILDREN will contain below. Navigation property name should be appended toET_EXPANDED_TECH_CLAUSES


ER_ENTITY
This will be a Deep Structure to hold header as well as Item data.
ET_EXPANDED_CLAUSES
Obsolete. Below is the replacement.
ET_EXPANDED_TECH_CLAUSES
Navigation property name should be appended toET_EXPANDED_TECH_CLAUSES(This will be the name of child entityset). If this is not done, Method will be triggered number of times(as per number of records) though the data is filled in the first iteration.

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET:


All the parameters have been covered above.

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY:


All the parameters have been covered above.

Build final table with exact deep structure ER_DEEP_ENTITY has. 

Make sure the deep internal table named after child entityset. If not item data will not be populated.

CREATE _ENTITY and CREATE_DEEP_ENTITY will be called based on the input request given. If the request contains deep body then CREATE_DEEP_ENTITY will be called.

Sunday, 14 August 2016

Go to the T-Code SPRO --> SAP Reference IMG


Than Go to SAP Netweaver --> Gateway --> oData Channel --> Administartion --> General Settings --> Activate and Maintain Services



OR use the T-Code /IWFND/MAINT_SERVICE to activate and maintain SAP oData Services

 Click on Add Services


Than Provide you System Alias name and Click Get Services -> Select the service and than Add the Selected Service


Once the Service is added Click on the ICF Node and than Activate the Service.




After Activation the oData Service will be shown in Green.

Thursday, 11 August 2016

Go through the below post first, before starting with this content.


Two tables ZMA_GW_EMPZMA_GW_EMP_DEP are created in the working example. Lets maintain some data in these tables and check how the data will be returned using the gateway client requests.


Employee Header Data: ZMA_GW_EMP




Employee Dependents Data: ZMA_GW_EMP_DEP


Service Name: ZMA_EMPS_DEMO_SRV

Entities: Emp_Data
    Dependent_Data
   
EntitySets: Emp_DataSet
        Dependent_DataSet
     
Association Name: Emp_Dependents




Example URIs to Test:


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet('00000001')/Dependent_Dataset?$format=json



/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet/$count?$filter=Employee gt '00000001'

Response: 3

/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet?$filter=Employee eq '00000001'&$expand=Dependent_Dataset

Response:  SAPNTGW - EXPAND Test Response


/sap/opu/odata/sap/ZMA_EMPS_SRV/Emp_DataSet?$filter=Employee eq '00000001'&$expand=Dependent_Dataset&$format=json

Response:   SAPNTGW - EXPAND_JSON Test Response



/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet?$filter=Employee eq '00000001'

Response:   SAPNTGW - FILTER Test Response


/sap/opu/odata/sap/ZMA_EMPS_SRV/Emp_DataSet?$filter=Employee ge '00000001' and EmployeeName eq 'Employee1'

Response:   SAPNTGW - FILTER_MULTIPLE_KEYS Test Response


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet('00000001')/Employee

Response:

<?xml version="1.0" encoding="UTF-8"?>
<d:Employeexmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">00000001</d:Employee>




/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Dependent_DataSet(Employee='00000001',DepNo='002')?$format=json


Response: 
{
  
"d" : {
    
"__metadata" : {
      
"id" "http://devdgw-ci.sap.umb.vqss.com:8001/sap/opu/odata/sap/ZMA_EMPS_SRV/Dependent_DataSet(Employee='00000001',DepNo='002')",
      
"uri" "http://devdgw-ci.sap.umb.vqss.com:8001/sap/opu/odata/sap/ZMA_EMPS_SRV/Dependent_DataSet(Employee='00000001',DepNo='002')",
      
"type" "ZMA_EMPS_SRV.Dependent_Data"
    },
    
"Employee" "00000001",
    
"DepNo" "002",
    
"DepType" "0001",
    
"DependentName" "Dependent2"

  }
}



/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet?$orderby=EmployeeName desc&$format=json

Response:   SAPNTGW - ORDERBY_DESC_JSON Test Response



/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet('00000001')/Employee/$value

Response: 00000001


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet?$select=Employee


Response:   SAPNTGW - SELECT Test Response


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Dependent_DataSet?$format=json

Response:   SAPNTGW - GET_ENTITYSET Test Response


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet


Request: 
        {
  "d" : {

    
"Employee" "00000008",
    
"EmployeeName" "Employee8"

  }
}

Response: Employee will be created


/sap/opu/odata/SAP/ZMA_EMPS_DEMO_SRV/Emp_DataSet

Request:

{
  
"d" : {
        
"Employee" "00000009",
        
"EmployeeName" "Employee9",
        
"Dependent_Dataset" : [
            {
              
"Employee" "00000009",
              
"DepNo" "001",
              
"DepType" "0001",
              
"DependentName" "Dependent1"

            }
            ]
        }
      }


Response: Employee will be created along with dependents