cancel
Showing results for 
Search instead for 
Did you mean: 

Error when adding an attribute to a redifined entity

jzeifang
Participant
0 Kudos

Dear Gateway experts,

I have the following problem:

In the service builder I have successfully created and activated an OData Service with several entities. Now I have created a second service and have redefined one of the entities of the first service. Finally I have added one attribute to this entity in the second service. Also this service could be generated succesfully. But when calling the service I get the error message "Property [NEW ATTRIBUT] of data object [ENTITY] has no Internal type assigned."

In the MPC class of the second service I see, that the structure belonging to the entity has been updated with this new attribute.

But the exporting parameter ET_ENTITYSET of the DPC class refer to the structure definition of the MPC class of the first service (because the inherite from them) without the new attribute.

So my problem is now, hoc can I add an attribute to a redfined entity without getting this error and be able to fill the export table?

Thanks a lot in advance!

Regards,

Juergen

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Juergen

If the entity is structure based there may be a couple of things that you can do to remedy this.

1/ Check that the structure base of the entity has added the fieldname in SEGW; in the property editor list there is a column to the far right where the ABAP names are located.

2/ If (1) looks OK, then you probably need to do some work in the redefined MPC_EXT class. I'm guessing you will have to define the attribute in the the appropriate define_<entity> method. Redefine it, call the super and then add your attribute - refer to the super method to see how this is done if not sure.

Hope that helps

Regards

Ron.

jzeifang
Participant
0 Kudos

Hi Ron,

thanks for your quick reply!

The entity of the original service is structure based. But the new attribute in the redefined service is not part of this structure. However I have added it manually and also filled the corresponding ABAP type in the column "ABAP Field Names".

The method DEFINE_<ENTITY> is only available in the MPC class of the original service. And this method is private so I can't call it from the subclasses.

In the MPC class of the redefined service there is a private method CREATE_NEW_ARTIFACTS, which is called in the method DEFINE. In this method the new attribute is already added to the entity, in the same way the other attributes were added in the DEFINE_<ENTITY> method:

lo_entity_type = model->get_entity_type(

     iv_entity_name = '<entity>' ).

lo_property = lo_entity_type->create_property(

     iv_property_name  ='<attribute>'

     iv_abap_fieldname = '<ATTRIBUTE in ABAP>' ).

lo_property->set_type_edm_string( ).

...



So I am not sure, what else to add in these methods.


Regards,

Juergen

jzeifang
Participant
0 Kudos

Hi Ron,

I believe I found the error:

In the generated method CREATE_NEW_ARTIFACTS of the MPC class of the redefined Service the statement

lo_entity_type->bind_structure( iv_structure_name  = ...


was missing.

After I have added this the service seems to work fine.


This looks like an error in the generation of this class.

Thanks again for your help!

Regards,

Juergen

Former Member
0 Kudos

Hi Juergen,

Well spotted, I don't think I'd have been looking for something like that as it's quite a fundamental step for a dictionary-based entity.That's quite a bug isn't it!

The MPC generation isn't 100% reliable and I have had some issues in the past with it generating internal data structures that do not match the metadata description. These lead to runtime errors when calling the service, just like you have seen.


Good luck with the rest of the modelling.


Regards


Ron

jzeifang
Participant
0 Kudos

Hi Ron,

thanks 🙂

This indeed looks like a little bug.

As I should not change the method CREATE_NEW_ARTIFACTS in the MPC class I have redefined the DEFINE method in the MPC_EXT class. In this redefinition I first called the DEFINE method of the super (where the CREATE_NEW_ARTIFACTS method is called an the attributes are defined), then I bind the entity to the structure:

METHOD define.

DATA: lo_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ.

TRY.
     
CALL METHOD super->define.
  
CATCH /iwbep/cx_mgw_med_exception .
ENDTRY.

lo_entity_rec
= model->get_entity_type( '<attribute>' ).
lo_entity_rec
->bind_structure( iv_structure_name  = '<type in MPC class>'
).

Regards,

Juergen

Answers (0)