Introduction

This document is written to understand the cause of “Property of Data Object has no type assigned” error in ODATA service.

Scenario

While writing the ODATA service, normally we follow the below steps in Model class.

1. Create Entity Type

2. Bind structure to Entity Type

3. Create Entity Sets


Now, For example,  If You have defined 3 Properties in your entity type.

*&———————————————————————————————————————————-*

* DATA

*&———————————————————————————————————————————-*

   DATA : lo_entity_type type ref to /iwbep/if_mgw_odata_entity_typ,

                lo_property   type ref to /iwbep/if_mgw_odata_property.

*&———————————————————————————————————————————-*

* Entity

*&———————————————————————————————————————————-*

*Define Entity Booking

  lo_entity_type model->create_entity_type( ‘Name’ ).

*Define Property FirstName

  lo_property = lo_entity_type->create_property( iv_property_name = ‘FirstName’

                                                                      iv_abap_fieldname = ‘FIRSTNAME’ ).

*Define Property MiddleName

   lo_property = lo_entity_type->create_property( iv_property_name = ‘MiddleName’

                                                                       iv_abap_fieldname = ‘MIDDLENAME’ ).

*Define Property LastName

  lo_property = lo_entity_type->create_property( iv_property_name = ‘LastName’

                                                                      iv_abap_fieldname = ‘LASTNAME’ ).

*&———————————————————————————————————————————–*

* Bind EntityType to an ABAP dictionary structure ZNAME which has two columns

* FIRSTNAME and LASTNAME

*&———————————————————————————————————————————-*

*Bind Entity Type to structure

  lo_entity_type->bind_structure( ‘ZNAME’ ).

*&———————————————————————————————————————————-*

* Create Entity Set

*&———————————————————————————————————————————-*

lo_entity_type->create_entity_set( ‘Names’ ).

Problem

On above scenario if you activating your model class will not result any kind of error or warning. After that you will create a Runtime Data Provider Class and at the end you will register your service.

When you call this service in your browser, it will give you an error “Property ‘MiddleName’ of Data Object ‘Name’ has no type assigned”

Odata1.PNG

This error occurs when execution goes to create the Entity Set. There is a internal check which maps properties of entity type to the structure which is bound to it.

Solution

If you come across errors like this, just go to your Model Class and cross check the entity properties with your structure. Update your structure with missing properties. If you are playing with standard SAP provided service then make sure that you apply all the respective notes.

Happy Learning


To report this post you need to login first.

4 Comments

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

  1. Ron Sargeant

    The OData and Gateway teams are working on improving the model consistency checks, so I’d hope this kind of error  would soon get picked up at design time.

    Service builder won’t define properties that aren’t chosen from the structure any; I would not waste time defining them manually like this unless you are on SP03 or lower. 😯

    It’s also worth pointing out that binding to a structure is not mandatory, and we should probably start looking at the OData models as abstracts which we map to business structures after designing them, not before/during. The use of DDIC import is a convenience that causes more problems than it solves at times.

    I would recommend that rather than using the Dictionary as the global type source, the MPC public types for the entityies and sets should be referenced instead – after all, this is what the DPC code refers to, not Directly to) the Dictionary.

    Regards

    Ron.

    (0) 
    1. Krishnakant Joshi Post author

      Thanks Ron for your valuable inputs.

      It may not seems a big problem at expert level 🙂 but for beginners like me may stuck up with it and try to reach at the root cause by doing some debugging on service.

      I also favor your comment for using Service Builder. we should not waste time on manual writing. Service builder is the best option to do it. Though i will suggest to those who are working on Odata for the first time that write your first Service Manually. It helps a lot in understanding the process.

      Regards,

      KK

      (0) 
      1. Ron Sargeant

        Hi Krishnakant,

        I pointed out the SEGW usage as a response to the statement “While writing the ODATA service, normally we follow the below steps in Model class”. The SP  level is rising fast and this is definitely not the norm now. Beginners might read this and then get the wrong idea about modelling.

        I agree it is definitely worth hand-coding some definition for understanding purposes; I used to  have to do it but I’m also glad I don’t have to anymore 🙂

        I’m flattered that you consider me an expert, but I would have the same potential pitfall if I was coding these by hand still. It can even happen with SEGW if you alter the structure.

        Cheers

        Ron.



        (0) 
  2. Pradeep Nellore

    Hello Krishkant,

    I had the same problem while extending SRM Approval cart with a BADI to add 2 new custom fields. I had solved by calling relevant methods of class /IWBEP/IF_MGW_ODATA_PROPERT. In my case i have called methods SET_TYPE_EDM_STRING and SET_INTERNAL_TYPE. Could be useful to other with similar issue.

    Cheers

    Pradeep.

    (0) 

Leave a Reply