Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 

In this Blog, I will explain creating Gateway Service with Read and Query operations using Date as an Input.  Before starting, I am expecting that you have basic idea of Gateway Service.

The reason for writing this Blog is, I had a requirement where I need to get the data from back-end system based on Date Field. I have searched Google but I was not able to find proper information on this requirement.

Scenario:

Search for flight details on given date and between the date ranges.

Procedure:


We have created ZSFLIGHT_DETAILS Gateway project to get the data based on Date Field as shown below.

Right Click on the Data Model folder and select Import DDIC structure and give the Entity Type Name as Sflight and select the required properties for the Entity Type.

In the Entity Type properties check Fldate as Key Field. Our Entity Type and its properties look as below.

Then click on Generate Runtime objects. It will display "Generated Objects Successfully”, all the required classes will be generated automatically.

1. Read Operation Using Date:


When user inputs date to find a flight on particular date. For this scenario we need to redefine SFLIGHTSET_GET_ENTITY method in the *DPC_EXT class and implement the below logic to read the data based on Date.

Code:

METHOD sflightset_get_entity.


*Data Declarations
DATA: ls_key LIKE LINE OF it_key_tab.

READ TABLE it_key_tab INTO ls_key WITH KEY name = 'Fldate'.

IF sy-subrc = 0.

SELECT SINGLE * FROM sflight INTO er_entity WHERE fldate = ls_key-value

  ENDIF.


ENDMETHOD.


2. Query Operation Using Date as filter:


When user wants to find flights between dates. For this scenario we need to redefine SFLIGHTSET_GET_ENTITYSET method in the *DPC_EXT class and implement the below logic to get the data based on Date Using Filter Query.

Code:


method SFLIGHTSET_GET_ENTITYSET.

*Data Declarations
DATA lo_filter                   TYPE  REF TO /iwbep/if_mgw_req_filter"Filter System Query Option Class
        lv_filter_str              
TYPE string,      "Filter Declaration
        lv_fldate                  
TYPE s_date,
        lt_filter_select_options   
TYPE /iwbep/t_mgw_select_option,
        r_date                     
TYPE RANGE OF sflight-fldate,
        ls_date                    
LIKE LINE OF r_date,
        lt_select_options          
TYPE /iwbep/t_cod_select_options,
        ls_filter_select_options   
LIKE LINE OF lt_filter_select_options,
        ls_select_options          
TYPE /iwbep/s_cod_select_option.

*Read the filter Select options
READ TABLE IT_FILTER_SELECT_OPTIONS INTO ls_filter_select_options INDEX 1.

IF sy-subrc = 0.
lt_select_options
= ls_filter_select_options-select_options.
ENDIF.


*Read the select options
READ TABLE lt_select_options INTO ls_select_options INDEX 1.

IF sy-subrc = 0.

ls_date
-sign    = 'I' .
ls_date
-option  = 'BT'.
ls_date
-low     = ls_select_options-low.
ls_date
-high    = ls_select_options-high.
APPEND ls_date TO r_date.
CLEAR ls_date.
ENDIF.


*To fetch the data from sflight based on Date Range

SELECT mandt carrid connid fldate FROM sflight INTO TABLE et_entityset
WHERE fldate IN r_date.
endmethod.

Testing Our Services:

Now we will test our service in Gateway Client transaction /IWFND/MAINT_SERVICE


In order to get the data for flight on given date use the following URI using HTTP GET Method.


URI: /sap/opu/odata/sap/ZSFLIGHT_DETAILS_SRV/SflightSet(Fldate=datetime'1995-02-28T00:00:00')


Service Response:

In order to get the flight details between the given date ranges, use the following URI using HTTP GET Method.

URI: /sap/opu/odata/sap/ZSFLIGHT_DETAILS_SRV/SflightSet?$filter=Fldate ge datetime'1995-02-28T00:00:00' and Fldate le datetime'1997-08-30T00:00:00'

Service Response:

Thanks&Regards,

Gangadhar B

9 Comments
Labels in this area