cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic entitys

michael_fallenbchel
Active Participant
0 Kudos

Hi experts,

is there a way to "generate" dynamic entitys?

For explanation:

I want to have a customizing table. Here the user should maintain which fields he need. Depending on this fields, I want to generate my entity.

Example:

My customizing-table has field MATNR -> entity only MATNR

Now I add MATKL, so my entity must also incluce MATKL.

Is this possible? Do I have to use the Model Provider Class? Or something else?

Thanks a lot

Michael

Accepted Solutions (0)

Answers (1)

Answers (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Michael,

Yes, this is very much possible. Seems you are building a custom framework.

But you cannot use Service Builder for this, instead you need to code the Gateway service. This document says how to use the code approach.  http://scn.sap.com/docs/DOC-43030

Here is the pseudo code for the define method in your Model Provider Class.

1. Create your Entity

2. Fetch properties to be created from you customizing table

3. Loop within the results and add properties to above entity.

Keep in mind that after each changes to your customizing table, you need to clear the metadata cache, so that MPC's define method is executed and properties get refreshed again to see the latest metadata.

Thanks

Krishna

michael_fallenbchel
Active Participant
0 Kudos

Hi Krishna,

first - thanks a lot...a little bit is working 😉

What I have done a the moment:

Created an entity "TEST".

Redefined the "DEINE" method in my model provider class EXT like this:

super->define( ).

Then I have added a new method, where I want to add my fields, like this:

lo_property = c_entity->create_property( iv_property_name = i_name iv_abap_fieldname = i_abap_field ). "#EC NOTEXT

lo_property->set_type_edm_string( ).

lo_property->set_maxlength( iv_max_length = i_length ).

lo_property->set_creatable( abap_false ).

lo_property->set_updatable( abap_false ).

lo_property->set_sortable( abap_false ).

lo_property->set_nullable( abap_false ).

lo_property->set_filterable( abap_false ).

Also fine and working. But after that, in the "standard" MPC, there's the binding of the strucutre:

lo_entity_type->bind_structure( iv_structure_name  = 'ZCL_ZTEST_MPC=>TS_TEST' ). "#EC NOTEXT

But this type won't have my dynamic added fields.

I'm not sure if this is the cause - but in the data provider class, for my newly created TEST entity, I have the TEST_GET_ENTITYSET method. That's fine, but here the ET_ENTITYSET has the wrong type (ZCL_ZTEST_MPC=>TT_TEST). What I have to do to have also my dynamic fields here?

Thanks

Michael

kammaje_cis
Active Contributor
0 Kudos

Hi Michael,

Sorry, I gave a wrong document link. That docuement uses Service Builder, which we do not want to use for this scenario.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/109c15ed-d8a3-2e10-7c9f-dcb1168aa...

So Here is the Pseudo code again

1. Redefine the "Define" method

2. Create Entity

3. Fetch the properties to be created as well as the data element (for binding).

4. Loop in above porperties and create properties. (

lo_property = c_entity->create_property( iv_property_name = i_name iv_abap_fieldname= i_abap_field )

).

5.  Check the methods of lo_property. There should be a method to bind this property with a data element. Use that.

6. You need not use "lo_entity_type->bind_structure" since you are doing binding for each proeprty.

Thanks

Krishna

michael_fallenbchel
Active Participant
0 Kudos

Morning Krishna,

thanks for the update!

What I have done now:

1. Create a pseudo entity in SEGW with one attribute (MATNR)

2. Redefined DEFINE method in MPC, here I call the define method of super class (super->define( ). ), then I change the entity (adding the fields of my customizing table, bind it to a data element).

3. Create an entityset for my entity

Now I want to call this entityset (I called it TEST). Problem is, that I get this error:

<?xml version="1.0" encoding="utf-8" ?>

          <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

                    <code>SY/530</code>

                    <message xml:lang="de">Methode 'GET_ENTITYSET' in Datenanbieterklasse nicht implementiert.</message>

                    <innererror>

                              <transactionid>51FF34E541840BC0E10080000A4A0439</transactionid>

                              <errordetails>

                                        <errordetail>

                                                  <code>/IWBEP/CX_MGW_TECH_EXCEPTION</code>

                                                  <message>Methode 'GET_ENTITYSET' in Datenanbieterklasse nicht implementiert.</message>

                                                  <propertyref />

                                                  <severity>error</severity>

                                        </errordetail>

                    </errordetails>

          </innererror>

</error>

I think I have to create method GET_ENTITYSET in my DPC_EXT.

Is there a way to "change" this name? I want to have the "normal" way - like TEST_GET_ENTITYSET?

Thanks

Michael

michael_fallenbchel
Active Participant
0 Kudos

Ah, got it - have to redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET in my DPC_EXT...

Seems to work at the moment, thanks for all your updates