OData is Rest-based protocol, used to retrieve and update the data. It acts as a medium between front-end and back-end.

Now our requirements are to build an ODATA service to fetch plant details based on company code and to fetch material details based on plant.

Step 1: Go to SEGW transaction, Create a project.

Step 2: Provide the project name, description and package. Click on continue.

Then the components like

  1. 1. Data Model
  2. 2. Service Implementation
  3. 3. Runtime Artifacts
  4. 4. Service Maintenance

Gets displayed automatically.

 

Step 3: Our project looks as below.

Step 4Now we need to build our Data model, first Create the Entity type by importing a DDIC Structure.

Step 5: Give the Entity type name and DDIC STRUCTURE to be imported and click on next.

Step 6: Select the required fields from the DDIC structure and click on next.

Step 7: Follow the steps 4 & 5 for plant details and select Werks field as the key.

Step 8: Follow the steps 4 & 5 for material details and select material number as key.

Step 9: Now we need to generate runtime artifacts. for that, you need to select Runtime Artifacts and click on

Click OK and save it.

Step 10: Right click on get entity set->go to ABAP workbench and redefine the methods.

Then we need to right click on the methods and redefine required methods in the following process.

Step 11: To get company codes, write the code as follows.

method COMPANYCODESET_GET_ENTITYSET.

SELECT bukrs FROM zsh_cds_Dlk1 Into CORRESPONDING FIELDS OF TABLE et_entityset.

end method.

Step 12: In the same way, redefine get entity set method for plant details.

 

write the logic as follows.

method PLANTSET_GET_ENTITYSET.

DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,

lt_plant TYPE TABLE OF zsh_cds_Dlk,

ls_plant TYPE zsh_cds_Dlk,

it_entityset TYPE ZCL_ZCREATE_PROJECT_MPC=>TT_PLANT,

ls_entity LIKE LINE OF et_entityset,

lv_soid TYPE bapi_epm_so_id,

WA TYPE ZSH_CDS_DLK,

lv type BUKRS ,”value ‘0001’,

ls_FILTER_SELECT_OPTIONS TYPE /IWBEP/S_MGW_SELECT_OPTION.

READ TABLE IT_FILTER_SELECT_OPTIONS INTO ls_FILTER_SELECT_OPTIONS INDEX 1.

lv = ls_FILTER_SELECT_OPTIONS-select_options[ 1 ]-low.

SELECT WERKS FROM ZSH_CDS_DLK( p_bukrs = @lv ) INTO CORRESPONDING FIELDS OF TABLE @it_entityset.

LOOP AT it_entityset INTO WA .

MOVE-CORRESPONDING WA TO LS_ENTITY.

APPEND LS_ENTITY TO ET_ENTITYSET.

ENDLOOP.

ENDMETHOD.

Step 13: Redefine material entity set method and write the logic to get material details as below.

method MATERIALSET_GET_ENTITYSET.

DATA WA TYPE ZSH_CDS_DLK2.

DATA:

ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,

lt_plant TYPE TABLE OF ZSH_CDS_DLK2,

ls_plant TYPE ZSH_CDS_DLK2,

it_entityset TYPE ZCL_ZCREAT_PROJECT_MPC=>TT_MATERIAL,

ls_entity LIKE LINE OF et_entityset,

lv_soid TYPE bapi_epm_so_id,

* lv type marc-werks ,”value ‘0001’,

lv TYPE WERKS_D,

ls_FILTER_SELECT_OPTIONS TYPE /IWBEP/S_MGW_SELECT_OPTION.

READ TABLE IT_FILTER_SELECT_OPTIONS INTO ls_FILTER_SELECT_OPTIONS INDEX 1.

lv = ls_FILTER_SELECT_OPTIONS-select_options[ 1 ]-low.

SELECT matnr FROM ZSH_CDS_DLK2( P_PLANT = @lv ) INTO CORRESPONDING FIELDS OF TABLE @it_entityset.

LOOP AT it_entityset INTO WA.

MOVE-CORRESPONDING WA TO LS_ENTITY.

APPEND LS_ENTITY TO ET_ENTITYSET.

ENDLOOP.

end method.

Step 14: Go to transaction /IWFND/MAINT_SERVICE and add service Press enter

 

Step 15: After adding that service gives system alias as a ‘LOCAL’ and click on get services select your service name.

Step 16: Select your service and go back and search your service it will be added are not.

Step 17: Select your service and click on sap gateway client.

Step 18: Start the Gateway Client (Transaction /IWFND/GW_CLIENT) in a separate window to run the service. Provide the following URI to get the metadata for the service:
/sap/opu/odata/sap/ZCREATE_project_SRV/$metadata

Step 19: Go to client transaction and select entity set as company code.Click on execute. The output is as follows. and select entity set as company code Click on execute. Then company code data will be displayed.

Step 20: Go to client transaction Select entity set has plant set Change the URI as shown below to display plant details for company code equals to ‘0005’ using filter functionality.

Step 21: Change the URI as shown below to display material details for plant equals to ‘0001’ using filter functionality.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Jelena Perfiljeva

    I appreciate you taking time to share this with the community but there was a very similar blog already posted almost a year ago. This blog could’ve been an improvement if it added more information as to why are these steps performed.

    E.g. what is “project”, what is “entity type”? Why did you chose Plant as key when the service is by Company code? What is that filter thing? Couldn’t you just use a standard table as an example instead of Z one? Poor formatting, random capitalization and errors are making the blog difficult to read and understand.

    I’m sure many people will gobble this up regardless (the “screenshot blogs” seem to be quite popular) but this could’ve been much, much better blog with just a little bit of more effort and attention to detail. Simply posting screenshots once again just doesn’t add a lot of value IMHO sorry!

    To those who are interested in more than just following the steps I recommend this blog and this one.

    Edit: and yet another, better step-by-step guide: https://blogs.sap.com/2012/10/26/step-by-step-guide-to-build-an-odata-service-based-on-rfcs-part-1/

    Kindly search Google for existing blogs first, going forward.

    (0) 

Leave a Reply