13
Odata Services 1. Create structure in SE11 and create FM in SE37 as per the requirement 2. Create new project in SEGW

Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Embed Size (px)

Citation preview

Page 1: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Odata Services

1. Create structure in SE11 and create FM in SE37 as per the requirement

2. Create new project in SEGW

Page 2: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Give the structure name:-

Page 3: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

The above checked fields will be shown in the output after testing the service.

The above checked boxes shows the inputs pass into the service for testing, means which fields

we want to pass in the input parameter of the service.

Now click on SAVE button and then click on GENERATE button

Page 4: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”
Page 5: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

After the service got generated then enter the method:-

GetEntity Method is used to return single output only means in structure it will return single

value.

GetEntitySet Method is used to return Multiple records in the structure.

Now we will describe each method with its format.

Page 6: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

GetEntity Method :-

To implement the method name click on the ABAP workbench.

Page 7: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Now click on Redifine:-

Code for reference:- *** DATA: ls_key TYPE /iwbep/s_mgw_name_value_pair.

***

*** DATA kunnr TYPE kunnr.

*** DATA plant TYPE werks_d.

*** DATA gt_address TYPE STANDARD TABLE OF zod_mob_shiptoparty_addr.

***

***

*** READ TABLE it_key_tab INTO ls_key WITH KEY name = 'Shiptopartyid'.

*** IF sy-subrc EQ 0 AND ls_key-value IS NOT INITIAL.

*** kunnr = ls_key-value.

*** ENDIF.

***

*** READ TABLE it_key_tab INTO ls_key WITH KEY name = 'Plant'.

*** IF sy-subrc EQ 0 AND ls_key-value IS NOT INITIAL.

*** plant = ls_key-value.

*** ENDIF.

***

***

*** CALL FUNCTION 'ZODATA_SHIPTOPARTY_ADDR'

*** EXPORTING

*** kunnr = kunnr

*** plant = plant

*** TABLES

*** gt_address = er_entity.

In er_entity structure the output will return only single value.

Page 8: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

GetEntitySet Method

Page 9: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Click on redefine.

Code for reference:-

DATA: lt_filters TYPE /iwbep/t_mgw_select_option,

ls_filter TYPE /iwbep/s_mgw_select_option,

lw_sopt TYPE /iwbep/s_cod_select_option.

DATA kunnr TYPE kunnr.

DATA plant TYPE werks_d.

DATA gt_address TYPE STANDARD TABLE OF zod_mob_shiptoparty_addr.

* Start of change for Cross domain issue

DATA: ls TYPE ihttpnvp.

ls-name = 'Access-Control-Allow-Origin'.

ls-value = '*'.

/iwbep/if_mgw_conv_srv_runtime~set_header( is_header = ls ).

* End of change for cross domain issue

lt_filters = io_tech_request_context->get_filter( )->get_filter_select_options( ).

*-get filter for ProductID

lt_filters = it_filter_select_options.

READ TABLE lt_filters WITH TABLE KEY property = 'Plant' INTO ls_filter.

READ TABLE ls_filter-select_options INTO lw_sopt INDEX 1.

IF sy-subrc EQ 0.

plant = lw_sopt-low.

ENDIF.

Page 10: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

READ TABLE lt_filters WITH TABLE KEY property = 'Shiptopartyid' INTO ls_filter.

READ TABLE ls_filter-select_options INTO lw_sopt INDEX 1.

IF sy-subrc EQ 0.

kunnr = lw_sopt-low.

ENDIF.

CALL FUNCTION 'ZODATA_SHIPTOPARTY_ADDR'

EXPORTING

kunnr = kunnr

plant = plant

TABLES

gt_address = ET_ENTITYSET.

After implementing the methods click on activate and generate button and save the code.

Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings-

>Activate and Maintain Services

Click on the “Add Services” button

Page 11: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Clicl on ‘Add Selected Services” and then click “Continue”

Page 12: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

Click on ‘Gateway Client” and execute the URL link.

Copy the href link to the URL.

After Service registration on Netweaver Gateway we will now test our service using the format of 2

different methods by passing input values into it.

GetEntity Method =

http://srnoidbd02.vecvnet.com:8000/sap/opu/odata/sap/ZODATA_SERVICES_SRV/zod_servicesSet(Matnr='80501032',

Werks='1000',ValidDate='31.12.9999')

GetEntitySet Method =

http://srnoidbd02.vecvnet.com:8000/sap/opu/odata/sap/ZOD_SHIPTOPARTY_ADDR_SRV_01/zod_mob_shiptoparty_ad

drSet?$filter=Shiptopartyid eq '120000011' and Plant eq '1020'

Page 13: Odata Services - sapdbm.com · Now go to SPRO->SAP Netweaver->Gateway->Odata Channel->Administration->General Settings->Activate and Maintain Services Click on the “Add Services”

The above marked fields are those fields which we have selected to display in output during our

creation of service in SEGW.