DDIC structure

Odata service implementation for GET_ENTITY

Pre-requisites

1.SAP user id with developer access
2.abap skill 
3.Odata service created using SEGW.(If you dont know how to Please refer  my previous post step-by-step-gateway-odata-service)
4.GET_ENTITYSET implemented already.(If you dont know how to Please refer  my previous post http://www.techippo.com/2015/10/odata-service-implementation-for.html)
        The GET_ENTITY method is implemented to get details of a single entry in the entityset.We pass the key values of an entityset entry and get back single entry.In our example we will be passing carrid of flight entityset and get back only details relevant to the passed carrid.


Steps
1.Go to SEGW .Open created service node.Expand Service Implementation node.Right click on GetEntity(Read) and click on Go to Abap Workbench.
 


2.You will get an information message that method is not implemented. Click OK.




3.You will now land on class builder with ****_DPC_EXT opened.We write our code in this class.Expand methods node.expand inherited methods node.Right click on FLIGHTSET_GET_ENTITY and click redefine.



4.Paste the code to get details of the flight inside method(FLIGHTSET_GET_ENTITY) and activate it.The internal table IT_KEY_TAB of type /IWBEP/T_MGW_NAME_VALUE_PAIR contains key name value pair.we simply access it and write a select query.


    data:ls_keytab TYPE LINE OF /IWBEP/T_MGW_NAME_VALUE_PAIR.
    loop at it_key_tab INTO ls_keytab.
    ENDLOOP.
    SELECT single * FROM scarr INTO CORRESPONDING FIELDS OF er_entity WHERE carrid = ls_keytab-value.



5.We are good to go .Now check your service in browser or gateway client.



If you enjoyed this post, Please Share!!

7 comments :

  1. Thank you for your efforts :)

    ReplyDelete
  2. How to send multiple values to the input internal table

    ReplyDelete
    Replies
    1. Hi,
      Your question is not clear.If you are asking how to pass multiple key fields in get_entity method the answer is you can give by comma seperated values.In this case if Carrid and Carrname are keys the url would be ***/FlightSet(Carrid='AC',Carrname='Air Canada')

      Delete
    2. How about implementation in class if the entity have multiple keys?

      Delete
  3. HI Shouldnt we write code in getentity set rather than get entity. Please clarify because it worked for me only when i added code in get entity set

    ReplyDelete
    Replies
    1. getentityset must be implemented for using getentity.

      Delete

Powered by Blogger.